y****e 发帖数: 23939 | 1 I want to start 3 threads, but I always get only one.
#include
#include
int main(int argc, char *argv[]){
printf("Hello from master thread.\n");
int num = 3;
omp_set_num_threads(num);
#pragma omp parallel num_threads(3)
{
printf("Team member %d reporting from team of %d\n",
omp_get_thread_num(),omp_get_num_threads() );
printf("Max number of threads for this system is: %d\n",
omp_get_max_threads() );
printf("Number of process |
y****e 发帖数: 23939 | |
O*******d 发帖数: 20343 | 3 You have to activate OpenMP in your compiler. For Visual Studio 2008,
Project->"your project"->C/C++->Language->OpenMP Support
【在 y****e 的大作中提到】 : I want to start 3 threads, but I always get only one. : #include : #include : int main(int argc, char *argv[]){ : printf("Hello from master thread.\n"); : int num = 3; : omp_set_num_threads(num); : #pragma omp parallel num_threads(3) : { :
|
O*******d 发帖数: 20343 | 4 The default number of threads in OpenMP is the number of CPU on your
computer if you do not call omp_set_num_threads(). Of course you have to
activate OpenMP support of your compiler. |
y****e 发帖数: 23939 | 5 谢谢你的回复。不过我还是有点不明白,我现在是在Linux里面用g++ compile的。
compile没有问
题,不知道你说的activate OpenMP是什么意思?
我的系统是intel dual core的,应该算两个processor吧。
而且我确实call了omp_set_num_threads()了呀。
但只起来了一个thread。
to
【在 O*******d 的大作中提到】 : The default number of threads in OpenMP is the number of CPU on your : computer if you do not call omp_set_num_threads(). Of course you have to : activate OpenMP support of your compiler.
|
O*******d 发帖数: 20343 | 6 比较新的compiler一般都支持OpenMP。 但是可能需要激活,至少Visual Studio 2008
是这样的。 激活就是把compiler
支持OpenMP的功能调用起来。 如果不激活,不管你有几个CPU,就只有一个thread。你
call omp_set_num_threads()
在没有激活的compiler下是无效的,但也不会给错。 这是为了backward
compatibility.
【在 y****e 的大作中提到】 : 谢谢你的回复。不过我还是有点不明白,我现在是在Linux里面用g++ compile的。 : compile没有问 : 题,不知道你说的activate OpenMP是什么意思? : 我的系统是intel dual core的,应该算两个processor吧。 : 而且我确实call了omp_set_num_threads()了呀。 : 但只起来了一个thread。 : : to
|
z*****a 发帖数: 3809 | 7 Did you use -fopenmp command line option?
【在 y****e 的大作中提到】 : 谢谢你的回复。不过我还是有点不明白,我现在是在Linux里面用g++ compile的。 : compile没有问 : 题,不知道你说的activate OpenMP是什么意思? : 我的系统是intel dual core的,应该算两个processor吧。 : 而且我确实call了omp_set_num_threads()了呀。 : 但只起来了一个thread。 : : to
|
y****e 发帖数: 23939 | 8 Thanks a lot for both of you. You are right, I need -fopenmp for both
compiling and linking. |
p******m 发帖数: 353 | 9 我尝试用intel 9 编译器在vc 6.0的环境里编译openmp, 但其中一个线程老是被重复
执行, 不知道为什么? 有谁遇到过类似的问题吗?
【在 y****e 的大作中提到】 : I want to start 3 threads, but I always get only one. : #include : #include : int main(int argc, char *argv[]){ : printf("Hello from master thread.\n"); : int num = 3; : omp_set_num_threads(num); : #pragma omp parallel num_threads(3) : { :
|
O*******d 发帖数: 20343 | 10 需要看你的码才能知道。
【在 p******m 的大作中提到】 : 我尝试用intel 9 编译器在vc 6.0的环境里编译openmp, 但其中一个线程老是被重复 : 执行, 不知道为什么? 有谁遇到过类似的问题吗?
|
p******m 发帖数: 353 | 11 int main(){
int i;
omp_set_num_threads(2);
#pragma omp parallel for
for(i = 0; i < 6; i++ )
printf("i = %d\n", i);
return 0;
} |
p******m 发帖数: 353 | 12 i = 0 或者 i=1会出现两次, 不知道为什么。 |
m**s 发帖数: 346 | 13 Just curious that if you didnt include -fopenmp option, didnt you get
Warning like "skipped #pragma ..."
you didn't use -Wall either??
【在 y****e 的大作中提到】 : Thanks a lot for both of you. You are right, I need -fopenmp for both : compiling and linking.
|