Skip to content

Commit ab1f094

Browse files
committed
Added pdlp_log_file to CUPDLP_WORK and passing it around HiPDLP
1 parent 915f04e commit ab1f094

File tree

9 files changed

+51
-27
lines changed

9 files changed

+51
-27
lines changed

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cc_library(
2828
"highs/parallel/*.cpp",
2929
"highs/pdlp/*.cpp",
3030
"highs/pdlp/cupdlp/*.c",
31+
"highs/pdlp/hipdlp/*.cc",
3132
"highs/presolve/*.cpp",
3233
"highs/qpsolver/*.cpp",
3334
"highs/simplex/*.cpp",

highs/pdlp/cupdlp/cupdlp_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ struct CUPDLP_WORK {
424424
// cusparseDnVecDescr_t vecbuffer;
425425
cublasHandle_t cublashandle;
426426
#endif
427+
FILE* pdlp_log_file;
427428
};
428429

429430
#ifdef __cplusplus

highs/pdlp/cupdlp/cupdlp_solver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,8 @@ cupdlp_retcode PDHG_Solve(const cupdlp_int* has_variables, CUPDLPwork *pdhg) {
897897
timers->nIter = 0;
898898
timers->dSolvingBeg = getTimeStamp();
899899

900-
FILE* pdlp_log_file = fopen("cuPDLP.log", "w");
901-
assert(pdlp_log_file);
900+
pdhg->pdlp_log_file = fopen("cuPDLP.log", "w");
901+
assert(pdhg->pdlp_log_file);
902902

903903
// PDHG_Init_Data does nothing!
904904
PDHG_Init_Data(pdhg);
@@ -918,7 +918,7 @@ cupdlp_retcode PDHG_Solve(const cupdlp_int* has_variables, CUPDLPwork *pdhg) {
918918
const int iter_log_between_header = 50;
919919
int iter_log_since_header = iter_log_between_header;
920920
for (timers->nIter = 0; timers->nIter < settings->nIterLim; ++timers->nIter) {
921-
pdlpLog(pdlp_log_file, timers->nIter);
921+
pdlpIterLog(pdhg->pdlp_log_file, timers->nIter);
922922
PDHG_Compute_SolvingTime(pdhg);
923923
#if CUPDLP_DUMP_ITERATES_STATS && CUPDLP_DEBUG
924924
PDHG_Dump_Stats(pdhg);
@@ -1154,7 +1154,7 @@ cupdlp_retcode PDHG_Solve(const cupdlp_int* has_variables, CUPDLPwork *pdhg) {
11541154
#endif
11551155

11561156
exit_cleanup:
1157-
fclose(pdlp_log_file);
1157+
fclose(pdhg->pdlp_log_file);
11581158
return retcode;
11591159
}
11601160

highs/pdlp/cupdlp/cupdlp_step.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void PDHG_primalGradientStep(CUPDLPwork *work, CUPDLPvec *xUpdate,
2121
// print norm of A'y
2222
double aty_norm = 0.0;
2323
cupdlp_twoNorm(work, problem->nCols, ATy->data, &aty_norm);
24-
cupdlp_printf("Norm of A'y: %g\n", aty_norm);
24+
pdlpAtyNormLog(work->pdlp_log_file, aty_norm);
2525

2626
#if !defined(CUPDLP_CPU) && USE_KERNELS
2727
cupdlp_pgrad_cuda(xUpdate->data, x->data, problem->cost,
@@ -201,7 +201,7 @@ void PDHG_Update_Iterate_Constant_Step_Size(CUPDLPwork *pdhg) {
201201
double ax_norm = 0.0;
202202
cupdlp_twoNorm(pdhg, problem->nRows, ax->data,
203203
&ax_norm);
204-
cupdlp_printf("Norm of Ax: %g\n", ax_norm);
204+
pdlpAxNormLog(pdhg->pdlp_log_file, ax_norm);
205205
ATy(pdhg, aty, y);
206206

207207
// x^{k+1} = proj_{X}(x^k - dPrimalStep * (c - A'y^k))

highs/pdlp/cupdlp/cupdlp_utils.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,14 @@ void writeSol(const char *fout, cupdlp_int nCols, cupdlp_int nRows,
17821782
fclose(fptr);
17831783
}
17841784

1785-
void pdlpLog(FILE* file, const int iter_num) {
1786-
fprintf(file, "%6d\n", iter_num);
1785+
void pdlpIterLog(FILE* file, const int iter_num) {
1786+
fprintf(file, "Iter %6d\n", iter_num);
1787+
}
1788+
1789+
void pdlpAxNormLog(FILE* file, const double ax_norm) {
1790+
fprintf(file, "||Ax|| = %g\n", ax_norm);
1791+
}
1792+
1793+
void pdlpAtyNormLog(FILE* file, const double aty_norm) {
1794+
fprintf(file, "||A^Ty|| = %g\n", aty_norm);
17871795
}

highs/pdlp/cupdlp/cupdlp_utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ void writeSol(const char *fout, cupdlp_int nCols, cupdlp_int nRows,
193193
cupdlp_float *col_value, cupdlp_float *col_dual,
194194
cupdlp_float *row_value, cupdlp_float *row_dual);
195195

196-
void pdlpLog(FILE* file, const int iter_num);
196+
void pdlpIterLog(FILE* file, const int iter_num);
197+
void pdlpAxNormLog(FILE* file, const double ax_norm);
198+
void pdlpAtyNormLog(FILE* file, const double aty_norm);
197199

198200
#ifdef __cplusplus
199201
}

highs/pdlp/hipdlp/pdhg.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,11 @@ void PDLPSolver::Solve(HighsLp& original_lp, const PrimalDualParams& params,
362362
// --- 2. Main PDHG Loop ---
363363
// A single loop handles max iterations, convergence, and restarts.
364364
for (int iter = 0; iter < params.max_iterations; ++iter) {
365-
pdlpLog(pdlp_log_file, iter);
365+
pdlpIterLog(pdlp_log_file, iter);
366366
linalg::Ax(lp, x_current_, Ax_current);
367367
//print norm of Ax
368368
double ax_norm = linalg::vector_norm(Ax_current);
369-
std::cout << "Norm of Ax: " << ax_norm << std::endl;
369+
pdlpAxNormLog(pdlp_log_file, ax_norm);
370370

371371
linalg::ATy(lp, y_current_, ATy_current);
372372
if (solver_timer.read() > params.time_limit) {
@@ -398,20 +398,23 @@ void PDLPSolver::Solve(HighsLp& original_lp, const PrimalDualParams& params,
398398
switch (params.step_size_strategy) {
399399
case StepSizeStrategy::FIXED:
400400
step::UpdateIteratesFixed(lp, working_params, fixed_eta, x, y, Ax_new,
401-
x_current_, y_current_, Ax_current);
401+
x_current_, y_current_, Ax_current,
402+
pdlp_log_file);
402403
break;
403404

404405
case StepSizeStrategy::ADAPTIVE:
405406
step::UpdateIteratesAdaptive(lp, working_params, x, y, Ax_new,
406407
x_current_, y_current_, Ax_current,
407-
ATy_current, current_eta_, iter);
408+
ATy_current, current_eta_, iter,
409+
pdlp_log_file);
408410
break;
409411

410412
case StepSizeStrategy::MALITSKY_POCK:
411413
step_success = step::UpdateIteratesMalitskyPock(
412414
lp, working_params, x, y, Ax_new, x_current_, y_current_,
413415
Ax_current, ATy_current, current_eta_, ratio_last_two_step_sizes_,
414-
num_rejected_steps_, first_malitsky_iteration);
416+
num_rejected_steps_, first_malitsky_iteration,
417+
pdlp_log_file);
415418

416419
if (!step_success) {
417420
std::cerr << "Malitsky-Pock step failed at iteration " << iter

highs/pdlp/hipdlp/step.cc

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <limits>
66

77
#include "linalg.hpp"
8+
#include "pdlp/cupdlp/cupdlp.h" // For pdlpLogging
89

910
namespace step {
1011

@@ -86,12 +87,13 @@ double ComputeNonlinearity(const std::vector<double>& delta_primal,
8687

8788
void UpdateX(std::vector<double>& x_new, const std::vector<double>& x_current,
8889
const HighsLp& lp, const std::vector<double>& y_current,
89-
double eta, double omega) {
90+
double eta, double omega,
91+
FILE* pdlp_log_file) {
9092
std::vector<double> ATy_cache(lp.num_col_);
9193
linalg::ATy(lp, y_current, ATy_cache);
9294
//print the norm of ATy_cache
9395
double aty_norm = linalg::vector_norm(ATy_cache);
94-
std::cout << "Norm of A'y: " << aty_norm << std::endl;
96+
pdlpAtyNormLog(pdlp_log_file, aty_norm);
9597
for (HighsInt i = 0; i < lp.num_col_; i++) {
9698
double gradient = lp.col_cost_[i] - ATy_cache[i];
9799
x_new[i] = linalg::project_box(x_current[i] - (eta / omega) * gradient,
@@ -139,8 +141,9 @@ void UpdateIteratesFixed(const HighsLp& lp, const PrimalDualParams& params,
139141
std::vector<double>& ax_new,
140142
const std::vector<double>& x_current,
141143
const std::vector<double>& y_current,
142-
const std::vector<double>& ax_current) {
143-
UpdateX(x_new, x_current, lp, y_current, params.eta, params.omega);
144+
const std::vector<double>& ax_current,
145+
FILE* pdlp_log_file) {
146+
UpdateX(x_new, x_current, lp, y_current, params.eta, params.omega, pdlp_log_file);
144147
linalg::Ax(lp, x_new, ax_new);
145148
UpdateY(y_new, y_current, lp, ax_new, ax_current, params.eta, params.omega);
146149
}
@@ -153,7 +156,8 @@ void UpdateIteratesAdaptive(const HighsLp& lp, const PrimalDualParams& params,
153156
const std::vector<double>& y_current,
154157
const std::vector<double>& ax_current,
155158
const std::vector<double>& aty_current,
156-
double& current_eta, int& step_size_iter_count) {
159+
double& current_eta, int& step_size_iter_count,
160+
FILE* pdlp_log_file) {
157161
const double MIN_ETA = 1e-6;
158162
const double MAX_ETA = 1.0;
159163

@@ -178,7 +182,7 @@ void UpdateIteratesAdaptive(const HighsLp& lp, const PrimalDualParams& params,
178182
std::vector<double> aty_candidate(lp.num_col_);
179183

180184
// Primal update
181-
UpdateX(x_candidate, x_current, lp, y_current, current_eta, params.omega);
185+
UpdateX(x_candidate, x_current, lp, y_current, current_eta, params.omega, pdlp_log_file);
182186
linalg::Ax(lp, x_candidate, ax_candidate);
183187

184188
// Dual update
@@ -263,14 +267,15 @@ bool UpdateIteratesMalitskyPock(
263267
const std::vector<double>& y_current, const std::vector<double>& ax_current,
264268
const std::vector<double>& aty_current, double& current_eta,
265269
double& ratio_last_two_step_sizes, int& num_rejected_steps,
266-
bool first_iteration) // Add this parameter to track first iteration
270+
bool first_iteration,
271+
FILE* pdlp_log_file) // Add this parameter to track first iteration
267272
{
268273
// Step 1: Compute primal update first (without extrapolation)
269274
const double primal_step_size = current_eta / params.omega;
270275

271276
std::vector<double> x_candidate(lp.num_col_);
272277
UpdateX(x_candidate, x_current, lp, y_current, primal_step_size,
273-
params.omega);
278+
params.omega, pdlp_log_file);
274279

275280
// Compute Ax for the primal candidate
276281
std::vector<double> ax_candidate(lp.num_row_);

highs/pdlp/hipdlp/step.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ double ComputeNonlinearity(const std::vector<double>& delta_primal,
4343
// The standard primal update step
4444
void UpdateX(std::vector<double>& x_new, const std::vector<double>& x_current,
4545
const HighsLp& lp, const std::vector<double>& y_current,
46-
double primal_step, double omega);
46+
double primal_step, double omega,
47+
FILE* pdlp_log_file);
4748

4849
// The standard dual update step
4950
void UpdateY(std::vector<double>& y_new, const std::vector<double>& y_current,
@@ -58,7 +59,8 @@ void UpdateIteratesFixed(const HighsLp& lp, const PrimalDualParams& params,
5859
std::vector<double>& ax_new,
5960
const std::vector<double>& x_current,
6061
const std::vector<double>& y_current,
61-
const std::vector<double>& ax_current);
62+
const std::vector<double>& ax_current,
63+
FILE* pdlp_log_file);
6264

6365
void UpdateIteratesAdaptive(const HighsLp& lp, const PrimalDualParams& params,
6466
std::vector<double>& x_new,
@@ -68,7 +70,8 @@ void UpdateIteratesAdaptive(const HighsLp& lp, const PrimalDualParams& params,
6870
const std::vector<double>& y_current,
6971
const std::vector<double>& ax_current,
7072
const std::vector<double>& aty_current,
71-
double& current_eta, int& step_size_iter_count);
73+
double& current_eta, int& step_size_iter_count,
74+
FILE* pdlp_log_file);
7275

7376
bool UpdateIteratesMalitskyPock(
7477
const HighsLp& lp, const PrimalDualParams& params,
@@ -77,8 +80,9 @@ bool UpdateIteratesMalitskyPock(
7780
const std::vector<double>& y_current, const std::vector<double>& ax_current,
7881
const std::vector<double>& aty_current, double& current_eta,
7982
double& ratio_last_two_step_sizes, int& num_rejected_steps,
80-
bool first_iteration);
83+
bool first_iteration,
84+
FILE* pdlp_log_file);
8185

8286
} // namespace step
8387

84-
#endif // STEP_HPP
88+
#endif // STEP_HPP

0 commit comments

Comments
 (0)