由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - A helloworld OpenMP question?
相关主题
[合集] Intel 9编译器在vc 6.0的环境里编译openmp的问题求助 怎么编辑 多个 .c files(比如a.c, b.c) 和一个.h file(ab (转载)
我写的C++ ParallelForLoop,感兴趣的来下载测试segfault
c++ thread 求助请大牛们帮忙看一段并行c++代码的效率问题
一个读用户输入的小问题Use Visual .NET for C++ programming
C的argc问题三个C syntax 弱问题
tree data conversion谁来解释一下这个是compiler问题吗?
请教一道题 (转载)这个C++程序为什么不能运行
问个简单的c程序a question on C++ string
相关话题的讨论汇总
话题: omp话题: threads话题: openmp话题: num话题: printf
进入Programming版参与讨论
1 (共1页)
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
2
这里没有人用过OpenMP的?
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.

1 (共1页)
进入Programming版参与讨论
相关主题
a question on C++ stringC的argc问题
A aimple C++ questiontree data conversion
请问C++中局部未使用的变量在优化的时候会去掉么?请教一道题 (转载)
C++ 初级再初级问题问个简单的c程序
[合集] Intel 9编译器在vc 6.0的环境里编译openmp的问题求助 怎么编辑 多个 .c files(比如a.c, b.c) 和一个.h file(ab (转载)
我写的C++ ParallelForLoop,感兴趣的来下载测试segfault
c++ thread 求助请大牛们帮忙看一段并行c++代码的效率问题
一个读用户输入的小问题Use Visual .NET for C++ programming
相关话题的讨论汇总
话题: omp话题: threads话题: openmp话题: num话题: printf