Skip to content

Commit f34e900

Browse files
authored
Merge pull request #3057 from ERGO-Code/fix-3049
Lines in options files with only spaces are now ignored, and text of first line with error is printed
2 parents 1dedab0 + 7ac997f commit f34e900

3 files changed

Lines changed: 44 additions & 29 deletions

File tree

check/TestOptions.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <cstdio>
2+
#include <fstream>
23

34
#include "HCheckConfig.h"
45
#include "Highs.h"
@@ -542,3 +543,20 @@ TEST_CASE("default-options", "[highs_options]") {
542543
options.solver = kSimplexString;
543544
REQUIRE(h.passOptions(options) == HighsStatus::kOk);
544545
}
546+
547+
TEST_CASE("incomplete-options-file-line", "[highs_options]") {
548+
const std::string test_name = Catch::getResultCapture().getCurrentTestName();
549+
const std::string incomplete_options_file = test_name + ".set";
550+
std::ofstream f;
551+
f.open(incomplete_options_file, std::ios::out);
552+
f << "presolve = off\n";
553+
f << " \n";
554+
f.close();
555+
556+
Highs h;
557+
h.setOptionValue("output_flag", dev_run);
558+
559+
REQUIRE(h.readOptions(incomplete_options_file) == HighsStatus::kOk);
560+
561+
std::remove(incomplete_options_file.c_str());
562+
}

highs/io/LoadOptions.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ HighsLoadOptionsStatus loadOptionsFromFile(
2929
while (file.good()) {
3030
getline(file, line);
3131
line_count++;
32-
if (line.size() == 0 || line[0] == '#') continue;
33-
32+
size_t non_space = line.find_first_not_of(" ");
33+
if (line.size() == 0 || line[0] == '#' || non_space == std::string::npos)
34+
continue;
3435
size_t equals = line.find_first_of("=");
3536
if (equals == std::string::npos || equals + 1 >= line.size()) {
3637
highsLogUser(report_log_options, HighsLogType::kError,
37-
"Error on line %" HIGHSINT_FORMAT " of options file.\n",
38-
line_count);
38+
"Error on line %" HIGHSINT_FORMAT
39+
" (\"%s\") of options file\n",
40+
line_count, line.c_str());
3941
return HighsLoadOptionsStatus::kError;
4042
}
4143
option = line.substr(0, equals);

highs/pdlp/hipdlp/pdhg.cc

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
521521
halpern_iteration_ = 0;
522522
}
523523

524-
#ifdef CUPDLP_GPU
524+
#ifdef CUPDLP_GPU
525525
if (!params_.use_halpern_restart) {
526526
CUDA_CHECK(cudaMemset(d_x_sum_, 0, lp_.num_col_ * sizeof(double)));
527527
CUDA_CHECK(cudaMemset(d_y_sum_, 0, lp_.num_row_ * sizeof(double)));
@@ -531,11 +531,9 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
531531
sum_weights_gpu_ = 0.0;
532532

533533
CUDA_CHECK(cudaMemcpy(d_x_current_, x_current_.data(),
534-
lp_.num_col_ * sizeof(double),
535-
cudaMemcpyHostToDevice));
534+
lp_.num_col_ * sizeof(double), cudaMemcpyHostToDevice));
536535
CUDA_CHECK(cudaMemcpy(d_y_current_, y_current_.data(),
537-
lp_.num_row_ * sizeof(double),
538-
cudaMemcpyHostToDevice));
536+
lp_.num_row_ * sizeof(double), cudaMemcpyHostToDevice));
539537

