summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Hahnfeld <hahnjo@hahnjo.de>2018-03-01 14:03:18 +0000
committerJonas Hahnfeld <hahnjo@hahnjo.de>2018-03-01 14:03:18 +0000
commitb0f051ae63e02f135cf8550deefc3e349c77b546 (patch)
tree88b995e9ac4cb0f12483182d4502fb293481ad74
parent69d6d7a4d8f5d6c8b4fdc003d77ec83812528344 (diff)
downloadbcm5719-llvm-b0f051ae63e02f135cf8550deefc3e349c77b546.tar.gz
bcm5719-llvm-b0f051ae63e02f135cf8550deefc3e349c77b546.zip
[OMPT] Fix interoperability test with GCC
We have to ensure that the runtime is initialized _before_ waiting for the two started threads to guarantee that the master threads post their ompt_event_thread_begin before the worker threads. This is not guaranteed in the parallel region where one worker thread could start before the other master thread has invoked the callback. The problem did not happen with Clang becauses the generated code calls __kmpc_global_thread_num() and cashes its result for functions that contain OpenMP pragmas. Differential Revision: https://reviews.llvm.org/D43882 llvm-svn: 326435
-rw-r--r--openmp/runtime/test/ompt/misc/interoperability.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/openmp/runtime/test/ompt/misc/interoperability.cpp b/openmp/runtime/test/ompt/misc/interoperability.cpp
index 862276470fe..5072f91e14c 100644
--- a/openmp/runtime/test/ompt/misc/interoperability.cpp
+++ b/openmp/runtime/test/ompt/misc/interoperability.cpp
@@ -3,19 +3,31 @@
#include <iostream>
#include <thread>
+
#include "callback.h"
+#include "omp.h"
+
int condition = 0;
+
void f() {
+ // Call OpenMP API function to force initialization of OMPT.
+ // (omp_get_thread_num() does not work because it just returns 0 if the
+ // runtime isn't initialized yet...)
+ omp_get_num_threads();
+
OMPT_SIGNAL(condition);
- // wait for both pthreads to arrive
+ // Wait for both initial threads to arrive that will eventually become the
+ // master threads in the following parallel region.
OMPT_WAIT(condition, 2);
- int i = 0;
+
#pragma omp parallel num_threads(2)
{
+ // Wait for all threads to arrive so that no worker thread can be reused...
OMPT_SIGNAL(condition);
OMPT_WAIT(condition, 6);
}
}
+
int main() {
std::thread t1(f);
std::thread t2(f);
OpenPOWER on IntegriCloud