aboutsummaryrefslogtreecommitdiff
path: root/Carpet
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2008-01-14 15:04:00 +0000
committerErik Schnetter <schnetter@cct.lsu.edu>2008-01-14 15:04:00 +0000
commit39a9cb3421a4389682f976e96f56ce5c12b19367 (patch)
tree52ec752204f883413ce386b544e67708e023e4d7 /Carpet
parentf807babfa91385dd4b949704c8761b0b71940eb3 (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')
-rw-r--r--Carpet/CarpetLib/param.ccl8
-rw-r--r--Carpet/CarpetLib/src/dist.cc18
-rw-r--r--Carpet/CarpetLib/src/dist.hh14
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_;
}