← Back to team overview

yade-dev team mailing list archive

Re: Parallel loops over interactions to sum

 

hi jerome,


I think you get indeterminism while summing something in parallel, have a look here:

https://yade-dem.org/doc/formulation.html?highlight=indeterminism#result-indeterminism

see what can happen running exactly the same simulation two times in parallel:

https://www.youtube.com/watch?v=ZAkfHMyG6MM


cheers,

christian


Zitat von Jerome Duriez <Jerome.Duriez@xxxxxxxxxxx>:

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






References