root/ompi/mca/coll/libnbc/nbc_ineighbor_allgatherv.c

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

DEFINITIONS

This source file includes following definitions.
  1. NBC_Ineighbor_allgatherv_args_compare
  2. nbc_neighbor_allgatherv_init
  3. ompi_coll_libnbc_ineighbor_allgatherv
  4. ompi_coll_libnbc_neighbor_allgatherv_init

   1 /* -*- Mode: C; c-basic-offset:2 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2006      The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2006      The Technical University of Chemnitz. All
   7  *                         rights reserved.
   8  * Copyright (c) 2014-2018 Research Organization for Information Science
   9  *                         and Technology (RIST).  All rights reserved.
  10  * Copyright (c) 2015      Los Alamos National Security, LLC.  All rights
  11  *                         reserved.
  12  * Copyright (c) 2017      IBM Corporation.  All rights reserved.
  13  * Copyright (c) 2018      FUJITSU LIMITED.  All rights reserved.
  14  * $COPYRIGHT$
  15  *
  16  * Additional copyrights may follow
  17  *
  18  * Author(s): Torsten Hoefler <htor@cs.indiana.edu>
  19  *
  20  */
  21 #include "nbc_internal.h"
  22 
  23 /* cannot cache schedules because one cannot check locally if the pattern is the same!! */
  24 #undef NBC_CACHE_SCHEDULE
  25 
  26 #ifdef NBC_CACHE_SCHEDULE
  27 /* tree comparison function for schedule cache */
  28 int NBC_Ineighbor_allgatherv_args_compare(NBC_Ineighbor_allgatherv_args *a, NBC_Ineighbor_allgatherv_args *b, void *param) {
  29   if ((a->sbuf == b->sbuf) &&
  30       (a->scount == b->scount) &&
  31       (a->stype == b->stype) &&
  32       (a->rbuf == b->rbuf) &&
  33       (a->rcount == b->rcount) &&
  34       (a->rtype == b->rtype) ) {
  35     return 0;
  36   }
  37 
  38   if( a->sbuf < b->sbuf ) {
  39     return -1;
  40   }
  41 
  42   return 1;
  43 }
  44 #endif
  45 
  46 
  47 static int nbc_neighbor_allgatherv_init(const void *sbuf, int scount, MPI_Datatype stype, void *rbuf,
  48                                         const int *rcounts, const int *displs, MPI_Datatype rtype,
  49                                         struct ompi_communicator_t *comm, ompi_request_t ** request,
  50                                         struct mca_coll_base_module_2_3_0_t *module, bool persistent) {
  51   int res, indegree, outdegree, *srcs, *dsts;
  52   MPI_Aint rcvext;
  53   ompi_coll_libnbc_module_t *libnbc_module = (ompi_coll_libnbc_module_t*) module;
  54   NBC_Schedule *schedule;
  55 
  56   res = ompi_datatype_type_extent(rtype, &rcvext);
  57   if (MPI_SUCCESS != res) {
  58     NBC_Error("MPI Error in ompi_datatype_type_extent() (%i)", res);
  59     return res;
  60   }
  61 
  62 #ifdef NBC_CACHE_SCHEDULE
  63   NBC_Ineighbor_allgatherv_args *args, *found, search;
  64 
  65   /* search schedule in communicator specific tree */
  66   search.sbuf = sbuf;
  67   search.scount = scount;
  68   search.stype = stype;
  69   search.rbuf = rbuf;
  70   search.rcount = rcount;
  71   search.rtype = rtype;
  72   found = (NBC_Ineighbor_allgatherv_args *) hb_tree_search ((hb_tree *) libnbc_module->NBC_Dict[NBC_NEIGHBOR_ALLGATHERV],
  73                                                             &search);
  74   if (NULL == found) {
  75 #endif
  76     schedule = OBJ_NEW(NBC_Schedule);
  77     if (OPAL_UNLIKELY(NULL == schedule)) {
  78       return OMPI_ERR_OUT_OF_RESOURCE;
  79     }
  80 
  81     res = NBC_Comm_neighbors(comm, &srcs, &indegree, &dsts, &outdegree);
  82     if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
  83       OBJ_RELEASE(schedule);
  84       return res;
  85     }
  86 
  87     /* simply loop over neighbors and post send/recv operations */
  88     for (int i = 0 ; i < indegree ; ++i) {
  89       if (srcs[i] != MPI_PROC_NULL) {
  90         res = NBC_Sched_recv ((char *) rbuf + displs[i] * rcvext, false, rcounts[i], rtype, srcs[i], schedule, false);
  91         if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
  92           break;
  93         }
  94       }
  95     }
  96 
  97     free (srcs);
  98 
  99     if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
 100       free (dsts);
 101       OBJ_RELEASE(schedule);
 102       return res;
 103     }
 104 
 105     for (int i = 0 ; i < outdegree ; ++i) {
 106       if (dsts[i] != MPI_PROC_NULL) {
 107         res = NBC_Sched_send ((char *) sbuf, false, scount, stype, dsts[i], schedule, false);
 108         if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
 109           break;
 110         }
 111       }
 112     }
 113 
 114     free (dsts);
 115 
 116     if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
 117       OBJ_RELEASE(schedule);
 118       return res;
 119     }
 120 
 121     res = NBC_Sched_commit (schedule);
 122     if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
 123       OBJ_RELEASE(schedule);
 124       return res;
 125     }
 126 #ifdef NBC_CACHE_SCHEDULE
 127     /* save schedule to tree */
 128     args = (NBC_Ineighbor_allgatherv_args *) malloc (sizeof (args));
 129     if (NULL != args) {
 130       args->sbuf = sbuf;
 131       args->scount = scount;
 132       args->stype = stype;
 133       args->rbuf = rbuf;
 134       args->rcount = rcount;
 135       args->rtype = rtype;
 136       args->schedule = schedule;
 137       res = hb_tree_insert ((hb_tree *) libnbc_module->NBC_Dict[NBC_NEIGHBOR_ALLGATHERV], args, args, 0);
 138       if (0 == res) {
 139         OBJ_RETAIN(schedule);
 140 
 141         /* increase number of elements for A2A */
 142         if(++libnbc_module->NBC_Dict_size[NBC_NEIGHBOR_ALLGATHERV] > NBC_SCHED_DICT_UPPER) {
 143           NBC_SchedCache_dictwipe ((hb_tree *) libnbc_module->NBC_Dict[NBC_NEIGHBOR_ALLGATHERV],
 144                                    &libnbc_module->NBC_Dict_size[NBC_NEIGHBOR_ALLGATHERV]);
 145         }
 146       } else {
 147         NBC_Error("error in dict_insert() (%i)", res);
 148         free (args);
 149       }
 150     }
 151   } else {
 152     /* found schedule */
 153     schedule = found->schedule;
 154     OBJ_RETAIN(schedule);
 155   }
 156 #endif
 157 
 158   res = NBC_Schedule_request(schedule, comm, libnbc_module, persistent, request, NULL);
 159   if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
 160     OBJ_RELEASE(schedule);
 161     return res;
 162   }
 163 
 164   return OMPI_SUCCESS;
 165 }
 166 
 167 int ompi_coll_libnbc_ineighbor_allgatherv(const void *sbuf, int scount, MPI_Datatype stype, void *rbuf,
 168                                           const int *rcounts, const int *displs, MPI_Datatype rtype,
 169                                           struct ompi_communicator_t *comm, ompi_request_t ** request,
 170                                           struct mca_coll_base_module_2_3_0_t *module) {
 171     int res = nbc_neighbor_allgatherv_init(sbuf, scount, stype, rbuf, rcounts, displs, rtype,
 172                                            comm, request, module, false);
 173     if (OPAL_LIKELY(OMPI_SUCCESS != res)) {
 174         return res;
 175     }
 176     res = NBC_Start(*(ompi_coll_libnbc_request_t **)request);
 177     if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
 178         NBC_Return_handle (*(ompi_coll_libnbc_request_t **)request);
 179         *request = &ompi_request_null.request;
 180         return res;
 181     }
 182 
 183     return OMPI_SUCCESS;
 184 }
 185 
 186 int ompi_coll_libnbc_neighbor_allgatherv_init(const void *sbuf, int scount, MPI_Datatype stype, void *rbuf,
 187                                               const int *rcounts, const int *displs, MPI_Datatype rtype,
 188                                               struct ompi_communicator_t *comm, MPI_Info info, ompi_request_t ** request,
 189                                               struct mca_coll_base_module_2_3_0_t *module) {
 190     int res = nbc_neighbor_allgatherv_init(sbuf, scount, stype, rbuf, rcounts, displs, rtype,
 191                                            comm, request, module, true);
 192     if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
 193         return res;
 194     }
 195 
 196     return OMPI_SUCCESS;
 197 }

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