[Openmp-commits] [PATCH] D43882: [OMPT] Fix interoperability test with GCC

Jonas Hahnfeld via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Feb 28 10:24:30 PST 2018


Hahnfeld created this revision.
Hahnfeld added reviewers: protze.joachim, jlpeyton, hbae, omalyshe.
Herald added a subscriber: openmp-commits.

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.


Repository:
  rOMP OpenMP

https://reviews.llvm.org/D43882

Files:
  runtime/test/ompt/misc/interoperability.cpp


Index: runtime/test/ompt/misc/interoperability.cpp
===================================================================
--- runtime/test/ompt/misc/interoperability.cpp
+++ runtime/test/ompt/misc/interoperability.cpp
@@ -3,19 +3,30 @@
 
 #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 master threads to arrive.
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43882.136330.patch
Type: text/x-patch
Size: 967 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20180228/7eddfe88/attachment-0001.bin>


More information about the Openmp-commits mailing list