This source file includes following definitions.
- NBC_Ineighbor_allgather_args_compare
- nbc_neighbor_allgather_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "nbc_internal.h"
22
23
24 #undef NBC_CACHE_SCHEDULE
25
26 #ifdef NBC_CACHE_SCHEDULE
27
28 int NBC_Ineighbor_allgather_args_compare(NBC_Ineighbor_allgather_args *a, NBC_Ineighbor_allgather_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_allgather_init(const void *sbuf, int scount, MPI_Datatype stype, void *rbuf,
48 int rcount, MPI_Datatype rtype, struct ompi_communicator_t *comm,
49 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_allgather_args *args, *found, search;
64
65
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_allgather_args *) hb_tree_search ((hb_tree *) libnbc_module->NBC_Dict[NBC_NEIGHBOR_ALLGATHER],
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 for (int i = 0 ; i < indegree ; ++i) {
88 if (MPI_PROC_NULL != srcs[i]) {
89 res = NBC_Sched_recv ((char *) rbuf + i * rcount * rcvext, true, rcount, rtype, srcs[i], schedule, false);
90 if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
91 break;
92 }
93 }
94 }
95
96 free (srcs);
97
98 if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
99 OBJ_RELEASE(schedule);
100 free (dsts);
101 return res;
102 }
103
104 for (int i = 0 ; i < outdegree ; ++i) {
105 if (MPI_PROC_NULL != dsts[i]) {
106 res = NBC_Sched_send ((char *) sbuf, false, scount, stype, dsts[i], schedule, false);
107 if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
108 break;
109 }
110 }
111 }
112
113 free (dsts);
114
115 if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
116 OBJ_RELEASE(schedule);
117 return res;
118 }
119
120 res = NBC_Sched_commit (schedule);
121 if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
122 OBJ_RELEASE(schedule);
123 return res;
124 }
125
126 #ifdef NBC_CACHE_SCHEDULE
127
128 args = (NBC_Ineighbor_allgather_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_ALLGATHER], args, args, 0);
138 if (0 == res) {
139 OBJ_RETAIN(schedule);
140
141
142 if (++libnbc_module->NBC_Dict_size[NBC_NEIGHBOR_ALLGATHER] > NBC_SCHED_DICT_UPPER) {
143 NBC_SchedCache_dictwipe ((hb_tree *) libnbc_module->NBC_Dict[NBC_NEIGHBOR_ALLGATHER],
144 &libnbc_module->NBC_Dict_size[NBC_NEIGHBOR_ALLGATHER]);
145 }
146 } else {
147 NBC_Error("error in dict_insert() (%i)", res);
148 free (args);
149 }
150 } else {
151
152 schedule = found->schedule;
153 OBJ_RETAIN(schedule);
154 }
155 #endif
156
157 res = NBC_Schedule_request(schedule, comm, libnbc_module, persistent, request, NULL);
158 if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
159 OBJ_RELEASE(schedule);
160 return res;
161 }
162
163 return OMPI_SUCCESS;
164 }
165
166 int ompi_coll_libnbc_ineighbor_allgather(const void *sbuf, int scount, MPI_Datatype stype, void *rbuf,
167 int rcount, MPI_Datatype rtype, struct ompi_communicator_t *comm,
168 ompi_request_t ** request, struct mca_coll_base_module_2_3_0_t *module) {
169 int res = nbc_neighbor_allgather_init(sbuf, scount, stype, rbuf, rcount, rtype,
170 comm, request, module, false);
171 if (OPAL_LIKELY(OMPI_SUCCESS != res)) {
172 return res;
173 }
174 res = NBC_Start(*(ompi_coll_libnbc_request_t **)request);
175 if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
176 NBC_Return_handle (*(ompi_coll_libnbc_request_t **)request);
177 *request = &ompi_request_null.request;
178 return res;
179 }
180
181 return OMPI_SUCCESS;
182 }
183
184
185 int ompi_coll_libnbc_neighbor_allgather_init(const void *sbuf, int scount, MPI_Datatype stype, void *rbuf,
186 int rcount, MPI_Datatype rtype, struct ompi_communicator_t *comm,
187 MPI_Info info, ompi_request_t ** request, struct mca_coll_base_module_2_3_0_t *module) {
188 int res = nbc_neighbor_allgather_init(sbuf, scount, stype, rbuf, rcount, rtype,
189 comm, request, module, true);
190 if (OPAL_UNLIKELY(OMPI_SUCCESS != res)) {
191 return res;
192 }
193
194 return OMPI_SUCCESS;
195 }