aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src
diff options
context:
space:
mode:
Diffstat (limited to 'Carpet/CarpetLib/src')
-rw-r--r--Carpet/CarpetLib/src/dist.cc4
-rw-r--r--Carpet/CarpetLib/src/dist.hh8
2 files changed, 12 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/src/dist.cc b/Carpet/CarpetLib/src/dist.cc
index d773d644e..ad0d46696 100644
--- a/Carpet/CarpetLib/src/dist.cc
+++ b/Carpet/CarpetLib/src/dist.cc
@@ -39,6 +39,7 @@ namespace dist {
int num_threads_ = -1;
int total_num_threads_ = -1;
+ int thread_num_ = -1;
@@ -464,6 +465,7 @@ namespace dist {
{
num_threads_ = omp_get_num_threads();
}
+ thread_num_ = omp_get_thread_num();
}
int const max_threads = omp_get_max_threads();
if (max_threads != num_threads_) {
@@ -473,8 +475,10 @@ namespace dist {
}
#else
num_threads_ = 1;
+ thread_num_ = 0;
#endif
assert (num_threads_ >= 1);
+ assert (thread_num_ >= 0 and thread_num_ < num_threads_);
MPI_Allreduce
(const_cast <int *> (& num_threads_), & total_num_threads_, 1, MPI_INT,
diff --git a/Carpet/CarpetLib/src/dist.hh b/Carpet/CarpetLib/src/dist.hh
index cb0770efe..8634ed0ae 100644
--- a/Carpet/CarpetLib/src/dist.hh
+++ b/Carpet/CarpetLib/src/dist.hh
@@ -37,6 +37,8 @@ namespace dist {
extern int num_threads_;
extern int total_num_threads_;
+ extern int thread_num_;
+#pragma omp threadprivate(thread_num_)
void init (int& argc, char**& argv);
void pseudoinit (MPI_Comm const c);
@@ -180,6 +182,12 @@ namespace dist {
{
return num_threads_;
}
+
+ // My own thread number
+ inline int thread_num ()
+ {
+ return thread_num_;
+ }
// Global number of threads
void collect_total_num_threads ();