540538
if (params_.use_halpern_restart) {
541539
CUDA_CHECK(cudaMemcpy(d_x_anchor_, d_x_current_,
@@ -548,10 +546,10 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
548546

549547
linalgGpuAx(d_x_current_, d_ax_current_);
550548
linalgGpuATy(d_y_current_, d_aty_current_);
551-
#else
549+
#else
552550
linalg::ax(lp_, x_current_, Ax_cache_);
553551
linalg::aTy(lp_, y_current_, ATy_cache_);
554-
#endif
552+
#endif
555553

556554
TerminationStatus termination_status = TerminationStatus::NOTSET;
557555
bool do_restart = false;
@@ -834,10 +832,9 @@ bool PDLPSolver::runConvergenceCheck(size_t iter, std::vector<double>& output_x,
834832
current_results, "[L]", dSlackPos_, dSlackNeg_);
835833
}
836834
if (!params_.use_halpern_restart) {
837-
average_converged =
838-
checkConvergence(iter, x_avg_, y_avg_, Ax_avg_, ATy_avg_,
839-
params_.tolerance, average_results, "[A]",
840-
dSlackPosAvg_, dSlackNegAvg_);
835+
average_converged = checkConvergence(
836+
iter, x_avg_, y_avg_, Ax_avg_, ATy_avg_, params_.tolerance,
837+
average_results, "[A]", dSlackPosAvg_, dSlackNegAvg_);
841838
}
842839
#endif
843840

@@ -1706,12 +1703,12 @@ double PDLPSolver::powerMethodGpu() {
17061703
cusparseDnVecDescr_t vecEigen = nullptr;
17071704
cusparseDnVecDescr_t vecNextEigen = nullptr;
17081705
cusparseDnVecDescr_t vecDual = nullptr;
1709-
CUSPARSE_CHECK(cusparseCreateDnVec(&vecEigen, a_num_rows_, d_eigenvector,
1710-
CUDA_R_64F));
1706+
CUSPARSE_CHECK(
1707+
cusparseCreateDnVec(&vecEigen, a_num_rows_, d_eigenvector, CUDA_R_64F));
17111708
CUSPARSE_CHECK(cusparseCreateDnVec(&vecNextEigen, a_num_rows_,
17121709
d_next_eigenvector, CUDA_R_64F));
1713-
CUSPARSE_CHECK(cusparseCreateDnVec(&vecDual, a_num_cols_, d_dual_product,
1714-
CUDA_R_64F));
1710+
CUSPARSE_CHECK(
1711+
cusparseCreateDnVec(&vecDual, a_num_cols_, d_dual_product, CUDA_R_64F));
17151712

17161713
CUSPARSE_CHECK(cusparseSpMV_bufferSize(
17171714
cusparse_handle_, CUSPARSE_OPERATION_NON_TRANSPOSE, &one, mat_a_T_csr_,
@@ -1744,18 +1741,16 @@ double PDLPSolver::powerMethodGpu() {
17441741
CUSPARSE_CHECK(cusparseDnVecSetValues(vecNextEigen, d_next_eigenvector));
17451742
CUSPARSE_CHECK(cusparseDnVecSetValues(vecDual, d_dual_product));
17461743

1747-
CUSPARSE_CHECK(cusparseSpMV(cusparse_handle_,
1748-
CUSPARSE_OPERATION_NON_TRANSPOSE, &one,
1749-
mat_a_T_csr_, vecNextEigen, &zero, vecDual,
1750-
CUDA_R_64F, CUSPARSE_SPMV_CSR_ALG2,
1751-
d_buffer_at));
1744+
CUSPARSE_CHECK(
1745+
cusparseSpMV(cusparse_handle_, CUSPARSE_OPERATION_NON_TRANSPOSE, &one,
1746+
mat_a_T_csr_, vecNextEigen, &zero, vecDual, CUDA_R_64F,
1747+
CUSPARSE_SPMV_CSR_ALG2, d_buffer_at));
17521748

17531749
CUSPARSE_CHECK(cusparseDnVecSetValues(vecEigen, d_eigenvector));
1754-
CUSPARSE_CHECK(cusparseSpMV(cusparse_handle_,
1755-
CUSPARSE_OPERATION_NON_TRANSPOSE, &one,
1756-
mat_a_csr_, vecDual, &zero, vecEigen,
1757-
CUDA_R_64F, CUSPARSE_SPMV_CSR_ALG2,
1758-
d_buffer_a));
1750+
CUSPARSE_CHECK(
1751+
cusparseSpMV(cusparse_handle_, CUSPARSE_OPERATION_NON_TRANSPOSE, &one,
1752+
mat_a_csr_, vecDual, &zero, vecEigen, CUDA_R_64F,
1753+
CUSPARSE_SPMV_CSR_ALG2, d_buffer_a));
17591754

17601755
CUBLAS_CHECK(cublasDdot(cublas_handle_, a_num_rows_, d_next_eigenvector, 1,
17611756
d_eigenvector, 1, &sigma_max_sq));

0 commit comments

Comments
 (0)