最简单的OPENMP并行例子

[复制链接]
查看11 | 回复0 | 2012-5-21 10:19:41 | 显示全部楼层 |阅读模式
#include "stdafx.h"
#include
#include
int _tmain(int argc, _TCHAR* argv[])
{
#pragma omp parallel num_threads(4)
{
int i = omp_get_thread_num();
printf_s("Hello from thread %d\n", i);
}

return 0;
}
// omp_parallel.cpp
// compile with: /openmp
执行结果,3次各不相同
Hello from thread 0
Hello from thread 1
Hello from thread 2
Hello from thread 3
D:\Documents and Set
Hello from thread 2
Hello from thread 0
Hello from thread 1
Hello from thread 3
D:\Documents and Set
Hello from thread 0
Hello from thread 3
Hello from thread 1
Hello from thread 2
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行