Parallelizaton for stdlist problem

  • Thread starter Thread starter xxh418
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 1K views
xxh418
Messages
9
Reaction score
0
Hi all,
I am trying to using OpenMP to parallelize a loop in C++.
The iterator for the loop is defined by std::list using C++ standard library containers.
The following is an example:


for (std::list<int>::iterator it=mylist.begin() ; it != mylist.end(); ++it)
std::count << ' ' << *it;

However, I found I can not use OpenMP command to do the parallelzation (#pragma). The simulation runs very slowly. For OpenMP, the first index in the for loop must be a integer for parallelzation. Does anyone encounter the same problem and have any idea how to solve it? Thank you very much!
 
Physics news on Phys.org
The basic idea of a "list" is that the entries are linked in sequence, by pointers.

All the "nice" C++ syntax like iterators, the ++ operator, etc isn't "magic". All it does is hide the details from you (which is useful, because you don't have to change the code if you replace the list by a diferent data structure).

The only way to parallelize access to the list entries would be to split it into several sub-lists.