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; }
ompi_cxx_communicator_type_t ompi_cxx_comm_get_type (MPI_Comm comm) { if (OMPI_COMM_IS_GRAPH(comm)) { return OMPI_CXX_COMM_TYPE_GRAPH; } else if (OMPI_COMM_IS_CART(comm)) { return OMPI_CXX_COMM_TYPE_CART; } else if (OMPI_COMM_IS_INTRA(comm)) { return OMPI_CXX_COMM_TYPE_INTRACOMM; } else if (OMPI_COMM_IS_INTER(comm)) { return OMPI_CXX_COMM_TYPE_INTERCOMM; } return OMPI_CXX_COMM_TYPE_UNKNOWN; }
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; }
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; }
int MPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int *index, int *edges) { int err; mca_topo_base_module_graph_get_fn_t func; /* check the arguments */ if (MPI_PARAM_CHECK) { if (MPI_COMM_NULL == comm) { return OMPI_ERRHANDLER_INVOKE (MPI_COMM_WORLD, MPI_ERR_COMM, FUNC_NAME); } if (OMPI_COMM_IS_INTER(comm)) { return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_COMM, FUNC_NAME); } if (!OMPI_COMM_IS_GRAPH(comm)) { return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_TOPOLOGY, FUNC_NAME); } if (0 > maxindex || 0 > maxedges || NULL == index || NULL == edges) { return OMPI_ERRHANDLER_INVOKE (comm, MPI_ERR_ARG, FUNC_NAME); } } /* get the function pointer to do the right thing */ func = comm->c_topo->topo_graph_get; /* call the function */ if ( MPI_SUCCESS != (err = func(comm, maxindex, maxedges, index, edges))) { return OMPI_ERRHANDLER_INVOKE(comm, err, FUNC_NAME); } /* All done */ return MPI_SUCCESS; }
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; }