libsc  2.8.7
The SC library provides support for parallel scientific applications.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Macros | Typedefs | Functions
sc_reduce.h File Reference

Self-contained implementations of MPI_Reduce and MPI_Allreduce. More...

#include <sc.h>
Include dependency graph for sc_reduce.h:

Go to the source code of this file.

Macros

#define SC_REDUCE_ALLTOALL_LEVEL   3
 The highest recursion level that uses direct all-to-all.
 

Typedefs

typedef void(* sc_reduce_t) (void *sendbuf, void *recvbuf, int sendcount, sc_MPI_Datatype sendtype)
 Prototype for a user-defined reduce operation.
 

Functions

int sc_allreduce_custom (void *sendbuf, void *recvbuf, int sendcount, sc_MPI_Datatype sendtype, sc_reduce_t reduce_fn, sc_MPI_Comm mpicomm)
 Custom allreduce operation with reproducible associativity. More...
 
int sc_reduce_custom (void *sendbuf, void *recvbuf, int sendcount, sc_MPI_Datatype sendtype, sc_reduce_t reduce_fn, int target, sc_MPI_Comm mpicomm)
 Custom reduce operation with reproducible associativity. More...
 
int sc_allreduce (void *sendbuf, void *recvbuf, int sendcount, sc_MPI_Datatype sendtype, sc_MPI_Op operation, sc_MPI_Comm mpicomm)
 Drop-in MPI_Allreduce replacement with reproducible associativity. More...
 
int sc_reduce (void *sendbuf, void *recvbuf, int sendcount, sc_MPI_Datatype sendtype, sc_MPI_Op operation, int target, sc_MPI_Comm mpicomm)
 Drop-in MPI_Reduce replacement with reproducible associativity. More...
 

Detailed Description

Self-contained implementations of MPI_Reduce and MPI_Allreduce.

Our motivation for writing these alternatives is reproducible associativity. With this implementation, the associativity of the reduction operation depends on the size of the communicator only and does not suffer from random or otherwise obscure influences.

Both algorithms use a binary communication tree. We provide implementations via a customizable reduction operator as well as drop-in replacements for minimum, maximum, and sum. We do not currently support user-defined MPI datatypes.

Function Documentation

◆ sc_allreduce()

int sc_allreduce ( void *  sendbuf,
void *  recvbuf,
int  sendcount,
sc_MPI_Datatype  sendtype,
sc_MPI_Op  operation,
sc_MPI_Comm  mpicomm 
)

Drop-in MPI_Allreduce replacement with reproducible associativity.

Currently we support the operations minimum, maximum, and sum.

Parameters
[in]sendbufSend buffer conforming to MPI specification.
[out]recvbufReceive buffer conforming to MPI specification.
[in]sendcountNumber of data items to reduce.
[in]sendtypeValid MPI datatype.
[in]operationsc_MPI_MIN, sc_MPI_MAX, or sc_MPI_SUM. We abort otherwise.
[in]mpicommValid MPI communicator.
Returns
sc_MPI_SUCCESS if not aborting on MPI error.

◆ sc_allreduce_custom()

int sc_allreduce_custom ( void *  sendbuf,
void *  recvbuf,
int  sendcount,
sc_MPI_Datatype  sendtype,
sc_reduce_t  reduce_fn,
sc_MPI_Comm  mpicomm 
)

Custom allreduce operation with reproducible associativity.

Parameters
[in]sendbufSend buffer conforming to MPI specification.
[out]recvbufReceive buffer conforming to MPI specification.
[in]sendcountNumber of data items to reduce.
[in]sendtypeValid MPI datatype.
[in]reduce_fnCustom, associative reduction operator.
[in]mpicommValid MPI communicator.
Returns
sc_MPI_SUCCESS if not aborting on MPI error.

◆ sc_reduce()

int sc_reduce ( void *  sendbuf,
void *  recvbuf,
int  sendcount,
sc_MPI_Datatype  sendtype,
sc_MPI_Op  operation,
int  target,
sc_MPI_Comm  mpicomm 
)

Drop-in MPI_Reduce replacement with reproducible associativity.

Currently we support the operations minimum, maximum, and sum.

Parameters
[in]sendbufSend buffer conforming to MPI specification.
[out]recvbufReceive buffer conforming to MPI specification.
[in]sendcountNumber of data items to reduce.
[in]sendtypeValid MPI datatype.
[in]operationsc_MPI_MIN, sc_MPI_MAX, or sc_MPI_SUM. We abort otherwise.
[in]targetThe MPI rank that obtains the result.
[in]mpicommValid MPI communicator.
Returns
sc_MPI_SUCCESS if not aborting on MPI error.

◆ sc_reduce_custom()

int sc_reduce_custom ( void *  sendbuf,
void *  recvbuf,
int  sendcount,
sc_MPI_Datatype  sendtype,
sc_reduce_t  reduce_fn,
int  target,
sc_MPI_Comm  mpicomm 
)

Custom reduce operation with reproducible associativity.

Parameters
[in]sendbufSend buffer conforming to MPI specification.
[out]recvbufReceive buffer conforming to MPI specification.
[in]sendcountNumber of data items to reduce.
[in]sendtypeValid MPI datatype.
[in]reduce_fnCustom, associative reduction operator.
[in]targetThe MPI rank that obtains the result.
[in]mpicommValid MPI communicator.
Returns
sc_MPI_SUCCESS if not aborting on MPI error.