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

Functions to compute the maximum over all MPI ranks. More...

#include <mpivars.h>

Go to the source code of this file.

Functions

int MPIMax_integer (int *global, int *var, int size, void *comm)
 
int MPIMax_double (double *global, double *var, int size, void *comm)
 

Detailed Description

Functions to compute the maximum over all MPI ranks.

Author
Debojyoti Ghosh

Definition in file MPIMax.c.

Function Documentation

◆ MPIMax_integer()

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

Compute the global maximum 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 maximum value of that element in var on all the MPI ranks in the given communicator.
Parameters
globalarray to contain the global maximums
varthe local array
sizesize of the local array
commMPI communicator

Definition at line 15 of file MPIMax.c.

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

◆ MPIMax_double()

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

Compute the global maximum 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 maximum value of that element in var on all the MPI ranks in the given communicator.
Parameters
globalarray to contain the global maximums
varthe local array
sizesize of the local array
commMPI communicator

Definition at line 38 of file MPIMax.c.

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