Skip to content

Commit

Permalink
cleanup(batch/parallel): compile with openmp and set threads
Browse files Browse the repository at this point in the history
  • Loading branch information
alevenberg committed Jun 6, 2024
1 parent 90351b0 commit e2bcf38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions batch/parallel/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ set(PACKAGE_BUGREPORT
"https://github.com/GoogleCloudPlatform/cpp-samples/issues")
project(cpp-samples-batch CXX)

find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

add_executable(finsim src/finsim.cc)
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 e2bcf38

Please sign in to comment.