OpenMP编程->同步机制
2014-04-13 18:20
387 查看
/* nowait用来取消栅障 */
void test12()
{
#pragma omp parallel
{
#pragma omp for nowait
for (int i = 0; i < 100; ++i)
{
std::cout << i << "+" << std::endl;
}
#pragma omp for
for (int j = 0; j < 100; ++j)
{
std::cout << j << "-" << std::endl;
}
}
}
/* 声明对应的并行程序块只由主线程完成 */
void test14()
{
#pragma omp parallel
{
#pragma omp master
{
for (int j = 0; j < 10; ++j)
{
std::cout << j << "-" << std::endl;
}
}
std::cout << "This will printed twice." << std::endl;
}
}
void test12()
{
#pragma omp parallel
{
#pragma omp for nowait
for (int i = 0; i < 100; ++i)
{
std::cout << i << "+" << std::endl;
}
#pragma omp for
for (int j = 0; j < 100; ++j)
{
std::cout << j << "-" << std::endl;
}
}
}
/* 显式同步栅障 在barrier处进行了同步,然后执行后边的for循环。 */ void test13() { #pragma omp parallel { for (int i = 0; i < 100; ++i) { cout<<"ID "<<omp_get_thread_num()<<" "; std::cout << i << "+" << std::endl; } #pragma omp barrier for (int j = 0; j < 100; ++j) { cout<<"ID "<<omp_get_thread_num()<<" "; std::cout << j << "-" << std::endl; } } }
/* 声明对应的并行程序块只由主线程完成 */
void test14()
{
#pragma omp parallel
{
#pragma omp master
{
for (int j = 0; j < 10; ++j)
{
std::cout << j << "-" << std::endl;
}
}
std::cout << "This will printed twice." << std::endl;
}
}
/* section用来指定不同的线程执行不同的部分 */ void test15() { #pragma omp parallel sections //声明该并行区域分为若干个section,section之间的运行顺序为并行的关系 { #pragma omp section //第一个section,由某个线程单独完成 for (int i = 0; i < 5; ++i) { std::cout <<"i "<< i << "+" << std::endl; cout<<"ID "<<omp_get_thread_num()<<" "; } #pragma omp section //第一个section,由某个线程单独完成 for (int j = 0; j < 5; ++j) { std::cout<<"j " << j << "-" << std::endl; cout<<"ID "<<omp_get_thread_num()<<" "; } } }
相关文章推荐
- OpenMP编程->同步机制
- 利用纯java捕获和播放音频
- [Python]Build-in方法all和any
- Java基础1
- 编程之美2014资格赛 大神与三个小伙伴 小数据
- 【DOM编程艺术】图片库改进版
- OpenMP编程->互斥锁函数
- [置顶] OpenMP编程->互斥锁函数
- java运行时内存分配详解
- ubuntu12.04.4下MySQLdb-python的使用
- 许令波老师的java的IO机制分析文章
- C++细节知识(1)
- [翻译]创建ASP.NET WebApi RESTful 服务(8)
- phpMyAdmin安装配置方法全过程,及问题解决
- Java面向对象之类和对象
- C#操作Active Directory(AD)详解
- GitHub详细教程
- Spring transaction事宜 roll back各种回滚
- VIM 编译C、C++、Fortran脚本
- struts2的动手搭建