diff options
author | arcadia-devtools <[email protected]> | 2022-03-04 17:07:42 +0300 |
---|---|---|
committer | arcadia-devtools <[email protected]> | 2022-03-04 17:07:42 +0300 |
commit | b81e978bbba64cd6c17f8bc64f06fd940ba70e2b (patch) | |
tree | 963c0bd898cbfccac68543c3dffcbe07eeeeaf79 /contrib/libs/cxxsupp/openmp/kmp_affinity.cpp | |
parent | 0e68a9803d96e74d7905b6eb556bf142a6ba7c59 (diff) |
intermediate changes
ref:706109e1fa74d21f22e35e791a5b533dc95e59a4
Diffstat (limited to 'contrib/libs/cxxsupp/openmp/kmp_affinity.cpp')
-rw-r--r-- | contrib/libs/cxxsupp/openmp/kmp_affinity.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/contrib/libs/cxxsupp/openmp/kmp_affinity.cpp b/contrib/libs/cxxsupp/openmp/kmp_affinity.cpp index 4e6699ff214..0dc6f734718 100644 --- a/contrib/libs/cxxsupp/openmp/kmp_affinity.cpp +++ b/contrib/libs/cxxsupp/openmp/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 |