diff options
author | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2016-01-12 17:21:55 +0000 |
---|---|---|
committer | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2016-01-12 17:21:55 +0000 |
commit | 4f88c8887039a33300c68bac906a85ef0c665490 (patch) | |
tree | b0f198dd46cd86b2804c5c435f3937d429b5cf7a /runtime/src/kmp_affinity.cpp | |
parent | 3d9851ae3cc8a5ba3d08e1b404a7a4bab09876c0 (diff) |
New API for restoring current thread's affinity to init affinity of application
This new API, int kmp_set_thread_affinity_mask_initial(), is available for use
by other parallel runtime libraries inside a possibly OpenMP-registered thread.
This entry point restores the current thread's affinity mask to the affinity
mask of the application when it first began. 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. If 0 is returned then, then the call
was successful. Any return value greater than zero indicates an error occurred
when setting affinity.
Differential Revision: http://reviews.llvm.org/D15867
git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@257489 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime/src/kmp_affinity.cpp')
-rw-r--r-- | runtime/src/kmp_affinity.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/runtime/src/kmp_affinity.cpp b/runtime/src/kmp_affinity.cpp index 4e6699f..0dc6f73 100644 --- a/runtime/src/kmp_affinity.cpp +++ b/runtime/src/kmp_affinity.cpp @@ -4732,4 +4732,42 @@ void __kmp_balanced_affinity( int tid, int nthreads ) } } +#if KMP_OS_LINUX +// We don't need this entry for Windows because +// there is GetProcessAffinityMask() api +// +// The intended usage is indicated by these steps: +// 1) The user gets the current affinity mask +// 2) Then sets the affinity by calling this function +// 3) Error check the return value +// 4) Use non-OpenMP parallelization +// 5) Reset the affinity to what was stored in step 1) +#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 |