如何将原子指令用于OpenMP中的部分
我使用OpenMP的截面指令并行化两个循环。
#pragma omp parallel sections
{
#pragma omp section //section 1
{
for (conditions){
statement
} }
#pragma omp section //section 2
{
#pragma omp for
for (conditions){
statement
} }
}
原因是两个循环彼此独立。第一个循环具有依赖性语句,因此不能并行化,其执行时间很大,而第二个循环可以并行化。但是,如果我仅在第二个循环中应用并行指令,则必须等待其执行,直到第一个循环完成。
因此,我试图使用截面或任务并行执行两个循环,在第一部分中,第一个循环可以顺序执行,在第二部分中,第二个循环可以并行化。
我不知道它是否会加快程序。但是在获得任何结果之前,我被困在如何依次在节中运行第一个循环。
i am parallelizing two loops using section directive of openMP.
#pragma omp parallel sections
{
#pragma omp section //section 1
{
for (conditions){
statement
} }
#pragma omp section //section 2
{
#pragma omp for
for (conditions){
statement
} }
}
The reason is both two loops are independent of each other. The first loop has dependent statements so it can not be parallelized and its execution time is large whereas the second loop can be parallelized. But if I apply parallel directives only on the second loop then it has to wait for its execution until the first one is completed.
So I am trying to execute both loops in parallel using a section or task where in the first section first loop can be executed sequentially and in the second section the second one can be parallelized.
I don't know whether it will speed up the program or not. But before getting any results, I was stuck on how to run the first loop in the section sequentially.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用任务来实现目标(同时运行2个循环:其中一个是按顺序运行的,另一个同时运行):
请注意,您的问题与原子操作无关。
You should use tasks to achieve your goal (to run 2 loops simultaneously: one of them sequentially and the other in parallel):
Note that your question has nothing to do with atomic operations.