0

I'm having problems parallelising the calling of a member function in a for loop. I only want to parallelise the iteration of objects, not the iteration of vectors within the called function.

This is how i call the parallel section, where particle_vector is a vector of objects and build_state_pylist() is a member function. state_vec and state_pylist are both object members.

#pragma omp parallel for
for (int i=0; i < n_sims; ++i) {
    particle_vector[i].build_state_pylist();
}

build_state_pylist() iterates through values of state_vec, which is a std::vector of vectors. The contained values and appending them to state_pylist, a boost::python::list, which is a member of the object.

void Particle::build_state_pylist() {
for (auto sim_iter = state_vec.begin(); sim_iter != state_vec.end(); ++sim_iter) {
    auto sim_vec = *sim_iter;
    for (auto vec_iter= sim_vec.begin(); vec_iter!= sim_vec.end(); ++vec_iter) {
        this->state_pylist.append(*vec_iter);
    }
}

}

Since the each loop iteration is only accessing memory contained within each object I didn't think parallelising this section would be a problem. But I get this error:

double free or corruption (!prev)

and

(core dumped)

The loop works without parallelisation. Any help would be greatly appreciated!

Behzad
  • 123
  • 1
  • 1
  • 11
  • 2
    This cannot be answered without seeing more code, the problem is likely somewhere deep inside. Are you 100% sure that there is no shared resource accessed by multiple threads within `Particle::build_state_pylist()`? – Daniel Langr Nov 08 '18 at 11:46
  • 1
    Also, couldn't this issue be related to your problem: [boost.python not supporting parallelism?](https://stackoverflow.com/questions/8009613/boost-python-not-supporting-parallelism) See also the documentation: https://wiki.python.org/moin/boost.python/HowTo#Multithreading_Support_for_my_function – Daniel Langr Nov 08 '18 at 11:51
  • Within `Particle::build_state_pylist()`, the resources being accessed are `state_vec` and `state_pylist`. Both of which are object members, so I'm not sure why they would be shared across threads. edit: I'll look into the boost parallel support! – Behzad Nov 08 '18 at 11:55
  • It's difficult to answer your question without having a minimal example to reproduce the issue. If you didn't already, you could try tools like [Clang's Thread Sanitizer](https://clang.llvm.org/docs/ThreadSanitizer.html) to have more information on the eventual data race. – Massimiliano Nov 14 '18 at 19:51

0 Answers0