Ejemplo n.º 1
0
int ompi_comm_neighbors_count(MPI_Comm comm, int *indegree, int *outdegree, int *weighted) {
    int res;

    if (OMPI_COMM_IS_CART(comm)) { 
        int ndims;
        res = MPI_Cartdim_get(comm, &ndims)  ;
        if (MPI_SUCCESS != res) {
            return res;
        }
        /* outdegree is always 2*ndims because we need to iterate over empty buffers for MPI_PROC_NULL */
        *outdegree = *indegree = 2*ndims;
        *weighted = 0;
    } else if (OMPI_COMM_IS_GRAPH(comm)) {
        int rank, nneighbors;
        rank = ompi_comm_rank ((ompi_communicator_t *) comm);
        res = MPI_Graph_neighbors_count(comm, rank, &nneighbors);
        if (MPI_SUCCESS != res) {
            return res;
        }
        *outdegree = *indegree = nneighbors;
        *weighted = 0;
    } else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
        res = MPI_Dist_graph_neighbors_count(comm, indegree, outdegree, weighted);
    } else {
        return MPI_ERR_ARG;
    }

    return MPI_SUCCESS;
}
int mca_topo_base_dist_graph_neighbors(ompi_communicator_t *comm, 
                                       int maxindegree,
                                       int sources[], int sourceweights[],
                                       int maxoutdegree, int destinations[],
                                       int destweights[])
{
    mca_topo_base_comm_dist_graph_2_2_0_t *dg = comm->c_topo->mtc.dist_graph;
    int i;

    if (!OMPI_COMM_IS_DIST_GRAPH(comm)) {
        return OMPI_ERR_NOT_FOUND;
    } else if (maxindegree < dg->indegree || maxoutdegree < dg->outdegree) {
        return OMPI_ERR_BAD_PARAM;
    }

    for (i = 0; i < dg->indegree; ++i) {
        sources[i] = dg->in[i];
        if (NULL != dg->inw) {
            sourceweights[i] = dg->inw[i];
        }
    }
    for (i = 0; i < dg->outdegree; ++i) {
        destinations[i] = dg->out[i];
        if (NULL != dg->outw) {
            destweights[i] = dg->outw[i];
        }
    }

    return MPI_SUCCESS;
}
int mca_topo_base_dist_graph_neighbors_count(ompi_communicator_t *comm, 
                                             int *inneighbors,
                                             int *outneighbors, int *weighted)
{
    mca_topo_base_comm_dist_graph_2_1_0_t* dist_graph = comm->c_topo->mtc.dist_graph;

    if (!OMPI_COMM_IS_DIST_GRAPH(comm)) {
        return OMPI_ERR_NOT_FOUND;
    }

    *inneighbors = dist_graph->indegree;
    *outneighbors = dist_graph->outdegree;
    *weighted = (int)dist_graph->weighted;

    return MPI_SUCCESS;
}
Ejemplo n.º 4
0
int ompi_comm_neighbors(MPI_Comm comm, int maxindegree, int sources[], int sourceweights[], int maxoutdegree, int destinations[], int destweights[]) {
    int res;
    int index = 0;

    int indeg, outdeg, wgtd;
    res = ompi_comm_neighbors_count(comm, &indeg, &outdeg, &wgtd);
    if (MPI_SUCCESS != res) {
        return res;
    }
    if(indeg > maxindegree && outdeg > maxoutdegree) return MPI_ERR_TRUNCATE; /* we want to return *all* neighbors */

    if (OMPI_COMM_IS_CART(comm)) { 
        int ndims, i, rpeer, speer;
        res = MPI_Cartdim_get(comm, &ndims);
        if (MPI_SUCCESS != res) {
            return res;
        }

        for(i = 0; i<ndims; i++) {
          res = MPI_Cart_shift(comm, i, 1, &rpeer, &speer);
          if (MPI_SUCCESS != res) {
              return res;
          }
          sources[index] = destinations[index] = rpeer; index++;
          sources[index] = destinations[index] = speer; index++;
        }
    } else if (OMPI_COMM_IS_GRAPH(comm)) {
        int rank = ompi_comm_rank ((ompi_communicator_t *) comm);
        res = MPI_Graph_neighbors(comm, rank, maxindegree, sources);
        if (MPI_SUCCESS != res) {
            return res;
        }
        for(int i=0; i<maxindegree; i++) destinations[i] = sources[i];
    } else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
        res = MPI_Dist_graph_neighbors(comm, maxindegree, sources, sourceweights, maxoutdegree, destinations, destweights);
        if (MPI_SUCCESS != res) {
            return res;
        }
    } else {
        return MPI_ERR_ARG;
    }

    return MPI_SUCCESS;
}
int mca_coll_basic_neighbor_alltoallv(void *sbuf, int scounts[], int sdisps[],
                                      struct ompi_datatype_t *sdtype, void *rbuf, int rcounts[],
                                      int rdisps[], struct ompi_datatype_t *rdtype,
                                      struct ompi_communicator_t *comm, mca_coll_base_module_t *module)
{
    if (OMPI_COMM_IS_INTER(comm)) {
        return OMPI_ERR_NOT_SUPPORTED;
    }

