我有以下代码,我认为应该显示一个近似整个过程进度的进度条(因为循环的每个并行线程应该以大致相同的速率前进)
#pragma omp parallel for
for(long int x=0;x<elevations.size1();x++){
#pragma omp master
{
progress_bar(x*omp_get_num_threads()); //Todo: Should I check to see if ftell fails here?
}
........
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误:
warning: master region may not be closely nested inside of work-sharing or explicit task region [enabled by default]
Run Code Online (Sandbox Code Playgroud)
现在,当我运行代码时,我确实得到了所需的结果.但我不喜欢警告.为什么这会给我一个警告,是否有更好的方法来实现这一目标?
谢谢!
我想运行以下代码(如下).我想生成两个独立的线程,每个线程都会运行并行for循环.不幸的是,我收到了一个错误.显然,并行for不能在里面产生section.怎么解决?
#include <omp.h>
#include "stdio.h"
int main()
{
omp_set_num_threads(10);
#pragma omp parallel
#pragma omp sections
{
#pragma omp section
#pragma omp for
for(int i=0; i<5; i++) {
printf("x %d\n", i);
}
#pragma omp section
#pragma omp for
for(int i=0; i<5; i++) {
printf(". %d\n", i);
}
} // end parallel and end sections
}
Run Code Online (Sandbox Code Playgroud)
而错误:
main.cpp: In function ‘int main()’:
main.cpp:14:9: warning: work-sharing region may not be closely nested inside of work-sharing, critical, ordered, master or …Run Code Online (Sandbox Code Playgroud)