Skip to content

Commit da2ae7e

Browse files
committed
fix code relate to PDLP_DEBUG_LOG
1 parent 5495e4a commit da2ae7e

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

highs/pdlp/CupdlpWrapper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
205205
&pdlp_num_iter);
206206
highs_info.pdlp_iteration_count = pdlp_num_iter;
207207

208+
#if PDLP_DEBUG_LOG
208209
// Print final solution using debugPdlpFinalSolutionLog
209210
debugPdlpFinalSolutionLog(w->debug_pdlp_log_file_,
210211
highs_solution.col_value.data(), lp.num_col_,
@@ -214,6 +215,7 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
214215
// still be used
215216
//
216217
PDHG_Destroy(&w);
218+
#endif
217219

218220
model_status = HighsModelStatus::kUnknown;
219221
highs_solution.value_valid = value_valid;

highs/pdlp/cupdlp/cupdlp_defs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern "C" {
4141
#define CUPDLP_DUMP_LINESEARCH_STATS (1)
4242
#define CUPDLP_INEXACT_EPS (1e-4)
4343

44-
#define PDLP_DEBUG_LOG (0)
44+
#define PDLP_DEBUG_LOG (1)
4545

4646
typedef struct CUPDLP_CUDA_DENSE_VEC CUPDLPvec;
4747
typedef struct CUPDLP_DENSE_MATRIX CUPDLPdense;
@@ -434,8 +434,11 @@ struct CUPDLP_WORK {
434434
// cusparseDnVecDescr_t vecbuffer;
435435
cublasHandle_t cublashandle;
436436
#endif
437+
438+
#if PDLP_DEBUG_LOG
437439
FILE* debug_pdlp_log_file_;
438440
struct DebugPdlpData debug_pdlp_data_;
441+
#endif
439442
};
440443

441444
#ifdef __cplusplus

highs/pdlp/cupdlp/cupdlp_restart.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ PDHG_restart_choice PDHG_Check_Restart_GPU(CUPDLPwork *work) {
2727
cupdlp_float muAverage = PDHG_Restart_Score_GPU(
2828
work->stepsize->dBeta, work->resobj->dPrimalFeasAverage,
2929
work->resobj->dDualFeasAverage, work->resobj->dDualityGapAverage);
30+
#if PDLP_DEBUG_LOG
3031
debugPdlpRestartLog(work->debug_pdlp_log_file_, timers->nIter, muCurrent, muAverage);
32+
#endif
3133
cupdlp_float muCandidate = 0.0;
3234
PDHG_restart_choice restart_choice = PDHG_RESTART_TO_AVERAGE;
3335
if (muCurrent < muAverage) {

highs/pdlp/cupdlp/cupdlp_solver.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ void PDHG_Init_Variables(const cupdlp_int* has_variables, CUPDLPwork *work) {
558558
// Ax(work, iterates->ax, iterates->x);
559559
// ATyCPU(work, iterates->aty, iterates->y);
560560
Ax(work, ax, x);
561+
562+
#if PDLP_DEBUG_LOG
561563
double ax_norm;
562564
cupdlp_twoNorm(work, lp->nRows, ax->data, &ax_norm);
563565
if (work->settings->nLogLevel>0)
@@ -567,6 +569,7 @@ void PDHG_Init_Variables(const cupdlp_int* has_variables, CUPDLPwork *work) {
567569
double aty_norm;
568570
cupdlp_twoNorm(work, lp->nCols, aty->data, &aty_norm);
569571
work->debug_pdlp_data_.aty_norm = aty_norm;
572+
#endif
570573

571574
// cupdlp_zero(iterates->xSum, cupdlp_float, lp->nCols);
572575
// cupdlp_zero(iterates->ySum, cupdlp_float, lp->nRows);
@@ -907,14 +910,15 @@ cupdlp_retcode PDHG_Solve(const cupdlp_int* has_variables, CUPDLPwork *pdhg) {
907910
timers->nIter = 0;
908911
timers->dSolvingBeg = getTimeStamp();
909912

913+
#if PDLP_DEBUG_LOG
910914
if (PDLP_DEBUG_LOG) {
911915
pdhg->debug_pdlp_log_file_ = fopen("cuPDLP.log", "w");
912916
assert(pdhg->debug_pdlp_log_file_);
913917
debugPdlpDataInitialise(&pdhg->debug_pdlp_data_);
914918
} else {
915919
pdhg->debug_pdlp_log_file_ = NULL;
916920
}
917-
921+
#endif
918922
// PDHG_Init_Data does nothing!
919923
PDHG_Init_Data(pdhg);
920924

@@ -932,10 +936,16 @@ cupdlp_retcode PDHG_Solve(const cupdlp_int* has_variables, CUPDLPwork *pdhg) {
932936
// iter_log_since_header so that an initial header is printed
933937
const int iter_log_between_header = 50;
934938
int iter_log_since_header = iter_log_between_header;
939+
#if PDLP_DEBUG_LOG
935940
debugPdlpIterHeaderLog(pdhg->debug_pdlp_log_file_);
941+
#endif
936942
for (timers->nIter = 0; timers->nIter < settings->nIterLim; ++timers->nIter) {
943+
#if PDLP_DEBUG_LOG
937944
debugPdlpIterLog(pdhg->debug_pdlp_log_file_, timers->nIter, &pdhg->debug_pdlp_data_, pdhg->stepsize->dBeta, pdhg->stepsize->dPrimalStep, pdhg->stepsize->dDualStep);
945+
#endif
946+
938947
PDHG_Compute_SolvingTime(pdhg);
948+
939949
#if CUPDLP_DUMP_ITERATES_STATS && CUPDLP_DEBUG
940950
PDHG_Dump_Stats(pdhg);
941951
#endif
@@ -982,6 +992,7 @@ cupdlp_retcode PDHG_Solve(const cupdlp_int* has_variables, CUPDLPwork *pdhg) {
982992
iter_log_since_header++;
983993
}
984994

995+
#if PDLP_DEBUG_LOG
985996
debugPdlpFeasOptLog(pdhg->debug_pdlp_log_file_,
986997
pdhg->timers->nIter,
987998
pdhg->resobj->dPrimalObj,
@@ -997,7 +1008,7 @@ cupdlp_retcode PDHG_Solve(const cupdlp_int* has_variables, CUPDLPwork *pdhg) {
9971008
pdhg->resobj->dPrimalFeasAverage / (1.0 + pdhg->scaling->dNormRhs),
9981009
pdhg->resobj->dDualFeasAverage / (1.0 + pdhg->scaling->dNormCost), "[A]");
9991010
debugPdlpIterHeaderLog(pdhg->debug_pdlp_log_file_);
1000-
1011+
#endif
10011012
// Termination check printing is only done when printing is full
10021013
int termination_print = bool_print && full_print;
10031014
if (PDHG_Check_Termination(pdhg, termination_print)) {
@@ -1059,14 +1070,16 @@ cupdlp_retcode PDHG_Solve(const cupdlp_int* has_variables, CUPDLPwork *pdhg) {
10591070

10601071
CUPDLPvec *ax = iterates->ax[timers->nIter % 2];
10611072
CUPDLPvec *aty = iterates->aty[timers->nIter % 2];
1073+
1074+
#if PDLP_DEBUG_LOG
10621075
double debug_pdlp_data_ax_norm = 0.0;
10631076
cupdlp_twoNorm(pdhg, problem->nRows, ax->data,
10641077
&debug_pdlp_data_ax_norm);
10651078
pdhg->debug_pdlp_data_.ax_norm = debug_pdlp_data_ax_norm;
10661079
double debug_pdlp_data_aty_norm = 0.0;
10671080
cupdlp_twoNorm(pdhg, problem->nCols, aty->data, &debug_pdlp_data_aty_norm);
10681081
pdhg->debug_pdlp_data_.aty_norm = debug_pdlp_data_aty_norm;
1069-
1082+
#endif
10701083
// CUPDLP_CALL(PDHG_Update_Iterate(pdhg));
10711084
if (PDHG_Update_Iterate(pdhg) == RETCODE_FAILED) {
10721085
// cupdlp_printf("Time limit reached.\n");

highs/pdlp/cupdlp/cupdlp_step.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ void PDHG_Compute_Average_Iterate(CUPDLPwork *work) {
400400
// ATyCPU(work, iterates->atyAverage, iterates->yAverage);
401401
Ax(work, iterates->axAverage, iterates->xAverage);
402402
ATy(work, iterates->atyAverage, iterates->yAverage);
403+
404+
#if PDLP_DEBUG_LOG
403405
// print norm of x_average
404406
cupdlp_float debug_pdlp_data_x_average_norm = 0.0;
405407
cupdlp_twoNormSquared(work, lp->nCols, iterates->xAverage
@@ -414,6 +416,7 @@ void PDHG_Compute_Average_Iterate(CUPDLPwork *work) {
414416
cupdlp_float debug_pdlp_data_aty_average_norm = 0.0;
415417
cupdlp_twoNormSquared(work, lp->nCols, iterates->atyAverage->data, &debug_pdlp_data_aty_average_norm);
416418
work->debug_pdlp_data_.aty_average_norm = debug_pdlp_data_aty_average_norm;
419+
#endif
417420
}
418421

419422
void PDHG_Update_Average(CUPDLPwork *work) {

0 commit comments

Comments
 (0)