nowait
nowait
是OpenMP中用于指示编译器在并行执行完指定代码块后不需要隐式等待的指令。通常情况下,当并行区域的代码执行完毕后,OpenMP 会隐式地等待所有线程都执行完毕,然后再继续执行下面的代码。但是,如果在并行区域的结尾使用了nowait
指令,则编译器会立即执行下面的代码,而不等待所有线程都完成。它通常与并行构造(如parallel for
、sections
等)一起使用
#include <iostream>
#include <omp.h>
using namespace std;
int main(int argc, char* argv[]){
#pragma omp parallel
{
int id = omp_get_thread_num();
#pragma omp for nowait
for (int i = 0; i < 5; ++i) {
cout << "thread " << id << " -> " << i << endl;
}
cout << "nowait - > " << id << endl;
}
return 0;
}
nowait
thread thread 02 -> -> 03thread
thread 0 -> 1
1 -> 2
nowait - > 1
nowait - > 0
thread 3 -> 4
nowait - > 3
nowait - > 2
non nowait
thread thread thread 1 -> 220 -> -> 30
thread 0 -> 1
thread 3 -> 4
nowait - > nowait - > 02
nowait - > 1
nowait - > 3
地方
标签:nowait,thread,int,并行,reduction,omp,OpenMP From: https://www.cnblogs.com/tao-gak567/p/18068572