diff options
author | Erik Schnetter <schnetter@cct.lsu.edu> | 2008-01-14 15:04:00 +0000 |
---|---|---|
committer | Erik Schnetter <schnetter@cct.lsu.edu> | 2008-01-14 15:04:00 +0000 |
commit | edd306959a8c5980f6fba2c5dd99d92aee62785c (patch) | |
tree | 52ec752204f883413ce386b544e67708e023e4d7 /Carpet/CarpetLib | |
parent | 5efeed6cad5bc6045cf1c54215a4274153963a17 (diff) |
CarpetLib: Set number of OpenMP threads via an external function call
Set the number of OpenMP threads via an external function call instead
of via a CarpetLib parameter.
darcs-hash:20080114150439-dae7b-a6a6a629162ca195411852823e1ece0a2071d771.gz
Diffstat (limited to 'Carpet/CarpetLib')
-rw-r--r-- | Carpet/CarpetLib/param.ccl | 8 | ||||
-rw-r--r-- | Carpet/CarpetLib/src/dist.cc | 18 | ||||
-rw-r--r-- | Carpet/CarpetLib/src/dist.hh | 14 |
3 files changed, 15 insertions, 25 deletions
diff --git a/Carpet/CarpetLib/param.ccl b/Carpet/CarpetLib/param.ccl index 4ed749066..f058923a2 100644 --- a/Carpet/CarpetLib/param.ccl +++ b/Carpet/CarpetLib/param.ccl @@ -23,14 +23,6 @@ BOOLEAN barriers "Insert barriers at strategic places for debugging purposes (sl -CCTK_INT num_threads "Number of threads per process" STEERABLE=recover -{ - -1 :: "use system default, probably influenced by OMP_NUM_THREADS" - 1:* :: "use this many threads" -} -1 - - - BOOLEAN output_bboxes "Output bounding box information to the screen" STEERABLE=always { } "no" diff --git a/Carpet/CarpetLib/src/dist.cc b/Carpet/CarpetLib/src/dist.cc index 1af4bcf38..7ac6f73f6 100644 --- a/Carpet/CarpetLib/src/dist.cc +++ b/Carpet/CarpetLib/src/dist.cc @@ -1,9 +1,9 @@ #include <cassert> +#include <mpi.h> #ifdef _OPENMP # include <omp.h> #endif -#include <mpi.h> #include "cctk.h" #include "cctk_Parameters.h" @@ -66,33 +66,21 @@ namespace dist { } } - // Local number of threads - int num_threads_worker () + // Set number of threads + void set_num_threads (int const num_threads) { - DECLARE_CCTK_PARAMETERS; - int num_threads_; #ifdef _OPENMP if (num_threads > 0) { // Set number of threads which should be used // TODO: do this at startup, not in this routine omp_set_num_threads (num_threads); } -#pragma omp parallel - { -#pragma omp single nowait - { - num_threads_ = omp_get_num_threads(); - } - } #else if (num_threads > 0 and num_threads != 1) { CCTK_WARN (CCTK_WARN_ABORT, "OpenMP is not enabled. Cannot set the number of threads."); } - num_threads_ = 1; #endif - assert (num_threads_ >= 1); - return num_threads_; } // Global number of threads diff --git a/Carpet/CarpetLib/src/dist.hh b/Carpet/CarpetLib/src/dist.hh index 1206901e3..7d501c857 100644 --- a/Carpet/CarpetLib/src/dist.hh +++ b/Carpet/CarpetLib/src/dist.hh @@ -6,6 +6,9 @@ #include <cstdlib> #include <mpi.h> +#ifdef _OPENMP +# include <omp.h> +#endif #include "cctk.h" @@ -63,13 +66,20 @@ namespace dist { return size_; } + // Set number of threads + void set_num_threads (int num_threads); + // Local number of threads - int num_threads_worker (); inline int num_threads () { static int num_threads_ = -1; if (num_threads_ == -1) { - num_threads_ = num_threads_worker(); +#ifdef _OPENMP + num_threads_ = omp_get_max_threads(); +#else + num_threads_ = 1; +#endif + assert (num_threads_ >= 1); } return num_threads_; } |