博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OpenMP
阅读量:4573 次
发布时间:2019-06-08

本文共 1225 字,大约阅读时间需要 4 分钟。

OpenMP中一个变量可以有三种类型,即shared、private和reduction,默认为shared,除非如下三种特别情况:

一、在并行for循环中紧临parallel for 语句的循环变量是私有的;

二、并行区域代码块里的声明的变量是私有的;

三、所有通过private,firstprivate,lastprivate和reduction子句声明的变量为私有变量。

 

#include 
#include
#include
#include
#include
#include
using namespace std;int main(int argc, char *argv[]){ ifstream ifs(argv[1]); string name; map
brands; while (!ifs.eof()) { getline(ifs, name); map
::const_iterator it = brands.find(name); if (it == brands.end()) { brands[name] = 1; } else { brands[name] = it->second + 1; } } vector
names; map
::const_iterator it; for (it = brands.begin(); it != brands.end(); ++it) { names.push_back(it->first); } vector
counts(names.size());#pragma omp parallel{ int i; #pragma omp for for (i = 0; i < names.size(); ++i) { int count = 0; map
::const_iterator it2; for (it2 = brands.begin(); it2 != brands.end(); ++it2) { string name = it2->first; if (name.find(names[i]) != string::npos) { count += it2->second; } } counts[i] = count; }} for (int i = 0; i < names.size(); ++i) { cout << names[i] << "\t" << counts[i] << endl; } return 0;}

 

转载于:https://www.cnblogs.com/agnostic/p/3795107.html

你可能感兴趣的文章
Centos 文件权限修改
查看>>
Linux下NFS服务器的搭建与配置
查看>>
1501 二叉树最大宽度和高度
查看>>
MySQL索引选择问题(要相信MySQL自己选择索引的能力)
查看>>
Angular i18n
查看>>
SQL Server 2008 教程
查看>>
docker安装
查看>>
JAVA boolean 类型
查看>>
MYSQL进阶学习笔记七:MySQL触发器的创建,应用及管理!(视频序号:进阶_16,17)...
查看>>
hdu 4069 福州赛区网络赛I DLC ***
查看>>
java web 方面
查看>>
Spring 源码学习(2) —— FactoryBean 的使用
查看>>
wiki 3143 二叉树的前序、中序及后序遍历
查看>>
一位创业者创业失败后,成功的做了一个创业孵化器!
查看>>
导出文本pdf文件
查看>>
C. Table Decorations(Codeforces Round 273)
查看>>
LayoutInflater和inflate()方法的使用方法
查看>>
Luogu P4306 JSOI2010 连通数
查看>>
爬取音悦台MV信息(requests,BeautifulSoup,xlwt)----待完善
查看>>
asp.net gridview 控件如何根据一列内容显示另一列的内容
查看>>