root/ompi/mpi/c/ireduce.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Ireduce

   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 (c) 2016      IBM Corporation.  All rights reserved.
  19  * $COPYRIGHT$
  20  *
  21  * Additional copyrights may follow
  22  *
  23  * $HEADER$
  24  */
  25 #include "ompi_config.h"
  26 #include <stdio.h>
  27 
  28 #include "ompi/mpi/c/bindings.h"
  29 #include "ompi/runtime/params.h"
  30 #include "ompi/communicator/communicator.h"
  31 #include "ompi/errhandler/errhandler.h"
  32 #include "ompi/datatype/ompi_datatype.h"
  33 #include "ompi/op/op.h"
  34 #include "ompi/memchecker.h"
  35 #include "ompi/runtime/ompi_spc.h"
  36 
  37 #if OMPI_BUILD_MPI_PROFILING
  38 #if OPAL_HAVE_WEAK_SYMBOLS
  39 #pragma weak MPI_Ireduce = PMPI_Ireduce
  40 #endif
  41 #define MPI_Ireduce PMPI_Ireduce
  42 #endif
  43 
  44 static const char FUNC_NAME[] = "MPI_Ireduce";
  45 
  46 
  47 int MPI_Ireduce(const void *sendbuf, void *recvbuf, int count,
  48                 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm, MPI_Request *request)
  49 {
  50     int err;
  51 
  52     SPC_RECORD(OMPI_SPC_IREDUCE, 1);
  53 
  54     MEMCHECKER(
  55         memchecker_datatype(datatype);
  56         memchecker_comm(comm);
  57 
  58         if(OMPI_COMM_IS_INTRA(comm)) {
  59             if(ompi_comm_rank(comm) == root) {
  60                 /* check whether root's 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                 /* check whether root's receive buffer is addressable. */
  68                 memchecker_call(&opal_memchecker_base_isaddressable, recvbuf, count, datatype);
  69             } else {
  70                 /* check whether send buffer is defined on other processes. */
  71                 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
  72             }
  73         } else {
  74             if (MPI_ROOT == root) {
  75                 /* check whether root's receive buffer is addressable. */
  76                 memchecker_call(&opal_memchecker_base_isaddressable, recvbuf, count, datatype);
  77             } else if (MPI_PROC_NULL != root) {
  78                 /* check whether send buffer is defined. */
  79                 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
  80             }
  81         }
  82     );
  83 
  84     if (MPI_PARAM_CHECK) {
  85         char *msg;
  86         err = MPI_SUCCESS;
  87         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  88         if (ompi_comm_invalid(comm)) {
  89             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
  90                                           FUNC_NAME);
  91         }
  92 
  93         /* Checks for all ranks */
  94 
  95         else if (MPI_OP_NULL == op || NULL == op) {
  96             err = MPI_ERR_OP;
  97         } else if (!ompi_op_is_valid(op, datatype, &msg, FUNC_NAME)) {
  98             int ret = OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_OP, msg);
  99             free(msg);
 100             return ret;
 101         } else if ((ompi_comm_rank(comm) != root && MPI_IN_PLACE == sendbuf) ||
 102                    (ompi_comm_rank(comm) == root && ((MPI_IN_PLACE == recvbuf) || (sendbuf == recvbuf)))) {
 103             err = MPI_ERR_ARG;
 104         } else {
 105             OMPI_CHECK_DATATYPE_FOR_SEND(err, datatype, count);
 106         }
 107         OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
 108 
 109         /* Intercommunicator errors */
 110 
 111         if (!OMPI_COMM_IS_INTRA(comm)) {
 112             if (! ((root >= 0 && root < ompi_comm_remote_size(comm)) ||
 113                    MPI_ROOT == root || MPI_PROC_NULL == root)) {
 114                 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
 115             }
 116         }
 117 
 118         /* Intracommunicator errors */
 119 
 120         else {
 121             if (root < 0 || root >= ompi_comm_size(comm)) {
 122                 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
 123             }
 124         }
 125     }
 126 
 127     /* MPI standard says that reductions have to have a count of at least 1,
 128      * but some benchmarks (e.g., IMB) calls this function with a count of 0.
 129      * So handle that case.
 130      */
 131     if (0 == count) {
 132         *request = &ompi_request_empty;
 133         return MPI_SUCCESS;
 134     }
 135 
 136     OPAL_CR_ENTER_LIBRARY();
 137 
 138     /* Invoke the coll component to perform the back-end operation */
 139     OBJ_RETAIN(op);
 140     err = comm->c_coll->coll_ireduce(sendbuf, recvbuf, count,
 141                                     datatype, op, root, comm, request,
 142                                     comm->c_coll->coll_ireduce_module);
 143     OBJ_RELEASE(op);
 144     OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
 145 }

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