HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
MPISum.c File Reference

Functions to compute the sum across MPI ranks. More...

#include <mpi.h>

Go to the source code of this file.

Functions

int MPISum_integer (int *global, int *var, int size, void *comm)
 
int MPISum_double (double *global, double *var, int size, void *comm)
 

Detailed Description

Functions to compute the sum across MPI ranks.

Author
Debojyoti Ghosh

Definition in file MPISum.c.

Function Documentation

◆ MPISum_integer()

int MPISum_integer ( int *  global,
int *  var,
int  size,
void *  comm 
)

Compute the global sum over all MPI ranks in a given communicator for int datatype.

  • If var is an array of size greater than 1, global will be an array of the same size with each element as the sum of that element in var on all the MPI ranks in the given communicator.
Parameters
globalarray to contain the global sums
varthe local array
sizesize of the local array
commMPI communicator

Definition at line 16 of file MPISum.c.

22 {
23 #ifdef serial
24  int i;
25  for (i = 0; i < size; i++) global[i] = var[i];
26 #else
27  MPI_Allreduce((var==global?MPI_IN_PLACE:var),global,size,MPI_INT,MPI_SUM,*((MPI_Comm*)comm));
28 #endif
29  return(0);
30 }

◆ MPISum_double()

int MPISum_double ( double *  global,
double *  var,
int  size,
void *  comm 
)

Compute the global sum over all MPI ranks in a given communicator for double datatype.

  • If var is an array of size greater than 1, global will be an array of the same size with each element as the sum of that element in var on all the MPI ranks in the given communicator.
Parameters
globalarray to contain the global sums
varthe local array
sizesize of the local array
commMPI communicator

Definition at line 39 of file MPISum.c.

45 {
46 #ifdef serial
47  int i;
48  for (i = 0; i < size; i++) global[i] = var[i];
49 #else
50  MPI_Allreduce((var==global?MPI_IN_PLACE:var),global,size,MPI_DOUBLE,MPI_SUM,*((MPI_Comm*)comm));
51 #endif
52  return(0);
53 }