我最近刚刚学习openMp,当我在Linux上编译并运行以下程序时,我遇到了“SEGMENT FAULT”。有人可以帮助我解决它吗?
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void Hello(void); /* Thread function */
int main(int argc, char* argv[]) {
/* Get number of threads from command line */
int thread_count = strtol(argv[1], NULL, 10);
# pragma omp parallel num_threads(thread_count)
Hello();
return 0; } /* main */
void Hello(void) {
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
printf("Hello World from thread %d of %d\n", my_rank, thread_count);
} /* Hello */
最佳答案
您必须使用与线程数相对应的参数来启动可执行文件:
g++ -fopenmp test.cpp -o myExec
./myExec 4
否则,您必须对 thread_count 变量进行硬编码,例如:
int thread_count = 4
那么你就不需要任何争论了。
关于c++ - openmp Linux 中的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50616151/