[Openmp-commits] [PATCH] D41167: Return appropiate values for ompt runtime entry points when the current thread is not an OpenMP thread

Simon Convent via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Dec 13 03:48:54 PST 2017


sconvent created this revision.
sconvent added reviewers: protze.joachim, Hahnfeld, jlpeyton.

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


https://reviews.llvm.org/D41167

Files:
  runtime/src/ompt-general.cpp
  runtime/src/ompt-specific.cpp


Index: runtime/src/ompt-specific.cpp
===================================================================
--- runtime/src/ompt-specific.cpp
+++ runtime/src/ompt-specific.cpp
@@ -219,16 +219,21 @@
 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);
-  } else {
-    info = __ompt_get_teaminfo(ancestor_level, NULL);
+  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;
   }
-  if (parallel_data) {
-    *parallel_data = info ? &(info->parallel_data) : NULL;
+  else {
+    return 0;
   }
-  return info ? 2 : 0;
 }
 
 //----------------------------------------------------------
@@ -314,6 +319,9 @@
                                   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;
 
Index: runtime/src/ompt-general.cpp
===================================================================
--- runtime/src/ompt-general.cpp
+++ runtime/src/ompt-general.cpp
@@ -541,6 +541,9 @@
 #if !KMP_AFFINITY_SUPPORTED
   return -1;
 #else
+  if (__kmp_get_gtid() < 0) 
+    return -1;
+
   int gtid;
   kmp_info_t *thread;
   if (!KMP_AFFINITY_CAPABLE())
@@ -559,6 +562,9 @@
 #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())
@@ -592,6 +598,9 @@
 
 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41167.126717.patch
Type: text/x-patch
Size: 2171 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20171213/ce8b0751/attachment-0001.bin>


More information about the Openmp-commits mailing list