[Openmp-commits] [PATCH] D15867: New API for setting initial mask for calling thread.

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Mon Jan 4 12:48:40 PST 2016


jlpeyton created this revision.
jlpeyton added reviewers: tlwilmar, hfinkel.
jlpeyton added a subscriber: openmp-commits.
jlpeyton set the repository for this revision to rL LLVM.

This new API, `int kmp_set_thread_affinity_mask_initial()`, is available to be used by another parallel runtime library inside a possibly OpenMP-registered thread to get the initial hardware resources available (cpu affinity) to the application when it first began.  This function sets the current thread's affinity to the initial affinity mask the root OpenMP master thread encountered when affinity initialization took place inside OpenMP.  If `-1` is returned it can be assumed that either the thread hasn't called affinity initialization or that the thread isn't registered with the OpenMP library.



Repository:
  rL LLVM

http://reviews.llvm.org/D15867

Files:
  runtime/src/kmp_affinity.cpp

Index: runtime/src/kmp_affinity.cpp
===================================================================
--- runtime/src/kmp_affinity.cpp
+++ runtime/src/kmp_affinity.cpp
@@ -4732,4 +4732,35 @@
     }
 }
 
+#if KMP_OS_LINUX
+// We don't need this entry for Windows because
+// there is GetProcessAffinityMask() api
+#ifdef __cplusplus
+extern "C"
+#endif
+int
+kmp_set_thread_affinity_mask_initial()
+// the function returns 0 on success,
+//   -1 if we cannot bind thread
+//   >0 (errno) if an error happened during binding
+{
+    int gtid = __kmp_get_gtid();
+    if (gtid < 0) {
+        // Do not touch non-omp threads
+        KA_TRACE(30, ( "kmp_set_thread_affinity_mask_initial: "
+            "non-omp thread, returning\n"));
+        return -1;
+    }
+    if (!KMP_AFFINITY_CAPABLE() || !__kmp_init_middle) {
+        KA_TRACE(30, ( "kmp_set_thread_affinity_mask_initial: "
+            "affinity not initialized, returning\n"));
+        return -1;
+    }
+    KA_TRACE(30, ( "kmp_set_thread_affinity_mask_initial: "
+        "set full mask for thread %d\n", gtid));
+    KMP_DEBUG_ASSERT(fullMask != NULL);
+    return __kmp_set_system_affinity(fullMask, FALSE);
+}
+#endif
+
 #endif // KMP_AFFINITY_SUPPORTED


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15867.43915.patch
Type: text/x-patch
Size: 1223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20160104/e1c28a66/attachment.bin>


More information about the Openmp-commits mailing list