Skip to content
Snippets Groups Projects
Unverified Commit 836687b5 authored by Carlo Camilloni's avatar Carlo Camilloni Committed by GitHub
Browse files

V2.4 set omp (#398)

* OpenMP changes to allow setting the number of threads from main code
furthermore avoiding to call getenv more than once (it is faster)

* setOpenMP: gromacs patch enabled to set the number of openMP threads

* OpenMP: moved static variables inside  a struct/function couple

* OpenMP: removed api interface and gromacs patch

* astyle
parent fc15d7f3
No related branches found
No related tags found
No related merge requests found
...@@ -29,16 +29,37 @@ ...@@ -29,16 +29,37 @@
namespace PLMD { namespace PLMD {
struct OpenMPVars {
unsigned cacheline_size=512;
bool cache_set=false;
unsigned num_threads=1;
bool nt_env_set=false;
};
static OpenMPVars & getOpenMPVars() {
static OpenMPVars vars;
return vars;
}
void OpenMP::setNumThreads(const unsigned nt) {
getOpenMPVars().num_threads=nt;
}
unsigned OpenMP::getCachelineSize() { unsigned OpenMP::getCachelineSize() {
static unsigned cachelineSize=512; if(!getOpenMPVars().cache_set) {
if(std::getenv("PLUMED_CACHELINE_SIZE")) Tools::convert(std::getenv("PLUMED_CACHELINE_SIZE"),cachelineSize); if(std::getenv("PLUMED_CACHELINE_SIZE")) Tools::convert(std::getenv("PLUMED_CACHELINE_SIZE"),getOpenMPVars().cacheline_size);
return cachelineSize; getOpenMPVars().cache_set = true;
}
return getOpenMPVars().cacheline_size;
} }
unsigned OpenMP::getNumThreads() { unsigned OpenMP::getNumThreads() {
static unsigned numThreads=1; if(!getOpenMPVars().nt_env_set) {
if(std::getenv("PLUMED_NUM_THREADS")) Tools::convert(std::getenv("PLUMED_NUM_THREADS"),numThreads); if(std::getenv("PLUMED_NUM_THREADS")) Tools::convert(std::getenv("PLUMED_NUM_THREADS"),getOpenMPVars().num_threads);
return numThreads; getOpenMPVars().nt_env_set = true;
}
return getOpenMPVars().num_threads;
} }
unsigned OpenMP::getThreadNum() { unsigned OpenMP::getThreadNum() {
......
...@@ -30,6 +30,9 @@ class OpenMP { ...@@ -30,6 +30,9 @@ class OpenMP {
public: public:
/// Set number of threads that can be used by openMP
static void setNumThreads(const unsigned nt);
/// Get number of threads that can be used by openMP /// Get number of threads that can be used by openMP
static unsigned getNumThreads(); static unsigned getNumThreads();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment