← Back to team overview

yade-dev team mailing list archive

Parallel loops over interactions to sum

 

Hi,

I have one engine in which I am looping over interactions to compute incrementally something :

something = 0
for each interaction
    something += f(considered interaction)

In fact, I wrote this code using parallel loops, like that :

   Real something = 0;

  #ifdef YADE_OPENMP
  const long size=scene->interactions->size();
  #pragma omp parallel for schedule(guided) num_threads(ompThreads>0 ? min(ompThreads,omp_get_max_threads()) : omp_get_max_threads())
  for(long i=0; i<size; i++){
    const shared_ptr<Interaction>& interaction=(*scene->interactions)[i];
  #else
  FOREACH(const shared_ptr<Interaction>& interaction, *scene->interactions){
  #endif
      something += f(considered interaction);
   }

And I got (significantly) different results, for the final value of something, running this code either in parallel, or not... Surely linked with a poor understanding of what's really behind this openmp lines, I do not get if I do something wrong, or not (and, if yes, what ?). Is this kind of tasks achievable in parallel, or not ?

Thanks a lot,

Jerome

Follow ups