Skip to content

Commit

Permalink
cleanup(batch/parallel): compile with openmp and set threads (#351)
Browse files Browse the repository at this point in the history
* cleanup(batch/parallel): compile with openmp and set threads

* add cmake suggestions
  • Loading branch information
alevenberg committed Jun 7, 2024
1 parent 5052b38 commit d450eb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions batch/parallel/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ set(PACKAGE_BUGREPORT
"https://github.com/GoogleCloudPlatform/cpp-samples/issues")
project(cpp-samples-batch CXX)

find_package(OpenMP REQUIRED)

add_executable(finsim src/finsim.cc)
target_link_libraries(finsim PRIVATE OpenMP::OpenMP_CXX)
2 changes: 2 additions & 0 deletions batch/parallel/application/src/finsim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ int main(int argc, char* argv[]) {
std::vector<double> results(input_config.simulations);
simulate(input_config);

omp_set_num_threads(input_config.total_threads);

#pragma omp parallel for
for (int i = 0; i < input_config.simulations; i++) {
results[i] = simulate(input_config);
Expand Down

0 comments on commit d450eb3

Please sign in to comment.