[英]Parallelize two for loops through c++ list/iterator using OpenMP
I would like to parallelize the following structure using OpenMP: 我想使用OpenMP并行化以下结构:
for (auto it = data.begin(); it != data.end(); ++it)
{
for (vector<my_element>::iterator it2 = it->begin(); it2 != it->end(); ++it2)
{
// code here (it2->process)
}
}
I have tried different approaches but I could not make it work properly. 我尝试了不同的方法,但无法使其正常工作。 Could you help me?.
你可以帮帮我吗?。
I am using gcc 5.3.0, OpenMP 4.0. 我正在使用gcc 5.3.0,OpenMP 4.0。 The solutions I've tried so far with no success are:
到目前为止,我尝试过但没有成功的解决方案是:
Solution 1: 解决方案1:
#pragma omp parallel
#pragma omp single
{
for (auto it = data.begin(); it != data.end(); ++it)
{
#pragma omp task firstprivate(it)
for (vector<my_element>::iterator it2 = it->begin(); it2 != it->end(); ++it2)
{
// code here (it2->process)
}
#pragma omp taskwait
}
}
Solution 2: 解决方案2:
#pragma omp parallel
{
for (auto it = data.begin(); it != data.end(); ++it)
{
#pragma omp single nowait
{
for (vector<my_element>::iterator it2 = it->begin(); it2 != it->end(); ++it2)
{
// code here (it2->process)
}
}
}
}
I think you should not call omp taskwait
. 我认为您不应致电
omp taskwait
。
#pragma omp parallel
{
#pragma omp single
{
for (auto it = data.begin(); it != data.end(); ++it)
{
#pragma omp task firstprivate(it)
for (vector<my_element>::iterator it2 = it->begin(); it2 != it->end(); ++it2)
{
// code here (it2->process)
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.