openMP线程问题 [英] openMP threading problem

查看:203
本文介绍了openMP线程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试学习openMP时,我遇到了这段代码示例

as I was trying to learn openMP , I came across this sample of code

#include < stdio.h>
#include < omp.h> // Include OpenMP
int main(int argc, char **argv)
{
#pragma omp parallel num_threads(10)
		{
			int threadNum;
			threadNum = omp_get_thread_num();
			printf("This is thread %d\n", threadNum);
		}
	return 0;
}



作者说它可以正常打印0到9的ID.
但是当我尝试它时,它只会显示id0.即,只有一个线程正在运行.
知道我的操作系统是win7,处理器是Intel icore7



the author said that it worked correctly print ids from 0-9.
but when I try it ,it only print id 0. i.e, only one thread is running .
knowing that my OS is win7 and processor is Intel icore7

推荐答案

此示例也在wiki上使用障碍. stdout不一定是线程安全的.再看一下Wiki上的内容:
http://en.wikipedia.org/wiki/OpenMP [
This example is also on the wiki where they use barriers. stdout doesn''t have to be thread safe. Have another look at the wiki on this:
http://en.wikipedia.org/wiki/OpenMP[^]

Good luck!


这篇关于openMP线程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