简体   繁体   English

OpenMP编译执行

[英]OpenMP compiling executing

I'm using linux and I don't know which is the command line to compile an OpenMP file, can I simply write: 我正在使用linux,但我不知道编译OpenMP文件的命令行是什么,我可以简单地写一下:

g++ myprog.cpp -o myprog

or g++ compiler doesn't work? 还是g++编译器不起作用?

And how I execute myprog ? 以及我如何执行myprog Where I choose the number of threads? 我在哪里选择线程数?

You want to compile with -fopenmp and before you run the executable, set the OMP_NUM_THREADS variable to set the number of threads, for example with export in bash. 您要使用-fopenmp进行编译,并且在运行可执行文件之前,请设置OMP_NUM_THREADS变量以设置线程数,例如使用bash中的export An example from here : 来自这里的一个例子:

$ gcc -o omp_helloc -fopenmp omp_hello.c
$ export OMP_NUM_THREADS=2
$ ./omp_helloc
Hello World from thread = 0
Hello World from thread = 1
Number of threads = 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM