[Openmp-commits] [openmp] r322620 - [OMPT] Return appropiate values for ompt runtime entry points for non-OpenMP threads

Joachim Protze via Openmp-commits openmp-commits at lists.llvm.org
Wed Jan 17 02:05:55 PST 2018


Author: jprotze
Date: Wed Jan 17 02:05:55 2018
New Revision: 322620

URL: http://llvm.org/viewvc/llvm-project?rev=322620&view=rev
Log:
[OMPT] Return appropiate values for ompt runtime entry points for non-OpenMP threads

When the current thread is not an (initialized) OpenMP thread, the runtime
entry points return values that correspond to "not available" or similar

Differential Revision: https://reviews.llvm.org/D41167

Added:
    openmp/trunk/runtime/test/ompt/misc/api_calls_from_other_thread.cpp
Modified:
    openmp/trunk/runtime/src/ompt-general.cpp
    openmp/trunk/runtime/src/ompt-specific.cpp

Modified: openmp/trunk/runtime/src/ompt-general.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/ompt-general.cpp?rev=322620&r1=322619&r2=322620&view=diff
==============================================================================
--- openmp/trunk/runtime/src/ompt-general.cpp (original)
+++ openmp/trunk/runtime/src/ompt-general.cpp Wed Jan 17 02:05:55 2018
@@ -553,6 +553,9 @@ OMPT_API_ROUTINE int ompt_get_place_num(
 #if !KMP_AFFINITY_SUPPORTED
   return -1;
 #else
+  if (__kmp_get_gtid() < 0)
+    return -1;
+
   int gtid;
   kmp_info_t *thread;
   if (!KMP_AFFINITY_CAPABLE())
@@ -571,6 +574,9 @@ OMPT_API_ROUTINE int ompt_get_partition_
 #if !KMP_AFFINITY_SUPPORTED
   return 0;
 #else
+  if (__kmp_get_gtid() < 0)
+    return 0;
+
   int i, gtid, place_num, first_place, last_place, start, end;
   kmp_info_t *thread;
   if (!KMP_AFFINITY_CAPABLE())
@@ -604,6 +610,9 @@ OMPT_API_ROUTINE int ompt_get_partition_
 
 OMPT_API_ROUTINE int ompt_get_proc_id(void) {
 #if KMP_OS_LINUX
+  if (__kmp_get_gtid() < 0)
+    return -1;
+
   return sched_getcpu();
 #else
   return -1;

Modified: openmp/trunk/runtime/src/ompt-specific.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/ompt-specific.cpp?rev=322620&r1=322619&r2=322620&view=diff
==============================================================================
--- openmp/trunk/runtime/src/ompt-specific.cpp (original)
+++ openmp/trunk/runtime/src/ompt-specific.cpp Wed Jan 17 02:05:55 2018
@@ -219,16 +219,20 @@ omp_state_t __ompt_get_state_internal(om
 int __ompt_get_parallel_info_internal(int ancestor_level,
                                       ompt_data_t **parallel_data,
                                       int *team_size) {
-  ompt_team_info_t *info;
-  if (team_size) {
-    info = __ompt_get_teaminfo(ancestor_level, team_size);
+  if (__kmp_get_gtid() >= 0) {
+    ompt_team_info_t *info;
+    if (team_size) {
+      info = __ompt_get_teaminfo(ancestor_level, team_size);
+    } else {
+      info = __ompt_get_teaminfo(ancestor_level, NULL);
+    }
+    if (parallel_data) {
+      *parallel_data = info ? &(info->parallel_data) : NULL;
+    }
+    return info ? 2 : 0;
   } else {
-    info = __ompt_get_teaminfo(ancestor_level, NULL);
-  }
-  if (parallel_data) {
-    *parallel_data = info ? &(info->parallel_data) : NULL;
+    return 0;
   }
-  return info ? 2 : 0;
 }
 
 //----------------------------------------------------------
@@ -314,6 +318,9 @@ int __ompt_get_task_info_internal(int an
                                   ompt_frame_t **task_frame,
                                   ompt_data_t **parallel_data,
                                   int *thread_num) {
+  if (__kmp_get_gtid() < 0)
+    return 0;
+
   if (ancestor_level < 0)
     return 0;
 

Added: openmp/trunk/runtime/test/ompt/misc/api_calls_from_other_thread.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/test/ompt/misc/api_calls_from_other_thread.cpp?rev=322620&view=auto
==============================================================================
--- openmp/trunk/runtime/test/ompt/misc/api_calls_from_other_thread.cpp (added)
+++ openmp/trunk/runtime/test/ompt/misc/api_calls_from_other_thread.cpp Wed Jan 17 02:05:55 2018
@@ -0,0 +1,51 @@
+// RUN: env OMP_PLACES=cores %libomp-cxx-compile-and-run | FileCheck %s
+// REQUIRES: ompt, linux
+
+#include <thread>
+#include "callback.h"
+
+void f() {
+    ompt_data_t* tdata = ompt_get_thread_data();
+    uint64_t tvalue = tdata ? tdata->value : 0;
+
+    printf("%" PRIu64 ": ompt_get_num_places()=%d\n", tvalue, ompt_get_num_places());
+
+    printf("%" PRIu64 ": ompt_get_place_proc_ids()=%d\n", tvalue, ompt_get_place_proc_ids(0, 0, NULL));
+
+    printf("%" PRIu64 ": ompt_get_place_num()=%d\n", tvalue, ompt_get_place_num());
+
+    printf("%" PRIu64 ": ompt_get_partition_place_nums()=%d\n", tvalue, ompt_get_partition_place_nums(0, NULL));
+
+    printf("%" PRIu64 ": ompt_get_proc_id()=%d\n", tvalue, ompt_get_proc_id());
+
+    printf("%" PRIu64 ": ompt_get_num_procs()=%d\n", tvalue, ompt_get_num_procs());
+}
+
+
+int main()
+{
+  #pragma omp parallel num_threads(1)
+  {}
+
+  std::thread t1(f);
+  t1.join();
+
+  // Check if libomp supports the callbacks for this test.
+
+  // CHECK: 0: NULL_POINTER=[[NULL:.*$]]
+
+  // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_get_num_places()=0
+
+  // CHECK: {{^}}[[MASTER_ID]]: ompt_get_place_proc_ids()=0
+
+  // CHECK: {{^}}[[MASTER_ID]]: ompt_get_place_num()=-1
+
+  // CHECK: {{^}}[[MASTER_ID]]: ompt_get_partition_place_nums()=0
+
+  // CHECK: {{^}}[[MASTER_ID]]: ompt_get_proc_id()=-1
+
+  // CHECK: {{^}}[[MASTER_ID]]: ompt_get_num_procs()={{[0-9]+}}
+
+
+  return 0;
+}




More information about the Openmp-commits mailing list