This source file includes following definitions.
- NBC_Comm_neighbors_count
- NBC_Comm_neighbors
1
2
3
4
5
6
7
8
9
10
11
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
21
22 *outdegree = *indegree = 2 * comm->c_topo->mtc.cart->ndims;
23 } else if (OMPI_COMM_IS_GRAPH(comm)) {
24
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
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
76 if (0 == indeg && 0 == outdeg) {
77 return OMPI_SUCCESS;
78 }
79
80 if (OMPI_COMM_IS_CART(comm)) {
81
82 int rpeer, speer;
83
84
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
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
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 }