当前位置:网站首页>[High Performance Computing] openMP
[High Performance Computing] openMP
2022-07-30 04:47:00 【Coke Daniel】
学习来源
预备知识
parallel foris a combination of two instructions,This is generally used rather than simply usedfor指令
案例1
#include <iostream>
#include "omp.h"
int main()
{
int tid,mcpu;
tid=omp_get_thread_num(); //返回线程号
mcpu=omp_get_num_threads(); //Returns the number of threads in the current parallel region
printf("---before parallel---\n");
printf("thread %d in %d cpus\n",tid,mcpu);
printf("---during parallel---\n");
#pragma omp parallel num_threads(3) private(tid,mcpu) //开启三个线程 And specify the two variables Each thread has its own private copy
{
tid=omp_get_thread_num();
mcpu=omp_get_num_threads();
printf("thread %d in %d cpus\n",tid,mcpu);
}
printf("---after parallel---\n");
printf("thread %d in %d cpus\n",tid,mcpu);
return 0;
}
OpenMPUse in parallel construction
常用指令
除此之外,还有一些要求,如:
forThe instruction is followed by the body of the loop;
只能是for循环不能是while循环;
for循环中的iMust be an integer,And the increment cannot be changed;
单入口单出口;
The variables inside the loop are public,但是i是私有的;
Only if there is no data correlationforcycle to usefor指令并行优化;
Parallelism starts from the outermost where possible,可以节约资源
The above is an example of data correlation
如果不使用collapse 我们只能对iThis layer loops in parallel,内部的j、k是串行的,The loop length becomes M;使用collapse(2),can be achieved fori,ktwo layers merged,The loop length becomes MxP
Declaration of private variables
这个变量的默认值是0,Does not inherit the value of external variables of the same name
如果是for循环,The value of the child thread's private variable of the last iteration is passed,如果是section的话,同理.
规约
规约:Often do some kind of operation on a variable,The result is also stored in the current variable
注意:
After each child thread ends,The value of the original reduction variable is indeterminate,It will be determined after all threads are executed.
The order in which threads are executed is indeterminate
边栏推荐
- Discourse 自定义头部链接(Custom Header Links)
- gnss rtcm rtklib Ntrip...
- (Problem practice) Conditional probability + weight line segment tree + FWT + suffix array
- 【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
- 需求设计文档和产品经理的角色改变
- Image stitching (registration) case based on OpenCV
- 22. Why do you need a message queue?What are the advantages of using the message queue?
- DAY17, CSRF vulnerability
- nSoftware.PowerShell.Server.2020
- 文件系统二
猜你喜欢
山西省第二届网络安全技能大赛(企业组)部分赛题WP(七)
1315_Use the LOOPBACK simulation mode to test whether the pyserial installation is successful
Discourse 自定义头部链接(Custom Header Links)
Whole process scheduling - Azkaban entry and advanced
cnpm installation steps
解决报错SyntaxError: (unicode error) ‘utf-8‘ codec can‘t decode byte 0xb7 in position 0: invalid start b
A must see for software testers!Database knowledge MySQL query statement Daquan
Simple experiment with BGP
Repetition XXL - JOB scheduling center background arbitrary command execution
uni-app realizes cross-end development of mobile phone Bluetooth to receive and send data
随机推荐
cnpm installation steps
Weight line segment tree + line segment tree split/merge + CF1659D
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!
Repetition XXL - JOB scheduling center background arbitrary command execution
Chapter8 Support Vector Machines
mysql隔离级别
Some understanding of YOLOv7
五、视图解析与模板引擎
Stimulsoft ReportsJS and DashboardsJS. 2022.3.3
小程序使用npm包定制全局样式
SVN 查看用户名密码
error: The following untracked working tree files would be overwritten by
- B + tree index and MySQL series 】 【 what is the difference between a HASH index
【MySQL系列】-B+树索引和HASH索引有什么区别
双指针问题(中)
[MRCTF2020]Hello_misc
Six, read application configuration + log configuration
Alibaba Cloud's EasyNLP Chinese text image generation model takes you to become an artist in seconds
Image stitching (registration) case based on OpenCV
Unity3D Application simulation enters the front and background and pauses