[mvapich-discuss] How to achieve a “single global reduction” in a typical C++ code?

Daniel WEI lakeat at gmail.com
Wed Apr 16 17:57:44 EDT 2014


Dear List,

I have heard a lot about "single global reduction", but I still don't
understand how it is realized in a typical C++ code, could anyone shed me
some lights on how it is actually done?

Let's use the following code as an example, could anyone show me how it
could be modified, so to have only one reduce? Thanks

double s1, s2;
void sum( double& data ) {
  double s = 0.0;
  for ( j=jmin; j<=jmax; j++ ) {
    s += data[j];
  }
  MPI_Allreduce(&s,&s1,1,MPI_SUM,..) ;}
void sumsq( double& data ) {
  double s = 0.0;
  for ( j=jmin; j<=jmax; j++ ) {
    s += data[j] * data[j];
  }
  MPI_Allreduce(&s,&s2,1,MPI_SUM,..) ;}
for( i=0; i<N; i++ ) {
  sum(a[i]);
  sumsq(a[i]);
  var[i] = (s2 - s1*s1/N)/(N-1);}





Zhigang Wei
----------------------
*University of Notre Dame*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cse.ohio-state.edu/pipermail/mvapich-discuss/attachments/20140416/9018832a/attachment.html>


More information about the mvapich-discuss mailing list