开发者

OpenMP - Running parallel code inside parallel code

开发者 https://www.devze.com 2023-04-03 13:19 出处:网络
I have a function compute() that has parallelized matrix multiplication inside of it using OpenMP #pragma omp parallel for

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 wou开发者_StackOverflow中文版ld like to run in parallel. Will there be any issues in running parallel code inside other parallel code?

This is c++ compiled on Ubuntu.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消