Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的openmp代码无法在服务器上工作? 我有一个简单的OpenMP C++代码,看起来像: #include <cmath> #include <iostream> #include <stdio.h> #include <string> int main() { #pragma omp parallel for for(int n=0; n<10; ++n) { printf(" %d", n); } printf(".\n"); }_C++_Gcc_Openmp - Fatal编程技术网

我的openmp代码无法在服务器上工作? 我有一个简单的OpenMP C++代码,看起来像: #include <cmath> #include <iostream> #include <stdio.h> #include <string> int main() { #pragma omp parallel for for(int n=0; n<10; ++n) { printf(" %d", n); } printf(".\n"); }

我的openmp代码无法在服务器上工作? 我有一个简单的OpenMP C++代码,看起来像: #include <cmath> #include <iostream> #include <stdio.h> #include <string> int main() { #pragma omp parallel for for(int n=0; n<10; ++n) { printf(" %d", n); } printf(".\n"); },c++,gcc,openmp,C++,Gcc,Openmp,但是,当我在我们的计算机服务器(基于linux)上执行相同操作时,我无法再现并行化: [me@my_cluster trial_openmp]$ g++ tmp2.cpp -fopenmp [me@my_cluster trial_openmp]$ qrsh -pe orte_pe 8 [me@compute-0-5 trial_openmp]$ ./a.out 0 1 2 3 4 5 6 7 8 9. 代码没有并行化,如果我检查g++版本,我认为openmp安装正确: [me@my_cl

但是,当我在我们的计算机服务器(基于linux)上执行相同操作时,我无法再现并行化:

[me@my_cluster trial_openmp]$ g++ tmp2.cpp -fopenmp
[me@my_cluster trial_openmp]$ qrsh -pe orte_pe 8
[me@compute-0-5 trial_openmp]$ ./a.out 
 0 1 2 3 4 5 6 7 8 9.
代码没有并行化,如果我检查g++版本,我认为openmp安装正确:

[me@my_cluster trial_openmp]$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/share/apps/gcc-4.8.0/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/share/apps/gcc-4.8.0 --with-gmp=/share/apps/gmp-5.1.1 --with-mpfr=/share/apps/mpfr-3.1.2 --with-mpc=/share/apps/mpc-1.0.1
Thread model: posix
gcc version 4.8.0 (GCC) 

有人知道发生了什么吗?谢谢。

我们在评论中得出的答案是,如果未定义的每个CPU只使用1个线程,那么wasabi123需要设置OMP_NUM_THREADS环境变量

导出OMP\u NUM\u THREADS=X


其中x是所需的线程数。

尝试让每个线程打印自己的线程ID,以确保没有多个线程。这是更常用的测试-例如,您可能有多个线程,而它们恰好以正确的顺序打印。。。在使用export-OMP_-NUM_-threads=x运行可执行文件之前,请尝试导出所需的线程数,其中x可能为8。我非常确定,它们无意中没有按正确的顺序打印……是的,这不太可能,但可能。我的观点很简单,它值得使用这种方法作为测试程序,而不是简单地打印数字。你试过环境变量了吗?哦,是的,设置环境变量确实解决了这个问题。非常感谢你。
[me@my_cluster trial_openmp]$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/share/apps/gcc-4.8.0/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/share/apps/gcc-4.8.0 --with-gmp=/share/apps/gmp-5.1.1 --with-mpfr=/share/apps/mpfr-3.1.2 --with-mpc=/share/apps/mpc-1.0.1
Thread model: posix
gcc version 4.8.0 (GCC)