root/ompi/mpi/c/allreduce.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. MPI_Allreduce

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2018 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2013      Los Alamos National Security, LLC.  All rights
  14  *                         reserved.
  15  * Copyright (c) 2015      Research Organization for Information Science
  16  *                         and Technology (RIST). All rights reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 #include "ompi_config.h"
  25 #include <stdio.h>
  26 
  27 #include "ompi/mpi/c/bindings.h"
  28 #include "ompi/runtime/params.h"
  29 #include "ompi/communicator/communicator.h"
  30 #include "ompi/errhandler/errhandler.h"
  31 #include "ompi/datatype/ompi_datatype.h"
  32 #include "ompi/op/op.h"
  33 #include "ompi/memchecker.h"
  34 #include "ompi/runtime/ompi_spc.h"
  35 
  36 #if OMPI_BUILD_MPI_PROFILING
  37 #if OPAL_HAVE_WEAK_SYMBOLS
  38 #pragma weak MPI_Allreduce = PMPI_Allreduce
  39 #endif
  40 #define MPI_Allreduce PMPI_Allreduce
  41 #endif
  42 
  43 static const char FUNC_NAME[] = "MPI_Allreduce";
  44 
  45 
  46 int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count,
  47                   MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
  48 {
  49     int err;
  50 
  51     SPC_RECORD(OMPI_SPC_ALLREDUCE, 1);
  52 
  53     MEMCHECKER(
  54         memchecker_datatype(datatype);
  55         memchecker_comm(comm);
  56 
  57         /* check whether receive buffer is defined. */
  58         memchecker_call(&opal_memchecker_base_isaddressable, recvbuf, count, datatype);
  59 
  60         /* check whether the actual send buffer is defined. */
  61         if (MPI_IN_PLACE == sendbuf) {
  62             memchecker_call(&opal_memchecker_base_isdefined, recvbuf, count, datatype);
  63         } else {
  64             memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
  65         }
  66     );
  67 
  68     if (MPI_PARAM_CHECK) {
  69         char *msg;
  70 
  71         /* Unrooted operation -- same checks for all ranks on both
  72            intracommunicators and intercommunicators */
  73 
  74         err = MPI_SUCCESS;
  75         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  76         if (ompi_comm_invalid(comm)) {
  77             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
  78                                           FUNC_NAME);
  79         } else if (MPI_OP_NULL == op) {
  80             err = MPI_ERR_OP;
  81         } else if (!ompi_op_is_valid(op, datatype, &msg, FUNC_NAME)) {
  82             int ret = OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_OP, msg);
  83             free(msg);
  84             return ret;
  85         } else if ((MPI_IN_PLACE == sendbuf && OMPI_COMM_IS_INTER(comm)) ||
  86                    MPI_IN_PLACE == recvbuf ) {
  87             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_BUFFER,
  88                                           FUNC_NAME);
  89         } else if( (sendbuf == recvbuf) &&
  90                    (MPI_BOTTOM != sendbuf) &&
  91                    (count > 1) ) {
  92             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_BUFFER,
  93                                           FUNC_NAME);
  94         } else {
  95             OMPI_CHECK_DATATYPE_FOR_SEND(err, datatype, count);
  96         }
  97         OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
  98     }
  99 
 100     /* MPI-1, p114, says that each process must supply at least
 101        one element.  But at least the Pallas benchmarks call
 102        MPI_REDUCE with a count of 0.  So be sure to handle it. */
 103 
 104     if (0 == count) {
 105         return MPI_SUCCESS;
 106     }
 107 
 108     OPAL_CR_ENTER_LIBRARY();
 109 
 110     /* Invoke the coll component to perform the back-end operation */
 111 
 112     OBJ_RETAIN(op);
 113     err = comm->c_coll->coll_allreduce(sendbuf, recvbuf, count,
 114                                       datatype, op, comm,
 115                                       comm->c_coll->coll_allreduce_module);
 116     OBJ_RELEASE(op);
 117     OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
 118 }
 119 

/* [<][>][^][v][top][bottom][index][help] */