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

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

DEFINITIONS

This source file includes following definitions.
  1. NBC_Comm_neighbors_count
  2. NBC_Comm_neighbors

   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) 2015      Los Alamos National Security, LLC.  All rights
   9  *                         reserved.
  10  *
  11  * Author(s): Torsten Hoefler <htor@cs.indiana.edu>
  12  *
  13  */
  14 
  15 #include "nbc_internal.h"
  16 #include "ompi/mca/topo/base/base.h"
  17 
  18 int NBC_Comm_neighbors_count (ompi_communicator_t *comm, int *indegree, int *outdegree) {
  19   if (OMPI_COMM_IS_CART(comm)) {
  20     /* cartesian */
  21     /* outdegree is always 2*ndims because we need to iterate over empty buffers for MPI_PROC_NULL */
  22     *outdegree = *indegree = 2 * comm->c_topo->mtc.cart->ndims;
  23   } else if (OMPI_COMM_IS_GRAPH(comm)) {
  24     /* graph */
  25     int rank, nneighbors;
  26 
  27     rank = ompi_comm_rank (comm);
  28     mca_topo_base_graph_neighbors_count (comm, rank, &nneighbors);
  29 
  30     *outdegree = *indegree = nneighbors;
  31   } else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
  32     /* graph */
  33     *indegree = comm->c_topo->mtc.dist_graph->indegree;
  34     *outdegree = comm->c_topo->mtc.dist_graph->outdegree;
  35   } else {
  36     return OMPI_ERR_BAD_PARAM;
  37   }
  38 
  39   return OMPI_SUCCESS;
  40 }
  41 
  42 int NBC_Comm_neighbors (ompi_communicator_t *comm, int **sources, int *source_count, int **destinations, int *dest_count) {
  43   int res, indeg, outdeg;
  44 
  45   *sources = *destinations = NULL;
  46 
  47   res = NBC_Comm_neighbors_count(comm, &indeg, &outdeg);
  48   if (OMPI_SUCCESS != res) {
  49     return res;
  50   }
  51 
  52   *source_count = indeg;
  53   *dest_count = outdeg;
  54 
  55   if (indeg) {
  56     *sources = malloc (sizeof (int) * indeg);
  57     if (OPAL_UNLIKELY(NULL == *sources)) {
  58       return OMPI_ERR_OUT_OF_RESOURCE;
  59     }
  60   } else {
  61     *sources = NULL;
  62   }
  63 
  64   if (outdeg) {
  65     *destinations = malloc (sizeof (int) * outdeg);
  66     if (OPAL_UNLIKELY(NULL == *destinations)) {
  67       free (*sources);
  68       *sources = NULL;
  69       return OMPI_ERR_OUT_OF_RESOURCE;
  70     }
  71   } else {
  72     *destinations = NULL;
  73   }
  74 
  75   /* silence clang static analyzer warning about NULL-dereference */
  76   if (0 == indeg && 0 == outdeg) {
  77     return OMPI_SUCCESS;
  78   }
  79 
  80   if (OMPI_COMM_IS_CART(comm)) {
  81     /* cartesian */
  82     int rpeer, speer;
  83 
  84     /* silence clang static analyzer warning */
  85     assert (indeg == outdeg);
  86 
  87     for (int dim = 0, i = 0 ; dim < comm->c_topo->mtc.cart->ndims ; ++dim) {
  88       mca_topo_base_cart_shift (comm, dim, 1, &rpeer, &speer);
  89       sources[0][i] = destinations[0][i] = rpeer; i++;
  90       sources[0][i] = destinations[0][i] = speer; i++;
  91     }
  92   } else if (OMPI_COMM_IS_GRAPH(comm)) {
  93     /* graph */
  94     mca_topo_base_graph_neighbors (comm, ompi_comm_rank (comm), indeg, sources[0]);
  95     memcpy (destinations[0], sources[0], indeg * sizeof (int));
  96   } else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
  97     /* dist graph */
  98     mca_topo_base_dist_graph_neighbors (comm, indeg, sources[0], MPI_UNWEIGHTED, outdeg, destinations[0],
  99                                          MPI_UNWEIGHTED);
 100   }
 101 
 102   return OMPI_SUCCESS;
 103 }

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