Nested Parallelism : Why only the main thread runs and executes the parallel for loop four times?
问题 My code: #include <cstdio> #include "omp.h" int main() { omp_set_num_threads(4); #pragma omp parallel { #pragma omp parallel for // Adding "parallel" is the cause of the problem, but I don't know how to explain it. for (int i = 0; i < 6; i++) { printf("i = %d, I am Thread %d\n", i, omp_get_thread_num()); } } return 0; } The output that I am getting: i = 0, I am Thread 0 i = 1, I am Thread 0 i = 2, I am Thread 0 i = 0, I am Thread 0 i = 1, I am Thread 0 i = 0, I am Thread 0 i = 1, I am Thread