我想使用openmp來加速下面的代碼。如何在while循環中使用openmp while
該代碼只是爲了解釋操作,而不是真實的。
Iterator iterator(records);
while(iterator.next())
{
int current_id = iterator.current_row_index();
bool result = index.find(records[current_id])
if (result == false)
if (index.insert(records[current_id]) == false)
break;
}
return iterator.current_row_index();
索引由所有線程共享。
這裏有一些想法從我:
- 使用OMP並行指令,確保線程才能運行。
- 使用omp關鍵指令來操作迭代器。
- 使用omp critical指令在索引中查找並插入索引。
但我真的懷疑加速,因爲幾乎所有的操作都很危險。
有沒有一些建議,以加快使用openmp的代碼?
謝謝!
是迭代器只是一個前向迭代器?它可以用作隨機訪問迭代器嗎? – Anton 2014-09-12 10:59:35
@Anton它現在只是一個前向迭代器,但我可以修改它以支持後向。但它不能隨機訪問。我不想修改迭代器代碼。 – b8flowerfire 2014-09-12 11:09:31
你想在串行while循環找到的第一個索引或任何索引處停下來嗎? – Walter 2014-09-12 14:05:50