    if (OMPI_COMM_IS_CART(comm)) {
        return mca_coll_basic_neighbor_alltoallv_cart (sbuf, scounts, sdisps, sdtype, rbuf,
                                                       rcounts, rdisps, rdtype, comm, module);
    } else if (OMPI_COMM_IS_GRAPH(comm)) {
        return mca_coll_basic_neighbor_alltoallv_graph (sbuf, scounts, sdisps, sdtype, rbuf,
                                                        rcounts, rdisps, rdtype, comm, module);
    } else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
        return mca_coll_basic_neighbor_alltoallv_dist_graph (sbuf, scounts, sdisps, sdtype, rbuf,
                                                             rcounts, rdisps, rdtype, comm, module);
    }

    return OMPI_ERR_NOT_SUPPORTED;
}
Ejemplo n.º 6
0
int NBC_Comm_neighbors_count (ompi_communicator_t *comm, int *indegree, int *outdegree) {
  if (OMPI_COMM_IS_CART(comm)) {
    /* cartesian */
    /* outdegree is always 2*ndims because we need to iterate over empty buffers for MPI_PROC_NULL */
    *outdegree = *indegree = 2 * comm->c_topo->mtc.cart->ndims;
  } else if (OMPI_COMM_IS_GRAPH(comm)) {
    /* graph */
    int rank, nneighbors;

    rank = ompi_comm_rank (comm);
    mca_topo_base_graph_neighbors_count (comm, rank, &nneighbors);

    *outdegree = *indegree = nneighbors;
  } else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
    /* graph */
    *indegree = comm->c_topo->mtc.dist_graph->indegree;
    *outdegree = comm->c_topo->mtc.dist_graph->outdegree;
  } else {
    return OMPI_ERR_BAD_PARAM;
  }

  return OMPI_SUCCESS;
}
Ejemplo n.º 7
0
int NBC_Comm_neighbors (ompi_communicator_t *comm, int **sources, int *source_count, int **destinations, int *dest_count) {
  int res, indeg, outdeg;

  *sources = *destinations = NULL;

  res = NBC_Comm_neighbors_count(comm, &indeg, &outdeg);
  if (OMPI_SUCCESS != res) {
    return res;
  }

  *source_count = indeg;
  *dest_count = outdeg;

  if (indeg) {
    *sources = malloc (sizeof (int) * indeg);
    if (OPAL_UNLIKELY(NULL == *sources)) {
      return OMPI_ERR_OUT_OF_RESOURCE;
    }
  } else {
    *sources = NULL;
  }

  if (outdeg) {
    *destinations = malloc (sizeof (int) * outdeg);
    if (OPAL_UNLIKELY(NULL == *destinations)) {
      free (*sources);
      *sources = NULL;
      return OMPI_ERR_OUT_OF_RESOURCE;
    }
  } else {
    *destinations = NULL;
  }

  /* silence clang static analyzer warning about NULL-dereference */
  if (0 == indeg && 0 == outdeg) {
    return OMPI_SUCCESS;
  }

  if (OMPI_COMM_IS_CART(comm)) {
    /* cartesian */
    int rpeer, speer;

    /* silence clang static analyzer warning */
    assert (indeg == outdeg);

    for (int dim = 0, i = 0 ; dim < comm->c_topo->mtc.cart->ndims ; ++dim) {
      mca_topo_base_cart_shift (comm, dim, 1, &rpeer, &speer);
      sources[0][i] = destinations[0][i] = rpeer; i++;
      sources[0][i] = destinations[0][i] = speer; i++;
    }
  } else if (OMPI_COMM_IS_GRAPH(comm)) {
    /* graph */
    mca_topo_base_graph_neighbors (comm, ompi_comm_rank (comm), indeg, sources[0]);
    memcpy (destinations[0], sources[0], indeg * sizeof (int));
  } else if (OMPI_COMM_IS_DIST_GRAPH(comm)) {
    /* dist graph */
    mca_topo_base_dist_graph_neighbors (comm, indeg, sources[0], MPI_UNWEIGHTED, outdeg, destinations[0],
                                         MPI_UNWEIGHTED);
  }

  return OMPI_SUCCESS;
}