Openmp Linux 中的分段错误



我最近才学习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 %dn", my_rank, thread_count); 
} /* Hello */ 

您必须使用与线程数相对应的参数启动可执行文件:

g++ -fopenmp test.cpp -o myExec
./myExec 4

否则,您必须对thread_count变量进行硬编码,例如:

int thread_count = 4

那么你就不需要任何争论了。

最新更新