【转载】设置openmp线程个数
2014-03-05 14:23
176 查看
两种方法
一。首先在函数中设置
#include"omp.h"
#include<iostream>
#include<stdio.h>
#include<time.h>
using namespace std;
int main()
{
clock_t start=clock();
#pragma omp parallel num_threads(8)
{
printf("Hello! time=%ld threadID=%d\n",clock()-start, omp_get_thread_num());
}
printf("last time=%ld",clock()-start);
system("pause");
return 0;
}
输出结果:
Hello! time=15 threadID=0
Hello! time=15 threadID=1
Hello! time=15 threadID=3
Hello! time=15 threadID=5
Hello! time=15 threadID=7
Hello! time=15 threadID=2
Hello! time=15 threadID=4
Hello! time=15 threadID=6
last time=15请按任意键继续. . .
二。在环境变量中设置
程序如下
#include"omp.h"
#include<iostream>
#include<stdio.h>
#include<time.h>
using namespace std;
int main()
{
clock_t start=clock();
#pragma omp parallel
{
printf("Hello! time=%ld threadID=%d\n",clock()-start, omp_get_thread_num());
}
printf("last time=%ld",clock()-start);
system("pause");
return 0;
}
输出如下:
Hello! time=15 threadID=0
Hello! time=15 threadID=2
Hello! time=15 threadID=1
Hello! time=15 threadID=3
last time=15请按任意键继续. . .
一。首先在函数中设置
#include"omp.h"
#include<iostream>
#include<stdio.h>
#include<time.h>
using namespace std;
int main()
{
clock_t start=clock();
#pragma omp parallel num_threads(8)
{
printf("Hello! time=%ld threadID=%d\n",clock()-start, omp_get_thread_num());
}
printf("last time=%ld",clock()-start);
system("pause");
return 0;
}
输出结果:
Hello! time=15 threadID=0
Hello! time=15 threadID=1
Hello! time=15 threadID=3
Hello! time=15 threadID=5
Hello! time=15 threadID=7
Hello! time=15 threadID=2
Hello! time=15 threadID=4
Hello! time=15 threadID=6
last time=15请按任意键继续. . .
二。在环境变量中设置
程序如下
#include"omp.h"
#include<iostream>
#include<stdio.h>
#include<time.h>
using namespace std;
int main()
{
clock_t start=clock();
#pragma omp parallel
{
printf("Hello! time=%ld threadID=%d\n",clock()-start, omp_get_thread_num());
}
printf("last time=%ld",clock()-start);
system("pause");
return 0;
}
输出如下:
Hello! time=15 threadID=0
Hello! time=15 threadID=2
Hello! time=15 threadID=1
Hello! time=15 threadID=3
last time=15请按任意键继续. . .
相关文章推荐
- 如何在linux/unix中设置线程的优先级
- [转载]线程中断技术
- Silverlight小技巧--路径的设置及资源文件(转载)
- 如何启动、关闭和设置ubuntu防火墙 (转载)
- 【转载】Java并发编程1:进程和线程之由来
- [转载]进程与线程的区别
- vs如何向main函数传参数、设置字符编码、设置OpenMp等
- MySQL远程连接设置(转载)
- Session设置不当导致API变成单线程问题的解决
- 静态路由设置初涉_不同网段指静态路由可以互访 (转载)
- Latex下字体设置-转载
- win2003系统下apache、php、mysql安装以及虚拟主机和目录权限设置(转载)
- [转载]怎样设置用不同的用户名和密码访问网上邻居的其他电脑?
- C#多线程学习(二) 如何操纵一个线程 (转载系列)——继续搜索引擎研究
- java多线程设置 线程超时 非阻塞实现
- android 自定义Dialog背景透明及显示位置设置(转载)
- 【C#】.NET中设置代理服务器浏览网页的实现--转载
- java 线程的优先级的设置的测试
- OpenMP创建线程中的锁及原子操作性能比较
- Notepad++的字体设置加Consolas和微软雅黑混合字体<转载>