From e0213567bf7569ff855ab820a91348ae62c98f90 Mon Sep 17 00:00:00 2001 From: Hall Date: Mon, 28 Nov 2022 21:45:48 +0000 Subject: [PATCH 1/4] Modified dependent equations timeout so it also works on a model of the time remaining, otherwise bdry2 never times out --- src/util/HFactor.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/util/HFactor.cpp b/src/util/HFactor.cpp index 3eb759fa74..9b954884a1 100644 --- a/src/util/HFactor.cpp +++ b/src/util/HFactor.cpp @@ -879,7 +879,10 @@ HighsInt HFactor::buildKernel() { const bool progress_report = false; // num_basic != num_row; const HighsInt progress_frequency = 10000; - const HighsInt timer_frequency = 100; + // Initial timer frequency: may be reduced if iterations get slow + HighsInt timer_frequency = 100; + double previous_iteration_time = 0; + double iteration_time = 0; const bool check_for_timeout = this->time_limit_ < kHighsInf; HighsInt search_k = 0; @@ -890,9 +893,19 @@ HighsInt HFactor::buildKernel() { reportAsm(); } // Detemine whether to return due to exceeding the time limit - if (check_for_timeout && search_k % timer_frequency == 0) - if (build_timer_->readRunHighsClock() > this->time_limit_) + if (check_for_timeout && search_k % timer_frequency == 0) { + double current_time = build_timer_->readRunHighsClock(); + double time_difference = current_time - previous_iteration_time; + previous_iteration_time = current_time; + iteration_time = time_difference / (1.0 * timer_frequency); + if (time_difference > this->time_limit_/1e3) + timer_frequency = std::max(1, timer_frequency/10); + HighsInt iterations_left = kernel_dim - search_k + 1; + double remaining_time_bound = iteration_time * iterations_left; + double total_time_bound = current_time + remaining_time_bound; + if (current_time > this->time_limit_ || total_time_bound > this->time_limit_) return kBuildKernelReturnTimeout; + } /** * 1. Search for the pivot From b712d6c3f53c53798bda94a5b34192af1344a254 Mon Sep 17 00:00:00 2001 From: Hall Date: Mon, 28 Nov 2022 22:06:23 +0000 Subject: [PATCH 2/4] Switched to running average iteration time --- src/util/HFactor.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util/HFactor.cpp b/src/util/HFactor.cpp index 9b954884a1..4fccc400b3 100644 --- a/src/util/HFactor.cpp +++ b/src/util/HFactor.cpp @@ -882,7 +882,7 @@ HighsInt HFactor::buildKernel() { // Initial timer frequency: may be reduced if iterations get slow HighsInt timer_frequency = 100; double previous_iteration_time = 0; - double iteration_time = 0; + double average_iteration_time = 0; const bool check_for_timeout = this->time_limit_ < kHighsInf; HighsInt search_k = 0; @@ -897,12 +897,16 @@ HighsInt HFactor::buildKernel() { double current_time = build_timer_->readRunHighsClock(); double time_difference = current_time - previous_iteration_time; previous_iteration_time = current_time; - iteration_time = time_difference / (1.0 * timer_frequency); + double iteration_time = time_difference / (1.0 * timer_frequency); + average_iteration_time = 0.9* average_iteration_time + 0.1 * iteration_time; + if (time_difference > this->time_limit_/1e3) timer_frequency = std::max(1, timer_frequency/10); HighsInt iterations_left = kernel_dim - search_k + 1; - double remaining_time_bound = iteration_time * iterations_left; + double remaining_time_bound = average_iteration_time * iterations_left; double total_time_bound = current_time + remaining_time_bound; + printf("%d; Iter: Time %11.4g; average = %11.4g; Bound = %11.4g\n", + search_k, iteration_time, average_iteration_time, total_time_bound); if (current_time > this->time_limit_ || total_time_bound > this->time_limit_) return kBuildKernelReturnTimeout; } From 661ac79528ddfe4154e379f3fcecc91647979dce Mon Sep 17 00:00:00 2001 From: Hall Date: Tue, 29 Nov 2022 09:13:39 +0000 Subject: [PATCH 3/4] Fixed std::max error for 64-bit integers --- src/util/HFactor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/HFactor.cpp b/src/util/HFactor.cpp index 4fccc400b3..90d78f9cdf 100644 --- a/src/util/HFactor.cpp +++ b/src/util/HFactor.cpp @@ -901,7 +901,7 @@ HighsInt HFactor::buildKernel() { average_iteration_time = 0.9* average_iteration_time + 0.1 * iteration_time; if (time_difference > this->time_limit_/1e3) - timer_frequency = std::max(1, timer_frequency/10); + timer_frequency = std::max(HighsInt(1), timer_frequency/10); HighsInt iterations_left = kernel_dim - search_k + 1; double remaining_time_bound = average_iteration_time * iterations_left; double total_time_bound = current_time + remaining_time_bound; From 77cce934825f7c057dc14f212355bb69ca32a0dc Mon Sep 17 00:00:00 2001 From: Hall Date: Tue, 29 Nov 2022 09:18:23 +0000 Subject: [PATCH 4/4] Formatted --- app/RunHighs.cpp | 2 +- check/TestHighsHessian.cpp | 2 +- check/TestHighsParallel.cpp | 2 +- check/TestThrow.cpp | 4 ++-- src/io/HMpsFF.h | 2 +- src/lp_data/HighsDebug.h | 2 +- src/lp_data/HighsInfoDebug.h | 2 +- src/lp_data/HighsModelUtils.h | 12 ++++++------ src/simplex/HApp.h | 14 +++++++------- src/simplex/HEkkDual.cpp | 14 +++++++------- src/simplex/HEkkDualMulti.cpp | 18 +++++++++--------- src/simplex/HSimplex.cpp | 4 ++-- src/simplex/HSimplexNlaDebug.cpp | 2 +- src/simplex/HSimplexNlaProductForm.cpp | 2 +- src/simplex/HighsSimplexAnalysis.cpp | 2 +- src/simplex/SimplexStruct.h | 2 +- src/util/HFactor.cpp | 15 +++++++++------ src/util/HSet.h | 2 +- src/util/HighsMatrixUtils.h | 2 +- 19 files changed, 54 insertions(+), 51 deletions(-) diff --git a/app/RunHighs.cpp b/app/RunHighs.cpp index ded6620453..89c4efceda 100644 --- a/app/RunHighs.cpp +++ b/app/RunHighs.cpp @@ -14,7 +14,7 @@ * @brief HiGHS main */ #include "Highs.h" -//#include "io/HighsIO.h" +// #include "io/HighsIO.h" #include "lp_data/HighsRuntimeOptions.h" void reportModelStatsOrError(const HighsLogOptions& log_options, diff --git a/check/TestHighsHessian.cpp b/check/TestHighsHessian.cpp index 2bf3379c01..3882aea66e 100644 --- a/check/TestHighsHessian.cpp +++ b/check/TestHighsHessian.cpp @@ -2,7 +2,7 @@ #include "lp_data/HighsOptions.h" #include "model/HighsHessian.h" #include "model/HighsHessianUtils.h" -//#include "" +// #include "" const bool dev_run = false; diff --git a/check/TestHighsParallel.cpp b/check/TestHighsParallel.cpp index a070fcb323..cafa374781 100644 --- a/check/TestHighsParallel.cpp +++ b/check/TestHighsParallel.cpp @@ -123,7 +123,7 @@ void matrix_multiplication_omp(unsigned nthreads) { } #endif void matrix_multiplication_highs(unsigned nthreads) { - //#pragma omp parallel for private(i, j) + // #pragma omp parallel for private(i, j) parallel::for_each(0, N, [&](HighsInt start, HighsInt end) { for (int i = start; i < end; ++i) { for (int j = 0; j < N; j++) { diff --git a/check/TestThrow.cpp b/check/TestThrow.cpp index 429c17980b..0088601279 100644 --- a/check/TestThrow.cpp +++ b/check/TestThrow.cpp @@ -1,9 +1,9 @@ -//#include "Highs.h" +// #include "Highs.h" #include #include //Used in HiGHS #include "catch.hpp" -//#include +// #include const bool dev_run = false; void invalidArgument() { diff --git a/src/io/HMpsFF.h b/src/io/HMpsFF.h index 0b855bf0b5..d9936bf93e 100644 --- a/src/io/HMpsFF.h +++ b/src/io/HMpsFF.h @@ -35,7 +35,7 @@ #include "io/HighsIO.h" #include "model/HighsModel.h" -//#include "util/HighsInt.h" +// #include "util/HighsInt.h" #include "util/stringutil.h" using Triplet = std::tuple; diff --git a/src/lp_data/HighsDebug.h b/src/lp_data/HighsDebug.h index a80bd8bd5f..b83ed4cdc8 100644 --- a/src/lp_data/HighsDebug.h +++ b/src/lp_data/HighsDebug.h @@ -23,7 +23,7 @@ #include "lp_data/HConst.h" #include "lp_data/HighsStatus.h" -//#include "lp_data/HighsOptions.h" +// #include "lp_data/HighsOptions.h" HighsStatus debugDebugToHighsStatus(const HighsDebugStatus debug_status); diff --git a/src/lp_data/HighsInfoDebug.h b/src/lp_data/HighsInfoDebug.h index 14127458bb..3821618a0a 100644 --- a/src/lp_data/HighsInfoDebug.h +++ b/src/lp_data/HighsInfoDebug.h @@ -20,7 +20,7 @@ #include "lp_data/HighsInfo.h" #include "lp_data/HighsLp.h" #include "lp_data/HighsOptions.h" -//#include "lp_data/HighsLp.h" +// #include "lp_data/HighsLp.h" HighsDebugStatus debugInfo(const HighsOptions& options, const HighsLp& lp, const HighsBasis& basis, diff --git a/src/lp_data/HighsModelUtils.h b/src/lp_data/HighsModelUtils.h index 35ef675dc4..ffcae965db 100644 --- a/src/lp_data/HighsModelUtils.h +++ b/src/lp_data/HighsModelUtils.h @@ -16,14 +16,14 @@ #ifndef LP_DATA_HIGHSMODELUTILS_H_ #define LP_DATA_HIGHSMODELUTILS_H_ -//#include "Highs.h" -//#include "lp_data/HighsStatus.h" +// #include "Highs.h" +// #include "lp_data/HighsStatus.h" #include "lp_data/HighsInfo.h" #include "model/HighsModel.h" -//#include "lp_data/HStruct.h" -//#include "lp_data/HighsInfo.h" -//#include "lp_data/HighsLp.h" -//#include "lp_data/HighsOptions.h" +// #include "lp_data/HStruct.h" +// #include "lp_data/HighsInfo.h" +// #include "lp_data/HighsLp.h" +// #include "lp_data/HighsOptions.h" // Analyse lower and upper bounds of a model void analyseModelBounds(const HighsLogOptions& log_options, const char* message, diff --git a/src/simplex/HApp.h b/src/simplex/HApp.h index c9a3c6cc06..bb275eaa92 100644 --- a/src/simplex/HApp.h +++ b/src/simplex/HApp.h @@ -14,13 +14,13 @@ #define SIMPLEX_HAPP_H_ // todo: clear includes. -//#include -//#include -//#include -//#include -//#include -//#include -//#include +// #include +// #include +// #include +// #include +// #include +// #include +// #include #include "lp_data/HighsLpSolverObject.h" #include "lp_data/HighsLpUtils.h" diff --git a/src/simplex/HEkkDual.cpp b/src/simplex/HEkkDual.cpp index 4a9f45f051..ee91a698bf 100644 --- a/src/simplex/HEkkDual.cpp +++ b/src/simplex/HEkkDual.cpp @@ -1264,25 +1264,25 @@ void HEkkDual::iterateTasks() { if (1.0 * row_ep.count / solver_num_row < 0.01) slice_PRICE = 0; analysis->simplexTimerStart(Group1Clock); - //#pragma omp parallel - //#pragma omp single + // #pragma omp parallel + // #pragma omp single { - //#pragma omp task + // #pragma omp task highs::parallel::spawn([&]() { col_DSE.copy(&row_ep); updateFtranDSE(&col_DSE); }); - //#pragma omp task + // #pragma omp task { if (slice_PRICE) chooseColumnSlice(&row_ep); else chooseColumn(&row_ep); - //#pragma omp task + // #pragma omp task highs::parallel::spawn([&]() { updateFtranBFRT(); }); - //#pragma omp task + // #pragma omp task updateFtran(); - //#pragma omp taskwait + // #pragma omp taskwait highs::parallel::sync(); } diff --git a/src/simplex/HEkkDualMulti.cpp b/src/simplex/HEkkDualMulti.cpp index a50775288b..95029540f7 100644 --- a/src/simplex/HEkkDualMulti.cpp +++ b/src/simplex/HEkkDualMulti.cpp @@ -44,8 +44,8 @@ void HEkkDual::iterateMulti() { slice_PRICE = 0; if (slice_PRICE) { - //#pragma omp parallel - //#pragma omp single + // #pragma omp parallel + // #pragma omp single chooseColumnSlice(multi_finish[multi_nFinish].row_ep); } else { chooseColumn(multi_finish[multi_nFinish].row_ep); @@ -200,7 +200,7 @@ void HEkkDual::majorChooseRowBtran() { } std::vector& edge_weight = ekk_instance_.dual_edge_weight_; // 4.2 Perform BTRAN - //#pragma omp parallel for schedule(static, 1) + // #pragma omp parallel for schedule(static, 1) // printf("start %d tasks for btran\n", multi_ntasks); // std::vector tmp(multi_ntasks); highs::parallel::for_each(0, multi_ntasks, [&](HighsInt start, HighsInt end) { @@ -491,7 +491,7 @@ void HEkkDual::minorUpdateRows() { } // Perform tasks - //#pragma omp parallel for schedule(dynamic) + // #pragma omp parallel for schedule(dynamic) // printf("minorUpdatesRows: starting %d tasks\n", multi_nTasks); highs::parallel::for_each( 0, multi_nTasks, [&](HighsInt start, HighsInt end) { @@ -650,7 +650,7 @@ void HEkkDual::majorUpdateFtranParallel() { } // Perform FTRAN - //#pragma omp parallel for schedule(dynamic, 1) + // #pragma omp parallel for schedule(dynamic, 1) // printf("majorUpdateFtranParallel: starting %d tasks\n", multi_ntasks); highs::parallel::for_each(0, multi_ntasks, [&](HighsInt start, HighsInt end) { for (HighsInt i = start; i < end; i++) { @@ -714,7 +714,7 @@ void HEkkDual::majorUpdateFtranFinal() { // The FTRAN regular buffer if (fabs(pivotX1) > kHighsTiny) { const double pivot = pivotX1 / pivotAlpha; - //#pragma omp parallel for + // #pragma omp parallel for highs::parallel::for_each( 0, solver_num_row, [&](HighsInt start, HighsInt end) { @@ -727,7 +727,7 @@ void HEkkDual::majorUpdateFtranFinal() { // The FTRAN-DSE buffer if (fabs(pivotX2) > kHighsTiny) { const double pivot = pivotX2 / pivotAlpha; - //#pragma omp parallel for + // #pragma omp parallel for highs::parallel::for_each( 0, solver_num_row, [&](HighsInt start, HighsInt end) { @@ -774,7 +774,7 @@ void HEkkDual::majorUpdatePrimal() { // non-pivotal edge weights const double* mixArray = &col_BFRT.array[0]; double* local_work_infeasibility = &dualRHS.work_infeasibility[0]; - //#pragma omp parallel for schedule(static) + // #pragma omp parallel for schedule(static) highs::parallel::for_each( 0, solver_num_row, [&](HighsInt start, HighsInt end) { @@ -805,7 +805,7 @@ void HEkkDual::majorUpdatePrimal() { // Update steepest edge weights const double* dseArray = &multi_finish[iFn].row_ep->array[0]; const double Kai = -2 / multi_finish[iFn].alpha_row; - //#pragma omp parallel for schedule(static) + // #pragma omp parallel for schedule(static) highs::parallel::for_each( 0, solver_num_row, [&](HighsInt start, HighsInt end) { diff --git a/src/simplex/HSimplex.cpp b/src/simplex/HSimplex.cpp index 837d1e7995..4fb326072b 100644 --- a/src/simplex/HSimplex.cpp +++ b/src/simplex/HSimplex.cpp @@ -21,8 +21,8 @@ #include #include -//#include "lp_data/HighsLpUtils.h" -//#include "util/HighsSort.h" +// #include "lp_data/HighsLpUtils.h" +// #include "util/HighsSort.h" using std::max; using std::min; diff --git a/src/simplex/HSimplexNlaDebug.cpp b/src/simplex/HSimplexNlaDebug.cpp index 349f16647a..daafcfd984 100644 --- a/src/simplex/HSimplexNlaDebug.cpp +++ b/src/simplex/HSimplexNlaDebug.cpp @@ -17,7 +17,7 @@ #include "simplex/HSimplexNla.h" #include "util/HighsRandom.h" -//#include +// #include const double kResidualLargeError = 1e-8; const double kResidualExcessiveError = sqrt(kResidualLargeError); diff --git a/src/simplex/HSimplexNlaProductForm.cpp b/src/simplex/HSimplexNlaProductForm.cpp index 3e8c3f3d6b..237dff089e 100644 --- a/src/simplex/HSimplexNlaProductForm.cpp +++ b/src/simplex/HSimplexNlaProductForm.cpp @@ -16,7 +16,7 @@ */ #include "simplex/HSimplexNla.h" -//#include +// #include #include using std::fabs; diff --git a/src/simplex/HighsSimplexAnalysis.cpp b/src/simplex/HighsSimplexAnalysis.cpp index c362cdfef7..44592bee7b 100644 --- a/src/simplex/HighsSimplexAnalysis.cpp +++ b/src/simplex/HighsSimplexAnalysis.cpp @@ -14,7 +14,7 @@ * @brief */ #include -//#include +// #include #include #include "HConfig.h" diff --git a/src/simplex/SimplexStruct.h b/src/simplex/SimplexStruct.h index 6c97cba48b..02575860ea 100644 --- a/src/simplex/SimplexStruct.h +++ b/src/simplex/SimplexStruct.h @@ -19,7 +19,7 @@ #include #include -//#include "lp_data/HighsLp.h" +// #include "lp_data/HighsLp.h" #include "lp_data/HConst.h" #include "simplex/SimplexConst.h" diff --git a/src/util/HFactor.cpp b/src/util/HFactor.cpp index 90d78f9cdf..8bda0c88d0 100644 --- a/src/util/HFactor.cpp +++ b/src/util/HFactor.cpp @@ -898,16 +898,19 @@ HighsInt HFactor::buildKernel() { double time_difference = current_time - previous_iteration_time; previous_iteration_time = current_time; double iteration_time = time_difference / (1.0 * timer_frequency); - average_iteration_time = 0.9* average_iteration_time + 0.1 * iteration_time; - - if (time_difference > this->time_limit_/1e3) - timer_frequency = std::max(HighsInt(1), timer_frequency/10); + average_iteration_time = + 0.9 * average_iteration_time + 0.1 * iteration_time; + + if (time_difference > this->time_limit_ / 1e3) + timer_frequency = std::max(HighsInt(1), timer_frequency / 10); HighsInt iterations_left = kernel_dim - search_k + 1; double remaining_time_bound = average_iteration_time * iterations_left; double total_time_bound = current_time + remaining_time_bound; printf("%d; Iter: Time %11.4g; average = %11.4g; Bound = %11.4g\n", - search_k, iteration_time, average_iteration_time, total_time_bound); - if (current_time > this->time_limit_ || total_time_bound > this->time_limit_) + search_k, iteration_time, average_iteration_time, + total_time_bound); + if (current_time > this->time_limit_ || + total_time_bound > this->time_limit_) return kBuildKernelReturnTimeout; } diff --git a/src/util/HSet.h b/src/util/HSet.h index 5a9e55a195..18cfd71b20 100644 --- a/src/util/HSet.h +++ b/src/util/HSet.h @@ -24,7 +24,7 @@ #include "util/HighsInt.h" -//#include +// #include using std::vector; diff --git a/src/util/HighsMatrixUtils.h b/src/util/HighsMatrixUtils.h index a12bf67a4d..0dabdc3909 100644 --- a/src/util/HighsMatrixUtils.h +++ b/src/util/HighsMatrixUtils.h @@ -19,7 +19,7 @@ #include #include -//#include "lp_data/HighsStatus.h" +// #include "lp_data/HighsStatus.h" #include "lp_data/HighsOptions.h" using std::vector;