我怎樣才能正確地並行內環:嵌套並行OMP 2.0版性能
int found = -1;
#pragma omp parallel for ordered schedule(dynamic, 1) shared(found)
for (long i = 0; i < big_number; ++i)
{
if(function())
{
#pragma omp ordered
if(found == -1)
{
found = i;
}
}
}
bool function()
{
for(int i =0; i < another_big_number; i++)
{
if(some_condition)
{
return true;
}
}
}
我不能張貼整個代碼,但我一直在最這似乎部分對於這個問題是必要的。第一個循環的想法是找到函數返回true的最低迭代。
編輯:當然關於提高並行認識任何想法,但是,我的問題是更多關於我如何能提高功能的性能()本身沿着外使用嵌套方法循環。
請注意,我知道崩潰條款,但我不能使用它(感謝視覺工作室不支持後續版本的OpenMP)。
任何改進整個並行循環的想法都是值得讚賞的。 :)
您是否認爲通過並行化for循環內部函數()會提高性能?
的例子你嘗試FIRSTPRIVATE(發現)LASTPRIVATE(缶nd),以擺脫共享和omp命令(這可能不會避免比賽)? – tim18
函數()可能更好地用simd進行優化,但如果您必須堅持使用Microsoft編譯器,則需要SSE/AVX內在函數。 – tim18
[在C++中並行向量的查找\ _第一個]的可能重複(http://stackoverflow.com/questions/40285046/find-first-of-a-vector-in-parallel-in-c) – Zulan