Nested parallel for loop ... "Parallel outer for loop" in "parallel inner for loop as function"

I want to run a function that contains a for loop (assuming it runs in parallel) in a parallel outer loop. So it looks like this:

void myfunction(){
    ...
    #pragma omp parallel for
    for (int i=0;i<10;i++){
        do something...
    }
}


int main(){
    #pragma omp parallel for
    for(int i=0;i<5;i++){
        myfunction();
    }
}

Given the code above, I want to create 5 parallel threads for a loop in a function main(), and I want each of the 5 threads to create other K threads in order to start its own parallel loop.

Although I know how to run nested for loops if the inner loop is not in a separate function, I cannot find a solution for this kind of problem.

, 5- , , .

- ?

+4
1

parallelism:

void myfunction(){

    #pragma omp parallel for
    for (int i=0;i<10;i++){
        ...
    }
}


int main(){

    omp_set_nested(1);       // Enable nested parallelism    
    omp_set_num_threads(5); // Use 5 threads for all parallel regions

    #pragma omp parallel for
    for(int i=0;i<5;i++)
    {

        myfunction();
    }
}
+4

Source: https://habr.com/ru/post/1662759/


All Articles