root/ompi/mpi/c/reduce.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Reduce

   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) 2006      Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2013      Los Alamos National Security, LLC.  All rights
  15  *                         reserved.
  16  * Copyright (c) 2015      Research Organization for Information Science
  17  *                         and Technology (RIST). All rights reserved.
  18  * $COPYRIGHT$
  19  *
  20  * Additional copyrights may follow
  21  *
  22  * $HEADER$
  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_Reduce = PMPI_Reduce
  39 #endif
  40 #define MPI_Reduce PMPI_Reduce
  41 #endif
  42 
  43 static const char FUNC_NAME[] = "MPI_Reduce";
  44 
  45 
  46 int MPI_Reduce(const void *sendbuf, void *recvbuf, int count,
  47                MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
  48 {
  49     int err;
  50 
  51     SPC_RECORD(OMPI_SPC_REDUCE, 1);
  52 
  53     MEMCHECKER(
  54         memchecker_datatype(datatype);
  55         memchecker_comm(comm);
  56 
  57         if(OMPI_COMM_IS_INTRA(comm)) {
  58             if(ompi_comm_rank(comm) == root) {
  59                 /* check whether root's send buffer is defined. */
  60                 if (MPI_IN_PLACE == sendbuf) {
  61                     memchecker_call(&opal_memchecker_base_isdefined, recvbuf, count, datatype);
  62                 } else {
  63                     memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
  64                 }
  65 
  66                 /* check whether root's receive buffer is addressable. */
  67                 memchecker_call(&opal_memchecker_base_isaddressable, recvbuf, count, datatype);
  68             } else {
  69                 /* check whether send buffer is defined on other processes. */
  70                 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
  71             }
  72         } else {
  73             if (MPI_ROOT == root) {
  74                 /* check whether root's receive buffer is addressable. */
  75                 memchecker_call(&opal_memchecker_base_isaddressable, recvbuf, count, datatype);
  76             } else if (MPI_PROC_NULL != root) {
  77                 /* check whether send buffer is defined. */
  78                 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
  79             }
  80         }
  81     );
  82 
  83     if (MPI_PARAM_CHECK) {
  84         char *msg;
  85         err = MPI_SUCCESS;
  86         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  87         if (ompi_comm_invalid(comm)) {
  88             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
  89                                           FUNC_NAME);
  90         }
  91 
  92         /* Checks for all ranks */
  93 
  94         else if (MPI_OP_NULL == op || NULL == op) {
  95             err = MPI_ERR_OP;
  96         } else if (!ompi_op_is_valid(op, datatype, &msg, FUNC_NAME)) {
  97             int ret = OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_OP, msg);
  98             free(msg);
  99             return ret;
 100         } else if ((ompi_comm_rank(comm) != root && MPI_IN_PLACE == sendbuf) ||
 101                    (ompi_comm_rank(comm) == root && ((MPI_IN_PLACE == recvbuf) || (sendbuf == recvbuf)))) {
 102             err = MPI_ERR_ARG;
 103         } else {
 104             OMPI_CHECK_DATATYPE_FOR_SEND(err, datatype, count);
 105         }
 106         OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
 107 
 108         /* Intercommunicator errors */
 109 
 110         if (!OMPI_COMM_IS_INTRA(comm)) {
 111             if (! ((root >= 0 && root < ompi_comm_remote_size(comm)) ||
 112                    MPI_ROOT == root || MPI_PROC_NULL == root)) {
 113                 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
 114             }
 115         }
 116 
 117         /* Intracommunicator errors */
 118 
 119         else {
 120             if (root < 0 || root >= ompi_comm_size(comm)) {
 121                 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
 122             }
 123         }
 124     }
 125 
 126     /* Do we need to do anything? (MPI says that reductions have to
 127        have a count of at least 1, but at least IMB calls reduce with
 128        a count of 0 -- blah!) */
 129 
 130     if (0 == count) {
 131         return MPI_SUCCESS;
 132     }
 133 
 134     OPAL_CR_ENTER_LIBRARY();
 135 
 136     /* Invoke the coll component to perform the back-end operation */
 137 
 138     OBJ_RETAIN(op);
 139     err = comm->c_coll->coll_reduce(sendbuf, recvbuf, count,
 140                                    datatype, op, root, comm,
 141                                    comm->c_coll->coll_reduce_module);
 142     OBJ_RELEASE(op);
 143     OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
 144 }

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