I want to use openmp to accelerate the code like below.
The code is just to explain the operations, not real.
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();
The index is shared by all the threads.
Here are some thoughts from me:
- using omp parallel directive, ensure the threads run in order.
- using omp critical directive to operate iterator.
- using omp critical directive to find in index and insert into index.
but I really doubt the speedup since almost all the operation are in critical.
Is there some advice to speedup the code using openmp?
Thanks!