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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With