Unable to retrieve solution after solving LP with PDHG (alpha version)
AnsweredI'm trying to solve an LP with PDHG on GPU with crossover turned off. After solving, the status is suboptimal (make sense as I solve it with large tolerance 1e-4), but I cannot retrieve this suboptimal solution. The solutions returned are all zero. I manually computed the objective function, it does not match the log file. I test C and C++ API, same problem exists. The problem is gone if I turn on crossover.
The following is the minimal reproducible example:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include "gurobi_c++.h"
int main() {
GRBEnv* env = nullptr;
GRBModel* model = nullptr;
try {
env = new GRBEnv();
model = new GRBModel(*env);
// This is a portfolio optimization-like problem:
// minimize: sum(i=1 to n) c_i * x_i
// subject to: sum(i=1 to n) x_i = 1 (budget constraint)
// sum(i=1 to n) a_ij * x_i <= b_j for j=1..m (risk constraints)
// x_i >= 0 for all i
int n = 50; // 50 variables
int m = 20; // 20 inequality constraints
std::vector<double> objCoef(n);
std::vector<GRBVar> vars;
// Generate objective coefficients
for (int i = 0; i < n; ++i) {
objCoef[i] = 1.0 + 0.1 * i + 0.01 * i * i; // Quadratic-like growth
}
for (int i = 0; i < n; ++i) {
vars.push_back(model->addVar(0.0, 1.0, objCoef[i], GRB_CONTINUOUS));
}
GRBLinExpr budget_expr = 0;
for (int i = 0; i < n; ++i) {
budget_expr += vars[i];
}
model->addConstr(budget_expr, GRB_EQUAL, 1.0);
// Add inequality constraints with random coefficients
for (int j = 0; j < m; ++j) {
GRBLinExpr ineq_expr = 0;
for (int i = 0; i < n; ++i) {
double coef = sin(i + j) + cos(2*i + 3*j); // Generate varied coefficients
ineq_expr += coef * vars[i];
}
double rhs = 0.5 + 0.1 * j; // Varied RHS values
model->addConstr(ineq_expr, GRB_LESS_EQUAL, rhs);
}
std::cout << "Created problem with " << n << " variables and " << (m+1) << " constraints" << std::endl;
float tolerance = 1e-8; // Tighter tolerance
model->set(GRB_IntParam_OutputFlag, 1);
// model->set(GRB_DoubleParam_TimeLimit, 60.0);
model->set(GRB_IntParam_Method, 6);
model->set("GURO_PAR_PDHGRELTOL", std::to_string(tolerance).c_str());
model->set("GURO_PAR_PDHGGPU", "1");
model->set(GRB_IntParam_Crossover, 0); // Turn on crossover, the problem is gone
model->optimize();
int status = model->get(GRB_IntAttr_Status);
std::cout << "Optimization status: " << status << std::endl;
if (status == GRB_OPTIMAL || status == GRB_SUBOPTIMAL) {
double primal_obj = model->get(GRB_DoubleAttr_ObjVal);
std::cout << "Gurobi reported objective: " << primal_obj << std::endl;
// Extract solution
std::vector<double> x_vec(n);
double solution_sum = 0.0;
bool has_nonzero = false;
for (int i = 0; i < n; ++i) {
x_vec[i] = vars[i].get(GRB_DoubleAttr_X);
solution_sum += x_vec[i];
if (std::abs(x_vec[i]) > 1e-10) has_nonzero = true;
if (i < 10) { // Print first 10 variables
std::cout << "x[" << i << "] = " << x_vec[i] << std::endl;
}
}
std::cout << "Sum of all variables: " << solution_sum << " (should be ~1.0)" << std::endl;
std::cout << "Has non-zero variables: " << has_nonzero << std::endl;
// Manual objective calculation
double manual_obj = 0.0;
for (int i = 0; i < n; ++i) {
manual_obj += objCoef[i] * x_vec[i];
}
std::cout << "Manual objective calculation: " << manual_obj << std::endl;
std::cout << "Difference: " << std::abs(primal_obj - manual_obj) << std::endl;
} else {
std::cout << "Optimization failed with status: " << status << std::endl;
}
} catch (GRBException& e) {
std::cerr << "Gurobi Error: " << e.getErrorCode() << " - " << e.getMessage() << std::endl;
}
if (model) delete model;
if (env) delete env;
return 0;
}-
Thanks for the report! We can reproduce this using the alpha version on a linux machine with a GPU without HMM.
Luckily our beta release (coming very soon) doesn't have this issue! Please stay tuned to try it out!Cheers,
David0 -
Can you provide the output of
nvidia-smi -qand your operating system details withuname -a. I'm trying to determine if a driver upgrade would fix this issue for the alpha release.Cheers,
David0 -
Thank you for the reply. Here is the driver info:
Linux YW 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux==============NVSMI LOG============== Timestamp : Fri Oct 3 10:45:14 2025 Driver Version : 576.83 CUDA Version : 12.9 Attached GPUs : 1 GPU 00000000:01:00.0 Product Name : NVIDIA GeForce RTX 3070 Laptop GPU Product Brand : GeForce Product Architecture : Ampere Display Mode : Requested functionality has been deprecated Display Attached : Yes Display Active : Enabled Persistence Mode : Enabled Addressing Mode : N/A MIG Mode Current : N/A Pending : N/A Accounting Mode : Disabled Accounting Mode Buffer Size : 4000 Driver Model Current : WDDM Pending : WDDM Serial Number : N/A GPU UUID : GPU-3362d3e1-4995-ddb2-59f3-6df6f03dea86 Minor Number : N/A VBIOS Version : 94.04.47.00.41 MultiGPU Board : No Board ID : 0x100 Board Part Number : N/A GPU Part Number : 24DD-750-A1 FRU Part Number : N/A Platform Info Chassis Serial Number : N/A Slot Number : N/A Tray Index : N/A Host ID : N/A Peer Type : N/A Module Id : 1 GPU Fabric GUID : N/A Inforom Version Image Version : G001.0000.03.03 OEM Object : 2.0 ECC Object : N/A Power Management Object : N/A Inforom BBX Object Flush Latest Timestamp : N/A Latest Duration : N/A GPU Operation Mode Current : N/A Pending : N/A GPU C2C Mode : N/A GPU Virtualization Mode Virtualization Mode : None Host VGPU Mode : N/A vGPU Heterogeneous Mode : N/A GPU Reset Status Reset Required : Requested functionality has been deprecated Drain and Reset Recommended : Requested functionality has been deprecated GPU Recovery Action : None GSP Firmware Version : N/A IBMNPU Relaxed Ordering Mode : N/A PCI Bus : 0x01 Device : 0x00 Domain : 0x0000 Device Id : 0x24DD10DE Bus Id : 00000000:01:00.0 Sub System Id : 0x0A8D1028 GPU Link Info PCIe Generation Max : 4 Current : 4 Device Current : 4 Device Max : 4 Host Max : 4 Link Width Max : 16x Current : 8x Bridge Chip Type : N/A Firmware : N/A Replays Since Reset : 0 Replay Number Rollovers : 0 Tx Throughput : 1300 KB/s Rx Throughput : 8450 KB/s Atomic Caps Outbound : N/A Atomic Caps Inbound : N/A Fan Speed : N/A Performance State : P5 Clocks Event Reasons Idle : Active Applications Clocks Setting : Not Active SW Power Cap : Not Active HW Slowdown : Not Active HW Thermal Slowdown : Not Active HW Power Brake Slowdown : Not Active Sync Boost : Not Active SW Thermal Slowdown : Not Active Display Clock Setting : Not Active Clocks Event Reasons Counters SW Power Capping : 39526 us Sync Boost : 0 us SW Thermal Slowdown : 0 us HW Thermal Slowdown : 0 us HW Power Braking : 0 us Sparse Operation Mode : N/A FB Memory Usage Total : 8192 MiB Reserved : 172 MiB Used : 1477 MiB Free : 6544 MiB BAR1 Memory Usage Total : 8192 MiB Used : 8164 MiB Free : 28 MiB Conf Compute Protected Memory Usage Total : N/A Used : N/A Free : N/A Compute Mode : Default Utilization GPU : 1 % Memory : 8 % Encoder : 0 % Decoder : 0 % JPEG : 0 % OFA : 0 % Encoder Stats Active Sessions : 0 Average FPS : 0 Average Latency : 0 FBC Stats Active Sessions : 0 Average FPS : 0 Average Latency : 0 DRAM Encryption Mode Current : N/A Pending : N/A ECC Mode Current : N/A Pending : N/A ECC Errors Volatile SRAM Correctable : N/A SRAM Uncorrectable Parity : N/A SRAM Uncorrectable SEC-DED : N/A DRAM Correctable : N/A DRAM Uncorrectable : N/A Aggregate SRAM Correctable : N/A SRAM Uncorrectable Parity : N/A SRAM Uncorrectable SEC-DED : N/A DRAM Correctable : N/A DRAM Uncorrectable : N/A SRAM Threshold Exceeded : N/A Aggregate Uncorrectable SRAM Sources SRAM L2 : N/A SRAM SM : N/A SRAM Microcontroller : N/A SRAM PCIE : N/A SRAM Other : N/A Retired Pages Single Bit ECC : N/A Double Bit ECC : N/A Pending Page Blacklist : N/A Remapped Rows : N/A Temperature GPU Current Temp : 50 C GPU T.Limit Temp : N/A GPU Shutdown Temp : 101 C GPU Slowdown Temp : 98 C GPU Max Operating Temp : 105 C GPU Target Temperature : 75 C Memory Current Temp : N/A Memory Max Operating Temp : N/A GPU Power Readings Average Power Draw : 20.65 W Instantaneous Power Draw : 20.87 W Current Power Limit : 110.00 W Requested Power Limit : 110.00 W Default Power Limit : 85.00 W Min Power Limit : 1.00 W Max Power Limit : 110.00 W GPU Memory Power Readings Average Power Draw : N/A Instantaneous Power Draw : N/A Module Power Readings Average Power Draw : N/A Instantaneous Power Draw : N/A Current Power Limit : N/A Requested Power Limit : N/A Default Power Limit : N/A Min Power Limit : N/A Max Power Limit : N/A Power Smoothing : N/A Workload Power Profiles Requested Profiles : N/A Enforced Profiles : N/A Clocks Graphics : 210 MHz SM : 210 MHz Memory : 810 MHz Video : 555 MHz Applications Clocks Graphics : N/A Memory : N/A Default Applications Clocks Graphics : N/A Memory : N/A Deferred Clocks Memory : N/A Max Clocks Graphics : 2100 MHz SM : 2100 MHz Memory : 6001 MHz Video : 1950 MHz Max Customer Boost Clocks Graphics : N/A Clock Policy Auto Boost : N/A Auto Boost Default : N/A Voltage Graphics : Requested functionality has been deprecated Fabric State : N/A Status : N/A CliqueId : N/A ClusterUUID : N/A Health Bandwidth : N/A Route Recovery in progress : N/A Route Unhealthy : N/A Access Timeout Recovery : N/A Processes : None Capabilities EGM : disabled0 -
Thank you very much for the output!
The line:
Addressing Mode : N/Aand the driver version being ≥ 535 means that HDMM isn’t enabled on this system so you the only workaround for this bug, until version 13 is setting ScaleFlag=0.
Cheers,
David0
Please sign in to leave a comment.
Comments
4 comments