root/ompi/mpi/c/bcast.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Bcast

   1 /*
   2  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2018 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2015      Research Organization for Information Science
  13  *                         and Technology (RIST). All rights reserved.
  14  * $COPYRIGHT$
  15  *
  16  * Additional copyrights may follow
  17  *
  18  * $HEADER$
  19  */
  20 #include "ompi_config.h"
  21 #include <stdio.h>
  22 
  23 #include "ompi/mpi/c/bindings.h"
  24 #include "ompi/runtime/params.h"
  25 #include "ompi/communicator/communicator.h"
  26 #include "ompi/errhandler/errhandler.h"
  27 #include "ompi/datatype/ompi_datatype.h"
  28 #include "ompi/memchecker.h"
  29 #include "ompi/runtime/ompi_spc.h"
  30 
  31 #if OMPI_BUILD_MPI_PROFILING
  32 #if OPAL_HAVE_WEAK_SYMBOLS
  33 #pragma weak MPI_Bcast = PMPI_Bcast
  34 #endif
  35 #define MPI_Bcast PMPI_Bcast
  36 #endif
  37 
  38 static const char FUNC_NAME[] = "MPI_Bcast";
  39 
  40 
  41 int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype,
  42               int root, MPI_Comm comm)
  43 {
  44     int err;
  45 
  46     SPC_RECORD(OMPI_SPC_BCAST, 1);
  47 
  48     MEMCHECKER(
  49         memchecker_datatype(datatype);
  50         memchecker_comm(comm);
  51         if (OMPI_COMM_IS_INTRA(comm)) {
  52             if (ompi_comm_rank(comm) == root) {
  53                 /* check whether root's send buffer is defined. */
  54                 memchecker_call(&opal_memchecker_base_isdefined, buffer, count, datatype);
  55             }
  56             /* check whether receive buffer is addressable. */
  57             memchecker_call(&opal_memchecker_base_isaddressable, buffer, count, datatype);
  58         } else {
  59             if (MPI_ROOT == root) {
  60                 /* check whether root's send buffer is defined. */
  61                 memchecker_call(&opal_memchecker_base_isdefined, buffer, count, datatype);
  62             } else if (MPI_PROC_NULL != root) {
  63                 /* check whether receive buffer is addressable. */
  64                 memchecker_call(&opal_memchecker_base_isaddressable, buffer, count, datatype);
  65             }
  66         }
  67     );
  68 
  69     if (MPI_PARAM_CHECK) {
  70       err = MPI_SUCCESS;
  71       OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  72       if (ompi_comm_invalid(comm)) {
  73           return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
  74                                      FUNC_NAME);
  75       }
  76 
  77       /* Errors for all ranks */
  78 
  79       OMPI_CHECK_DATATYPE_FOR_SEND(err, datatype, count);
  80       OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
  81       if (MPI_IN_PLACE == buffer) {
  82           return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
  83       }
  84 
  85       /* Errors for intracommunicators */
  86 
  87       if (OMPI_COMM_IS_INTRA(comm)) {
  88         if ((root >= ompi_comm_size(comm)) || (root < 0)) {
  89           return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
  90         }
  91       }
  92 
  93       /* Errors for intercommunicators */
  94 
  95       else {
  96         if (! ((root >= 0 && root < ompi_comm_remote_size(comm)) ||
  97                MPI_ROOT == root || MPI_PROC_NULL == root)) {
  98             return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
  99         }
 100       }
 101     }
 102 
 103     /* If there's only one node, or if the count is 0, we're done */
 104 
 105     if ((OMPI_COMM_IS_INTRA(comm) && ompi_comm_size(comm) <= 1) ||
 106         0 == count) {
 107         return MPI_SUCCESS;
 108     }
 109 
 110     OPAL_CR_ENTER_LIBRARY();
 111 
 112     /* Invoke the coll component to perform the back-end operation */
 113 
 114     err = comm->c_coll->coll_bcast(buffer, count, datatype, root, comm,
 115                                   comm->c_coll->coll_bcast_module);
 116     OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
 117 }

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