root/ompi/mpi/c/gather.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Gather

   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-2007 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2008      University of Houston.  All rights reserved.
  15  * Copyright (c) 2008      Sun Microsystems, Inc.  All rights reserved.
  16  * Copyright (c) 2013      Los Alamos National Security, LLC.  All rights
  17  *                         reserved.
  18  * Copyright (c) 2015      Research Organization for Information Science
  19  *                         and Technology (RIST). All rights reserved.
  20  * $COPYRIGHT$
  21  *
  22  * Additional copyrights may follow
  23  *
  24  * $HEADER$
  25  */
  26 #include "ompi_config.h"
  27 #include <stdio.h>
  28 
  29 #include "ompi/mpi/c/bindings.h"
  30 #include "ompi/runtime/params.h"
  31 #include "ompi/communicator/communicator.h"
  32 #include "ompi/errhandler/errhandler.h"
  33 #include "ompi/datatype/ompi_datatype.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_Gather = PMPI_Gather
  40 #endif
  41 #define MPI_Gather PMPI_Gather
  42 #endif
  43 
  44 static const char FUNC_NAME[] = "MPI_Gather";
  45 
  46 
  47 int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
  48                void *recvbuf, int recvcount, MPI_Datatype recvtype,
  49                int root, MPI_Comm comm)
  50 {
  51     int err;
  52 
  53     SPC_RECORD(OMPI_SPC_GATHER, 1);
  54 
  55     MEMCHECKER(
  56         int rank;
  57         ptrdiff_t ext;
  58 
  59         rank = ompi_comm_rank(comm);
  60         ompi_datatype_type_extent(recvtype, &ext);
  61 
  62         memchecker_comm(comm);
  63         if(OMPI_COMM_IS_INTRA(comm)) {
  64             if(ompi_comm_rank(comm) == root) {
  65                 /* check whether root's send buffer is defined. */
  66                 if (MPI_IN_PLACE == sendbuf) {
  67                   memchecker_call(&opal_memchecker_base_isdefined,
  68                                   (char *)(recvbuf)+rank*ext,
  69                                   recvcount, recvtype);
  70                 } else {
  71                     memchecker_datatype(sendtype);
  72                     memchecker_call(&opal_memchecker_base_isdefined, sendbuf, sendcount, sendtype);
  73                 }
  74 
  75                 memchecker_datatype(recvtype);
  76                 /* check whether root's receive buffer is addressable. */
  77                 memchecker_call(&opal_memchecker_base_isaddressable, recvbuf, recvcount, recvtype);
  78             } else {
  79                 memchecker_datatype(sendtype);
  80                 /* check whether send buffer is defined on other processes. */
  81                 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, sendcount, sendtype);
  82             }
  83         } else {
  84             if (MPI_ROOT == root) {
  85                 memchecker_datatype(recvtype);
  86                 /* check whether root's receive buffer is addressable. */
  87                 memchecker_call(&opal_memchecker_base_isaddressable, recvbuf, recvcount, recvtype);
  88             } else if (MPI_PROC_NULL != root) {
  89                 memchecker_datatype(sendtype);
  90                 /* check whether send buffer is defined. */
  91                 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, sendcount, sendtype);
  92             }
  93         }
  94     );
  95 
  96     if (MPI_PARAM_CHECK) {
  97         err = MPI_SUCCESS;
  98         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  99         if (ompi_comm_invalid(comm)) {
 100             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
 101                                           FUNC_NAME);
 102         } else if ((ompi_comm_rank(comm) != root && MPI_IN_PLACE == sendbuf) ||
 103                    (ompi_comm_rank(comm) == root && MPI_IN_PLACE == recvbuf)) {
 104             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
 105         }
 106 
 107         /* Errors for intracommunicators */
 108 
 109         if (OMPI_COMM_IS_INTRA(comm)) {
 110 
 111             /* Errors for all ranks */
 112 
 113             if ((root >= ompi_comm_size(comm)) || (root < 0)) {
 114                 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
 115             }
 116 
 117             if (MPI_IN_PLACE != sendbuf) {
 118                 OMPI_CHECK_DATATYPE_FOR_SEND(err, sendtype, sendcount);
 119             }
 120             OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
 121 
 122             /* Errors for the root.  Some of these could have been
 123                combined into compound if statements above, but since
 124                this whole section can be compiled out (or turned off at
 125                run time) for efficiency, it's more clear to separate
 126                them out into individual tests. */
 127 
 128             if (ompi_comm_rank(comm) == root) {
 129                 if (MPI_DATATYPE_NULL == recvtype || NULL == recvtype) {
 130                     return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
 131                 }
 132 
 133                 if (recvcount < 0) {
 134                     return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
 135                 }
 136             }
 137         }
 138 
 139         /* Errors for intercommunicators */
 140 
 141         else {
 142             if (! ((root >= 0 && root < ompi_comm_remote_size(comm)) ||
 143                    MPI_ROOT == root || MPI_PROC_NULL == root)) {
 144                 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
 145             }
 146 
 147             /* Errors for the senders */
 148 
 149             if (MPI_ROOT != root && MPI_PROC_NULL != root) {
 150                 OMPI_CHECK_DATATYPE_FOR_SEND(err, sendtype, sendcount);
 151                 OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
 152             }
 153 
 154             /* Errors for the root.  Ditto on the comment above -- these
 155                error checks could have been combined above, but let's
 156                make the code easier to read. */
 157 
 158             else if (MPI_ROOT == root) {
 159                 if (recvcount < 0) {
 160                     return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
 161                 }
 162 
 163                 if (MPI_DATATYPE_NULL == recvtype || NULL == recvtype) {
 164                     return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
 165                 }
 166             }
 167         }
 168     }
 169 
 170     /* Do we need to do anything? */
 171 
 172     if ((0 == sendcount && MPI_ROOT != root &&
 173          (ompi_comm_rank(comm) != root ||
 174           (ompi_comm_rank(comm) == root && MPI_IN_PLACE != sendbuf))) ||
 175         (ompi_comm_rank(comm) == root && MPI_IN_PLACE == sendbuf &&
 176          0 == recvcount) ||
 177         (0 == recvcount && (MPI_ROOT == root || MPI_PROC_NULL == root))) {
 178         return MPI_SUCCESS;
 179     }
 180 
 181     OPAL_CR_ENTER_LIBRARY();
 182 
 183     /* Invoke the coll component to perform the back-end operation */
 184     err = comm->c_coll->coll_gather(sendbuf, sendcount, sendtype, recvbuf,
 185                                    recvcount, recvtype, root, comm,
 186                                    comm->c_coll->coll_gather_module);
 187     OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
 188 }

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