I would like to run the following code (below). I want to create two independent threads, each of which will start a parallel loop. Sorry, I am getting an error. Apparently, a parallel for
cannot be spawned inside a section
. How to solve this?
#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 }
And the error:
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 explicit task region [enabled by default] main.cpp:20:9: warning: work-sharing region may not be closely nested inside of work-sharing, critical, ordered, master or explicit task region [enabled by default]
source share