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!