【发布时间】:2011-11-01 04:50:26
【问题描述】:
我有两种工作要做,foobar1 要并行完成 3 次,foobar2 要并行完成 5 次。
我的想法是让主线程创建这两个工作组。但我面临一个困难。
是否可以让线程从并行循环中逃脱?我的意思是实现这样的代码,主任务可以 逃离第一组的工作创建第二组
#pragma omp parallel num_threads(8)
{
// first team of task which will execute the foobar1 function in parallel
#pragma omp for schedule(static,1) nowait
for(i = 0; i < 3; i++)
{
#pragma omp master
{
//escape here to create a second team in parallel
}
foobar1();
}
// second team of task which will execute the foobar2
#pragma omp for schedule(static,1) nowait
for(j = 0; j < 5; j++)
{
foobar2();
}
}
【问题讨论】:
-
您是否尝试拆分 8 个线程,以便 3 个运行第一个循环,5 个运行第二个循环?
-
@Mysticial,是的,这正是我想要的。
标签: c loops parallel-processing openmp