-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP -- OpenMP automate settings to get good performance
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |