Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenMP - Running parallel code inside parallel code

I have a function compute() that has parallelized matrix multiplication inside of it using OpenMP

#pragma omp parallel for

This function is called many times in a loop - which I would like to run in parallel. Will there be any issues in running parallel code inside other parallel code?

This is c++ compiled on Ubuntu.

like image 972
Mikhail Avatar asked Sep 07 '11 17:09

Mikhail


People also ask

Is nested parallelism possible in OpenMP?

OpenMP parallel regions can be nested inside each other. If nested parallelism is disabled, then the new team created by a thread encountering a parallel construct inside a parallel region consists only of the encountering thread. If nested parallelism is enabled, then the new team may consist of more than one thread.

How does OMP parallel work?

When run, an OpenMP program will use one thread (in the sequential sections), and several threads (in the parallel sections). There is one thread that runs from the beginning to the end, and it's called the master thread. The parallel sections of the program will cause additional threads to fork.


1 Answers

It will work fine, but you'll need to enable OpenMP nesting for it to work.

Call

omp_set_nested(1);

at the start of the program and it will allow you to have nested parallel regions.

However: Be aware, that you could end up running many more threads than what you want. So you will want to limit the # of threads of both the top and inner parallel regions.

like image 110
Mysticial Avatar answered Sep 23 '22 02:09

Mysticial