root/ompi/mca/coll/inter/coll_inter_allgatherv.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_coll_inter_allgatherv_inter

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2017 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 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) 2006-2010 University of Houston. All rights reserved.
  13  * Copyright (c) 2015-2017 Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 #include "ompi_config.h"
  23 #include "coll_inter.h"
  24 
  25 #include "mpi.h"
  26 #include "ompi/datatype/ompi_datatype.h"
  27 #include "ompi/communicator/communicator.h"
  28 #include "ompi/constants.h"
  29 #include "ompi/mca/coll/coll.h"
  30 #include "ompi/mca/coll/base/coll_tags.h"
  31 #include "ompi/mca/coll/base/coll_base_util.h"
  32 #include "ompi/mca/pml/pml.h"
  33 
  34 
  35 /*
  36  *      allgatherv_inter
  37  *
  38  *      Function:       - allgatherv using other MPI collectives
  39  *      Accepts:        - same as MPI_Allgatherv()
  40  *      Returns:        - MPI_SUCCESS or error code
  41  */
  42 int
  43 mca_coll_inter_allgatherv_inter(const void *sbuf, int scount,
  44                                 struct ompi_datatype_t *sdtype,
  45                                 void *rbuf, const int *rcounts, const int *disps,
  46                                 struct ompi_datatype_t *rdtype,
  47                                 struct ompi_communicator_t *comm,
  48                                mca_coll_base_module_t *module)
  49 {
  50     int i, rank, size, size_local, total=0, err;
  51     int *count=NULL,*displace=NULL;
  52     char *ptmp_free=NULL, *ptmp=NULL;
  53     ompi_datatype_t *ndtype = NULL;
  54 
  55     rank = ompi_comm_rank(comm);
  56     size_local = ompi_comm_size(comm->c_local_comm);
  57     size = ompi_comm_remote_size(comm);
  58 
  59     if (0 == rank) {
  60         count = (int *)malloc(sizeof(int) * size_local);
  61         displace = (int *)malloc(sizeof(int) * size_local);
  62         if ((NULL == count) || (NULL == displace)) {
  63             err = OMPI_ERR_OUT_OF_RESOURCE;
  64             goto exit;
  65         }
  66     }
  67     /* Local gather to get the scount of each process */
  68     err = comm->c_local_comm->c_coll->coll_gather(&scount, 1, MPI_INT,
  69                                                  count, 1, MPI_INT,
  70                                                  0, comm->c_local_comm,
  71                                                  comm->c_local_comm->c_coll->coll_gather_module);
  72     if (OMPI_SUCCESS != err) {
  73         goto exit;
  74     }
  75     if(0 == rank) {
  76         displace[0] = 0;
  77         for (i = 1; i < size_local; i++) {
  78             displace[i] = displace[i-1] + count[i-1];
  79         }
  80         total = 0;
  81         for (i = 0; i < size_local; i++) {
  82             total = total + count[i];
  83         }
  84         if ( total > 0 ) {
  85             ptrdiff_t gap, span;
  86             span = opal_datatype_span(&sdtype->super, total, &gap);
  87             ptmp_free = (char*)malloc(span);
  88             if (NULL == ptmp_free) {
  89                 err = OMPI_ERR_OUT_OF_RESOURCE;
  90                 goto exit;
  91             }
  92             ptmp = ptmp_free - gap;
  93         }
  94     }
  95     err = comm->c_local_comm->c_coll->coll_gatherv(sbuf, scount, sdtype,
  96                                                   ptmp, count, displace,
  97                                                   sdtype,0, comm->c_local_comm,
  98                                                   comm->c_local_comm->c_coll->coll_gatherv_module);
  99     if (OMPI_SUCCESS != err) {
 100         goto exit;
 101     }
 102 
 103     ompi_datatype_create_indexed(size,rcounts,disps,rdtype,&ndtype);
 104     ompi_datatype_commit(&ndtype);
 105 
 106     if (0 == rank) {
 107         /* Exchange data between roots */
 108         err = ompi_coll_base_sendrecv_actual(ptmp, total, sdtype, 0,
 109                                              MCA_COLL_BASE_TAG_ALLGATHERV,
 110                                              rbuf, 1, ndtype, 0,
 111                                              MCA_COLL_BASE_TAG_ALLGATHERV,
 112                                              comm, MPI_STATUS_IGNORE);
 113         if (OMPI_SUCCESS != err) {
 114             goto exit;
 115         }
 116     }
 117 
 118     /* bcast the message to all the local processes */
 119     err = comm->c_local_comm->c_coll->coll_bcast(rbuf, 1, ndtype,
 120                                                 0, comm->c_local_comm,
 121                                                 comm->c_local_comm->c_coll->coll_bcast_module);
 122   exit:
 123     if( NULL != ndtype ) {
 124         ompi_datatype_destroy(&ndtype);
 125     }
 126     if (NULL != ptmp_free) {
 127         free(ptmp_free);
 128     }
 129     if (NULL != displace) {
 130         free(displace);
 131     }
 132     if (NULL != count) {
 133         free(count);
 134     }
 135 
 136     return err;
 137 
 138 }

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