I want to use openmp to parallelize my program. But on some devices it will trigger __kmp_abort_process. Openmp produced the following log .And it's quite hard to reproduce.
OMP: Error #100: Fatal system error detected.
OMP: System error #1: Operation not permitted.
I found from the openmp source code that a "fatal system error" will only occur when openmp init env and set thread affinity.
I extracted the part of the code that I was most suspicious of.Here is my simplified pseudocode. I init a static global variable with openmp and set thread affinity manually.
#include <omp.h>
int test(){
int num_threads= getFromCpuInfo();
std::vector<int> cpu_ids = getBigCoreCpu();
omp_set_dynamic(0);
// set affinity for each thread
omp_set_num_threads(num_threads);
#pragma omp parallel for
for (int i = 0; i < num_threads; i++) {
setSchedAffinity(cpu_ids); // this func call syscall(__NR_sched_setaffinity,...);
}
return num_threads;
}
static const int thread_num = test();
int main(){
printf("thread_num %d", thread_num );
}
Since this problem is not easy to reproduce, I am not sure if it has been fixed. Can anyone help me with this question?