[Openmp-commits] [openmp] r326435 - [OMPT] Fix interoperability test with GCC

Jonas Hahnfeld via Openmp-commits openmp-commits at lists.llvm.org
Thu Mar 1 06:03:18 PST 2018


Author: hahnfeld
Date: Thu Mar  1 06:03:18 2018
New Revision: 326435

URL: http://llvm.org/viewvc/llvm-project?rev=326435&view=rev
Log:
[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

Modified:
    openmp/trunk/runtime/test/ompt/misc/interoperability.cpp

Modified: openmp/trunk/runtime/test/ompt/misc/interoperability.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/test/ompt/misc/interoperability.cpp?rev=326435&r1=326434&r2=326435&view=diff
==============================================================================
--- openmp/trunk/runtime/test/ompt/misc/interoperability.cpp (original)
+++ openmp/trunk/runtime/test/ompt/misc/interoperability.cpp Thu Mar  1 06:03:18 2018
@@ -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);




More information about the Openmp-commits mailing list