Skip to content

Commit 5495e4a

Browse files
committed
add real PDLP_DEBUG_LOG
1 parent 229176e commit 5495e4a

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

check/TestPdlp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ TEST_CASE("pdlp-restart-add-row", "[pdlp]") {
342342
}
343343

344344
TEST_CASE("hi-pdlp", "[pdlp]") {
345-
std::string model = "neso-2005"; //"adlittle";//"afiro";// shell// stair
345+
std::string model = "afiro"; //"adlittle";//"afiro";// shell// stair
346346
////25fv47 //fit2p //avgas //neso-2245 //neso-2005
347347
std::string model_file =
348348
//std::string(HIGHS_DIR) + "/srv/" + model + ".mps.gz";
@@ -357,7 +357,7 @@ TEST_CASE("hi-pdlp", "[pdlp]") {
357357
HighsInt pdlp_features_off = 0
358358
//+kPdlpScalingOff
359359
//+kPdlpRestartOff
360-
//+kPdlpAdaptiveStepSizeOff
360+
+kPdlpAdaptiveStepSizeOff
361361
;
362362
h.setOptionValue("pdlp_features_off", pdlp_features_off);
363363

@@ -366,9 +366,9 @@ TEST_CASE("hi-pdlp", "[pdlp]") {
366366
//+ kPdlpScalingL2
367367
+ kPdlpScalingPC;
368368
h.setOptionValue("pdlp_scaling_mode", pdlp_scaling);
369-
h.setOptionValue("pdlp_step_size_strategy", 1);
369+
h.setOptionValue("pdlp_step_size_strategy", 0);
370370
h.setOptionValue("pdlp_restart_strategy", 2);
371-
h.setOptionValue("pdlp_iteration_limit", 20000);
371+
h.setOptionValue("pdlp_iteration_limit", 20);
372372
//h.setOptionValue("pdlp_time_limit", 60);
373373
// h.setOptionValue("log_dev_level", kHighsLogDevLevelVerbose);
374374
auto start_hipdlp = std::chrono::high_resolution_clock::now();

highs/pdlp/cupdlp/cupdlp_defs.h

Lines changed: 1 addition & 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 (1)
44+
#define PDLP_DEBUG_LOG (0)
4545

4646
typedef struct CUPDLP_CUDA_DENSE_VEC CUPDLPvec;
4747
typedef struct CUPDLP_DENSE_MATRIX CUPDLPdense;

highs/pdlp/hipdlp/pdhg.cc

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,12 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
513513

514514
// --- 1. Initialization ---
515515
restart_scheme_.passLogOptions(&working_params.log_options_);
516+
517+
#ifdef PDLP_DEBUG_LOG
516518
restart_scheme_.passDebugPdlpLogFile(debug_pdlp_log_file_);
517519
restart_scheme_.passDebugPdlpData(&debug_pdlp_data_);
520+
#endif
521+
518522
initialize(); // Sets initial x, y and results_
519523
restart_scheme_.passParams(&working_params);
520524
restart_scheme_.Initialize(results_);
@@ -550,17 +554,22 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
550554
logger_.print_iteration_header();
551555

552556
// --- 2. Main PDHG Loop ---
557+
#ifdef PDLP_DEBUG_LOG
553558
debugPdlpIterHeaderLog(debug_pdlp_log_file_);
554559
debugPdlpDataInitialise(&debug_pdlp_data_);
555560
debug_pdlp_data_.ax_average_norm = 0.0;
556561
debug_pdlp_data_.aty_average_norm = 0.0;
557562
debug_pdlp_data_.x_average_norm = 0.0;
558563
debug_pdlp_data_.ax_norm = linalg::vector_norm(Ax_cache_);
564+
#endif
559565

560566
for (int iter = 0; iter < params_.max_iterations; ++iter) {
567+
std::cout << "PDHG Iteration " << iter << std::endl;
568+
#ifdef PDLP_DEBUG_LOG
561569
debugPdlpIterLog(debug_pdlp_log_file_, iter, &debug_pdlp_data_,
562570
restart_scheme_.getBeta(), stepsize_.primal_step,
563571
stepsize_.dual_step);
572+
#endif
564573

565574
// Check time limit
566575
if (solver_timer.read() > params_.time_limit) {
@@ -809,6 +818,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
809818
cudaMemcpyDeviceToDevice));
810819
CUDA_CHECK(cudaMemcpy(d_y_next_, d_y_current_, a_num_rows_ * sizeof(double),
811820
cudaMemcpyDeviceToDevice));
821+
#ifdef PDLP_DEBUG_LOG
812822
// Copy Ax and ATy cache to host
813823
CUDA_CHECK(cudaMemcpy(Ax_cache_.data(), d_ax_current_,
814824
a_num_rows_ * sizeof(double),
@@ -818,11 +828,15 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
818828
cudaMemcpyDeviceToHost));
819829
debug_pdlp_data_.ax_norm = linalg::vector_norm(Ax_cache_);
820830
debug_pdlp_data_.aty_norm = linalg::vector_norm(ATy_cache_);
831+
#endif
821832
#else
822833
x_next_ = x_current_;
823834
y_next_ = y_current_;
835+
836+
#ifdef PDLP_DEBUG_LOG
824837
debug_pdlp_data_.ax_norm = linalg::vector_norm(Ax_cache_);
825838
debug_pdlp_data_.aty_norm = linalg::vector_norm(ATy_cache_);
839+
#endif
826840
#endif
827841

828842
switch (params_.step_size_strategy) {
@@ -992,7 +1006,9 @@ void PDLPSolver::computeAverageIterate(std::vector<double>& ax_avg,
9921006
for (size_t i = 0; i < y_avg_.size(); ++i) y_avg_[i] = y_sum_[i] * dDualScale;
9931007
hipdlpTimerStop(kHipdlpClockAverageIterateComputeY);
9941008

1009+
#ifdef PDLP_DEBUG_LOG
9951010
debug_pdlp_data_.x_average_norm = linalg::vector_norm_squared(x_avg_);
1011+
#endif
9961012

9971013
hipdlpTimerStart(kHipdlpClockAverageIterateMatrixMultiply);
9981014
linalg::Ax(lp_, x_avg_, ax_avg);
@@ -1002,8 +1018,10 @@ void PDLPSolver::computeAverageIterate(std::vector<double>& ax_avg,
10021018
linalg::ATy(lp_, y_avg_, aty_avg);
10031019
hipdlpTimerStop(kHipdlpClockAverageIterateMatrixTransposeMultiply);
10041020

1021+
#ifdef PDLP_DEBUG_LOG
10051022
debug_pdlp_data_.ax_average_norm = linalg::vector_norm_squared(ax_avg);
10061023
debug_pdlp_data_.aty_average_norm = linalg::vector_norm_squared(aty_avg);
1024+
#endif
10071025
}
10081026

10091027
// lambda = c - proj_{\Lambda}(c - K^T y)
@@ -1224,10 +1242,12 @@ bool PDLPSolver::checkConvergence(
12241242
std::abs(duality_gap) / (1.0 + std::abs(primal_obj) + std::abs(dual_obj));
12251243
results.relative_obj_gap = relative_obj_gap;
12261244

1245+
#ifdef PDLP_DEBUG_LOG
12271246
debugPdlpFeasOptLog(debug_pdlp_log_file_, iter, primal_obj, dual_obj,
12281247
relative_obj_gap,
12291248
primal_feasibility / (1.0 + unscaled_rhs_norm_),
12301249
dual_feasibility / (1.0 + unscaled_c_norm_), type);
1250+
#endif
12311251

12321252
// Check convergence criteria (matching cuPDLP)
12331253
bool primal_feasible =
@@ -1673,6 +1693,9 @@ void PDLPSolver::updateIteratesFixed() {
16731693
vecDiff(ax_next_gpu, Ax_next_, 1e-10, "UpdateIteratesFixed Ax");
16741694
bool aty_match =
16751695
vecDiff(aty_next_gpu, ATy_next_, 1e-10, "UpdateIteratesFixed ATy");
1696+
1697+
#else
1698+
16761699
#endif
16771700
}
16781701

@@ -2237,11 +2260,13 @@ bool PDLPSolver::checkConvergenceGpu(const int iter, const double* d_x,
22372260
results.relative_obj_gap =
22382261
std::abs(duality_gap) / (1.0 + std::abs(primal_obj) + std::abs(dual_obj));
22392262

2263+
#ifdef PDLP_DEBUG_LOG
22402264
debugPdlpFeasOptLog(debug_pdlp_log_file_, iter, primal_obj, dual_obj,
22412265
results.relative_obj_gap,
22422266
results.primal_feasibility / (1.0 + unscaled_rhs_norm_),
22432267
results.dual_feasibility / (1.0 + unscaled_c_norm_),
22442268
type);
2269+
#endif
22452270

22462271
bool primal_feasible =
22472272
results.primal_feasibility < epsilon * (1.0 + unscaled_rhs_norm_);
@@ -2300,12 +2325,13 @@ void PDLPSolver::computeAverageIterateGpu() {
23002325
// Recompute Ax_avg and ATy_avg on GPU
23012326
linalgGpuAx(d_x_avg_, d_ax_avg_);
23022327
linalgGpuATy(d_y_avg_, d_aty_avg_);
2328+
2329+
#ifdef PDLP_DEBUG_LOG
23032330
// copy x_avg to host
23042331
CUDA_CHECK(cudaMemcpy(x_avg_.data(), d_x_avg_, a_num_cols_ * sizeof(double),
23052332
cudaMemcpyDeviceToHost));
23062333
debug_pdlp_data_.x_average_norm = linalg::vector_norm_squared(x_avg_);
2307-
2308-
// debug_pdlp_data_.ax_average_norm = computeDiffNormCuBLAS;
2334+
#endif
23092335
}
23102336

23112337
double PDLPSolver::computeMovementGpu(const double* d_x_new,

highs/pdlp/hipdlp/pdhg.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <cusparse.h>
1717
#endif
1818

19+
#define DEBUG_MODE 1
20+
1921
#include <algorithm>
2022
#include <cmath>
2123
#include <iostream>
@@ -53,10 +55,11 @@ class PDLPSolver {
5355
int getnCol() const { return lp_.num_col_; }
5456
int getnRow() const { return lp_.num_row_; }
5557

58+
#ifdef PDLP_DEBUG_LOG
5659
// --- Debugging ---
5760
FILE* debug_pdlp_log_file_ = nullptr;
5861
DebugPdlpData debug_pdlp_data_;
59-
62+
#endif
6063
void reportHipdlpTimer();
6164
void closeDebugLog();
6265

0 commit comments

Comments
 (0)