Skip to content

Commit b0f051a

Browse files
committedMar 1, 2018
[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
1 parent 69d6d7a commit b0f051a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed
 

‎openmp/runtime/test/ompt/misc/interoperability.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,31 @@
33

44
#include <iostream>
55
#include <thread>
6+
67
#include "callback.h"
8+
#include "omp.h"
9+
710
int condition = 0;
11+
812
void f() {
13+
// Call OpenMP API function to force initialization of OMPT.
14+
// (omp_get_thread_num() does not work because it just returns 0 if the
15+
// runtime isn't initialized yet...)
16+
omp_get_num_threads();
17+
918
OMPT_SIGNAL(condition);
10-
// wait for both pthreads to arrive
19+
// Wait for both initial threads to arrive that will eventually become the
20+
// master threads in the following parallel region.
1121
OMPT_WAIT(condition, 2);
12-
int i = 0;
22+
1323
#pragma omp parallel num_threads(2)
1424
{
25+
// Wait for all threads to arrive so that no worker thread can be reused...
1526
OMPT_SIGNAL(condition);
1627
OMPT_WAIT(condition, 6);
1728
}
1829
}
30+
1931
int main() {
2032
std::thread t1(f);
2133
std::thread t2(f);

0 commit comments

Comments
 (0)
Please sign in to comment.