From 842d1779c7e023ff1f356b8a388b4f7b0c3478f5 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Fri, 3 Nov 2023 16:09:40 -0400 Subject: [PATCH 1/2] Switch to using non-concurrent vector with fixed indicies for multi-pathfinder --- src/stan/services/pathfinder/multi.hpp | 32 ++++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/stan/services/pathfinder/multi.hpp b/src/stan/services/pathfinder/multi.hpp index b9b8d2ab41..cbf01ead8b 100644 --- a/src/stan/services/pathfinder/multi.hpp +++ b/src/stan/services/pathfinder/multi.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -101,12 +100,11 @@ inline int pathfinder_lbfgs_multi( model.constrained_param_names(param_names, true, true); parameter_writer(param_names); - tbb::concurrent_vector> - individual_lp_ratios; - individual_lp_ratios.reserve(num_paths); - tbb::concurrent_vector> + std::vector> individual_lp_ratios; + individual_lp_ratios.resize(num_paths); + std::vector> individual_samples; - individual_samples.reserve(num_paths); + individual_samples.resize(num_paths); std::atomic lp_calls{0}; tbb::parallel_for( tbb::blocked_range(0, num_paths), [&](tbb::blocked_range r) { @@ -125,13 +123,27 @@ inline int pathfinder_lbfgs_multi( + std::to_string(iter) + " failed."); return; } - individual_lp_ratios.emplace_back( - std::move(std::get<1>(pathfinder_ret))); - individual_samples.emplace_back( - std::move(std::get<2>(pathfinder_ret))); + individual_lp_ratios[iter] = std::move(std::get<1>(pathfinder_ret)); + individual_samples[iter] = std::move(std::get<2>(pathfinder_ret)); lp_calls += std::get<3>(pathfinder_ret); } }); + + // if any pathfinders failed, we want to remove their empty results + individual_lp_ratios.erase( + std::remove_if(individual_lp_ratios.begin(), individual_lp_ratios.end(), + [](const auto& v) { + return v.size() == 0; + }), + individual_lp_ratios.end()); + individual_samples.erase( + std::remove_if( + individual_samples.begin(), individual_samples.end(), + [](const auto& v) { + return v.size() == 0; + }), + individual_samples.end()); + const auto end_pathfinders_time = std::chrono::steady_clock::now(); const double pathfinders_delta_time = stan::services::util::duration_diff( From 783626424343b030b0bb74b33872e96f1cc2475f Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Fri, 3 Nov 2023 16:17:55 -0400 Subject: [PATCH 2/2] [Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1 --- src/stan/services/pathfinder/multi.hpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/stan/services/pathfinder/multi.hpp b/src/stan/services/pathfinder/multi.hpp index cbf01ead8b..585a5ebffa 100644 --- a/src/stan/services/pathfinder/multi.hpp +++ b/src/stan/services/pathfinder/multi.hpp @@ -132,16 +132,11 @@ inline int pathfinder_lbfgs_multi( // if any pathfinders failed, we want to remove their empty results individual_lp_ratios.erase( std::remove_if(individual_lp_ratios.begin(), individual_lp_ratios.end(), - [](const auto& v) { - return v.size() == 0; - }), + [](const auto& v) { return v.size() == 0; }), individual_lp_ratios.end()); individual_samples.erase( - std::remove_if( - individual_samples.begin(), individual_samples.end(), - [](const auto& v) { - return v.size() == 0; - }), + std::remove_if(individual_samples.begin(), individual_samples.end(), + [](const auto& v) { return v.size() == 0; }), individual_samples.end()); const auto end_pathfinders_time = std::chrono::steady_clock::now();