root/ompi/mpiext/pcollreq/c/gatherv_init.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPIX_Gatherv_init

   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-2017 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-2012 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
  15  *                         reserved.
  16  * Copyright (c) 2015-2018 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/mpiext/pcollreq/c/mpiext_pcollreq_c.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 MPIX_Gatherv_init = PMPIX_Gatherv_init
  39 #endif
  40 #define MPIX_Gatherv_init PMPIX_Gatherv_init
  41 #endif
  42 
  43 static const char FUNC_NAME[] = "MPIX_Gatherv_init";
  44 
  45 
  46 int MPIX_Gatherv_init(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
  47                       void *recvbuf, const int recvcounts[], const int displs[],
  48                       MPI_Datatype recvtype, int root, MPI_Comm comm,
  49                       MPI_Info info, MPI_Request *request)
  50 {
  51     int i, size, err;
  52 
  53     SPC_RECORD(OMPI_SPC_GATHERV_INIT, 1);
  54 
  55     MEMCHECKER(
  56         ptrdiff_t ext;
  57 
  58         size = ompi_comm_remote_size(comm);
  59         ompi_datatype_type_extent(recvtype, &ext);
  60 
  61         memchecker_comm(comm);
  62         if(OMPI_COMM_IS_INTRA(comm)) {
  63             if(ompi_comm_rank(comm) == root) {
  64                 /* check whether root's send buffer is defined. */
  65                 if (MPI_IN_PLACE == sendbuf) {
  66                     for (i = 0; i < size; i++) {
  67                         memchecker_call(&opal_memchecker_base_isdefined,
  68                                         (char *)(recvbuf)+displs[i]*ext,
  69                                         recvcounts[i], recvtype);
  70                     }
  71                 } else {
  72                     memchecker_datatype(sendtype);
  73                     memchecker_call(&opal_memchecker_base_isdefined, sendbuf, sendcount, sendtype);
  74                 }
  75 
  76                 memchecker_datatype(recvtype);
  77                 /* check whether root's receive buffer is addressable. */
  78                 for (i = 0; i < size; i++) {
  79                     memchecker_call(&opal_memchecker_base_isaddressable,
  80                                     (char *)(recvbuf)+displs[i]*ext,
  81                                     recvcounts[i], recvtype);
  82                 }
  83             } else {
  84                 memchecker_datatype(sendtype);
  85                 /* check whether send buffer is defined on other processes. */
  86                 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, sendcount, sendtype);
  87             }
  88         } else {
  89             if (MPI_ROOT == root) {
  90                 memchecker_datatype(recvtype);
  91                 /* check whether root's receive buffer is addressable. */
  92                 for (i = 0; i < size; i++) {
  93                     memchecker_call(&opal_memchecker_base_isaddressable,
  94                                     (char *)(recvbuf)+displs[i]*ext,
  95                                     recvcounts[i], recvtype);
  96                 }
  97             } else if (MPI_PROC_NULL != root) {
  98                 memchecker_datatype(sendtype);
  99                 /* check whether send buffer is defined. */
 100                 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, sendcount, sendtype);
 101             }
 102         }
 103     );
 104 
 105     if (MPI_PARAM_CHECK) {
 106         err = MPI_SUCCESS;
 107         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
 108         if (ompi_comm_invalid(comm)) {
 109             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
 110                                           FUNC_NAME);
 111         } else if ((ompi_comm_rank(comm) != root && MPI_IN_PLACE == sendbuf) ||
 112                    (ompi_comm_rank(comm) == root && MPI_IN_PLACE == recvbuf)) {
 113             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
 114         }
 115 
 116         /* Errors for intracommunicators */
 117 
 118         if (OMPI_COMM_IS_INTRA(comm)) {
 119 
 120             /* Errors for all ranks */
 121 
 122             if ((root >= ompi_comm_size(comm)) || (root < 0)) {
 123                 err = MPI_ERR_ROOT;
 124             } else if (MPI_IN_PLACE != sendbuf) {
 125                 OMPI_CHECK_DATATYPE_FOR_SEND(err, sendtype, sendcount);
 126             }
 127             OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
 128 
 129             /* Errors for the root.  Some of these could have been
 130                combined into compound if statements above, but since
 131                this whole section can be compiled out (or turned off at
 132                run time) for efficiency, it's more clear to separate
 133                them out into individual tests. */
 134 
 135             if (ompi_comm_rank(comm) == root) {
 136                 if (NULL == displs) {
 137                     return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
 138                 }
 139 
 140                 if (NULL == recvcounts) {
 141                     return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
 142                 }
 143 
 144                 size = ompi_comm_size(comm);
 145                 for (i = 0; i < size; ++i) {
 146                     if (recvcounts[i] < 0) {
 147                         return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
 148                     } else if (MPI_DATATYPE_NULL == recvtype || NULL == recvtype) {
 149                         return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
 150                     }
 151                 }
 152             }
 153         }
 154 
 155         /* Errors for intercommunicators */
 156 
 157         else {
 158             if (! ((root >= 0 && root < ompi_comm_remote_size(comm)) ||
 159                    MPI_ROOT == root || MPI_PROC_NULL == root)) {
 160                 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
 161             }
 162 
 163             /* Errors for the senders */
 164 
 165             if (MPI_ROOT != root && MPI_PROC_NULL != root) {
 166                 OMPI_CHECK_DATATYPE_FOR_SEND(err, sendtype, sendcount);
 167                 OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
 168             }
 169 
 170             /* Errors for the root.  Ditto on the comment above -- these
 171                error checks could have been combined above, but let's
 172                make the code easier to read. */
 173 
 174             else if (MPI_ROOT == root) {
 175                 if (NULL == displs) {
 176                     return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
 177                 }
 178 
 179                 if (NULL == recvcounts) {
 180                     return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
 181                 }
 182 
 183                 size = ompi_comm_remote_size(comm);
 184                 for (i = 0; i < size; ++i) {
 185                     if (recvcounts[i] < 0) {
 186                         return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
 187                     } else if (MPI_DATATYPE_NULL == recvtype || NULL == recvtype) {
 188                         return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
 189                     }
 190                 }
 191             }
 192         }
 193     }
 194 
 195     OPAL_CR_ENTER_LIBRARY();
 196 
 197     /* Invoke the coll component to perform the back-end operation */
 198     err = comm->c_coll->coll_gatherv_init(sendbuf, sendcount, sendtype, recvbuf,
 199                                           recvcounts, displs, recvtype,
 200                                           root, comm, info, request,
 201                                           comm->c_coll->coll_gatherv_init_module);
 202     OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
 203 }

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