Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel Iterators

I am designing a C++ data structure (for graphs) which is to be used by parallel code (using OpenMP).

Suppose I want to have a method which enables iteration over all elements (nodes). Of course, this iteration is going to be parallelized.

Is it possible to use an iterator for this purpose? How should an iterator look like that enables parallel access? Would you advise for or against using iterators in this case?

like image 626
clstaudt Avatar asked Nov 05 '12 13:11

clstaudt


1 Answers

OpenMP parallel loops don't play nicely with iterators. You'll want to implement an indexing mechanism (operator[] taking an integral argument) on your graph class.

If you do want to use OpenMP 3.0 iterator support, make sure you have a random access iterator. Implementing it as an pointer to a node or edge is the simplest choice.

like image 160
Fred Foo Avatar answered Sep 16 '22 18:09

Fred Foo