Skip to content

Commit

Permalink
WIP -- OpenMP automate settings to get good performance
Browse files Browse the repository at this point in the history
  • Loading branch information
burlen committed Jun 23, 2023
1 parent e5a58ae commit 0032dc2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(teca_core_srcs
teca_bad_cast.cxx
teca_binary_stream.cxx
teca_common.cxx
teca_core_init.cxx
teca_dataset.cxx
teca_dataset_capture.cxx
teca_index_executive.cxx
Expand Down
33 changes: 33 additions & 0 deletions core/teca_core_init.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
#include <string>
#include <cstdlib>
#include <thread>

__attribute__((constructor)) void init(void)
{
std::cerr << "teca initializing ... " << std::endl;

// do something reasonable if the user doesn't. TODO -- see if we can use
// MPI here so we can coordinate thread placement across all ranks on the
// same node.
if (!getenv("OMP_NUM_THREADS"))
{
int n_threads = std::max(1u, std::thread::hardware_concurrency() / 2);
setenv("OMP_NUM_THREADS", std::to_string(n_threads).c_str(), 1);
}

if (!getenv("OMP_PROC_BIND"))
setenv("OMP_PROC_BIND", "true", 1);

if (!getenv("OMP_PLACES"))
setenv("OMP_PLACES", "cores", 1);

// TODO -- remove these, they just prove that the ab ove works.
setenv("OMP_DISPLAY_ENV", "true", 1);
setenv("OMP_DISPLAY_AFFINITY", "true", 1);
}

__attribute__((destructor)) void fini(void)
{
std::cerr << "teca finalizing ... " << std::endl;
}

0 comments on commit 0032dc2

Please sign in to comment.