root/ompi/mpi/c/iallreduce.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Iallreduce

   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 (c) 2016      IBM Corporation.  All rights reserved.
  18  * $COPYRIGHT$
  19  *
  20  * Additional copyrights may follow
  21  *
  22  * $HEADER$
  23  */
  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_Iallreduce = PMPI_Iallreduce
  40 #endif
  41 #define MPI_Iallreduce PMPI_Iallreduce
  42 #endif
  43 
  44 static const char FUNC_NAME[] = "MPI_Iallreduce";
  45 
  46 
  47 int MPI_Iallreduce(const void *sendbuf, void *recvbuf, int count,
  48                    MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request *request)
  49 {
  50     int err;
  51 
  52     SPC_RECORD(OMPI_SPC_IALLREDUCE, 1);
  53 
  54     MEMCHECKER(
  55         memchecker_datatype(datatype);
  56         memchecker_comm(comm);
  57 
  58         /* check whether receive buffer is defined. */
  59         memchecker_call(&opal_memchecker_base_isaddressable, recvbuf, count, datatype);
  60 
  61         /* check whether the actual send buffer is defined. */
  62         if (MPI_IN_PLACE == sendbuf) {
  63             memchecker_call(&opal_memchecker_base_isdefined, recvbuf, count, datatype);
  64         } else {
  65             memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
  66         }
  67     );
  68 
  69     if (MPI_PARAM_CHECK) {
  70         char *msg;
  71 
  72         /* Unrooted operation -- same checks for all ranks on both
  73            intracommunicators and intercommunicators */
  74 
  75         err = MPI_SUCCESS;
  76         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  77         if (ompi_comm_invalid(comm)) {
  78             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
  79                                           FUNC_NAME);
  80         } else if (MPI_OP_NULL == op) {
  81             err = MPI_ERR_OP;
  82         } else if (!ompi_op_is_valid(op, datatype, &msg, FUNC_NAME)) {
  83             int ret = OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_OP, msg);
  84             free(msg);
  85             return ret;
  86         } else if ((MPI_IN_PLACE == sendbuf && OMPI_COMM_IS_INTER(comm)) ||
  87                    MPI_IN_PLACE == recvbuf ) {
  88             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_BUFFER,
  89                                           FUNC_NAME);
  90         } else if( (sendbuf == recvbuf) &&
  91                    (MPI_BOTTOM != sendbuf) &&
  92                    (count > 1) ) {
  93             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_BUFFER,
  94                                           FUNC_NAME);
  95         } else {
  96             OMPI_CHECK_DATATYPE_FOR_SEND(err, datatype, count);
  97         }
  98         OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
  99     }
 100 
 101 
 102     /* MPI standard says that reductions have to have a count of at least 1,
 103      * but some benchmarks (e.g., IMB) calls this function with a count of 0.
 104      * So handle that case.
 105      */
 106     if (0 == count) {
 107         *request = &ompi_request_empty;
 108         return MPI_SUCCESS;
 109     }
 110 
 111     OPAL_CR_ENTER_LIBRARY();
 112 
 113     /* Invoke the coll component to perform the back-end operation */
 114 
 115     OBJ_RETAIN(op);
 116     err = comm->c_coll->coll_iallreduce(sendbuf, recvbuf, count, datatype,
 117                                        op, comm, request, comm->c_coll->coll_iallreduce_module);
 118     OBJ_RELEASE(op);
 119     OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
 120 }
 121 

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