Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Parallelizaton for stdlist problem

  1. Mar 14, 2013 #1
    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::cout << ' ' << *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!
  2. jcsd
  3. Mar 14, 2013 #2


    User Avatar
    2017 Award

    Staff: Mentor

    You want to parallelize "cout"s? I don't see how this is supposed to work.
  4. Mar 14, 2013 #3


    User Avatar
    Science Advisor
    Homework Helper

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook