2323
2424static inline int a2av_sched_linear (int rank , int p , NBC_Schedule * schedule ,
2525 const void * sendbuf , const int * sendcounts ,
26- const int * sdispls , MPI_Aint sndext , MPI_Datatype sendtype ,
26+ const int * sdispls , MPI_Aint sndext , MPI_Datatype sendtype , const size_t sdtype_size ,
2727 void * recvbuf , const int * recvcounts ,
28- const int * rdispls , MPI_Aint rcvext , MPI_Datatype recvtype );
28+ const int * rdispls , MPI_Aint rcvext , MPI_Datatype recvtype , const size_t rdtype_size );
2929
3030static inline int a2av_sched_pairwise (int rank , int p , NBC_Schedule * schedule ,
3131 const void * sendbuf , const int * sendcounts , const int * sdispls ,
32- MPI_Aint sndext , MPI_Datatype sendtype ,
32+ MPI_Aint sndext , MPI_Datatype sendtype , const size_t sdtype_size ,
3333 void * recvbuf , const int * recvcounts , const int * rdispls ,
34- MPI_Aint rcvext , MPI_Datatype recvtype );
34+ MPI_Aint rcvext , MPI_Datatype recvtype , const size_t rdtype_size );
3535
3636static inline int a2av_sched_inplace (int rank , int p , NBC_Schedule * schedule ,
3737 void * buf , const int * counts , const int * displs ,
38- MPI_Aint ext , MPI_Datatype type , ptrdiff_t gap );
38+ MPI_Aint ext , MPI_Datatype type , const size_t dtype_size , ptrdiff_t gap );
3939
4040/* an alltoallv schedule can not be cached easily because the contents
4141 * of the recvcounts array may change, so a comparison of the address
@@ -48,6 +48,7 @@ static int nbc_alltoallv_init(const void* sendbuf, const int *sendcounts, const
4848 mca_coll_base_module_t * module , bool persistent )
4949{
5050 int rank , p , res ;
51+ size_t sdtype_size , rdtype_size ;
5152 MPI_Aint sndext , rcvext ;
5253 NBC_Schedule * schedule ;
5354 char * rbuf , * sbuf , inplace ;
@@ -60,6 +61,7 @@ static int nbc_alltoallv_init(const void* sendbuf, const int *sendcounts, const
6061 rank = ompi_comm_rank (comm );
6162 p = ompi_comm_size (comm );
6263
64+ ompi_datatype_type_size (recvtype , & rdtype_size );
6365 res = ompi_datatype_type_extent (recvtype , & rcvext );
6466 if (MPI_SUCCESS != res ) {
6567 NBC_Error ("MPI Error in ompi_datatype_type_extent() (%i)" , res );
@@ -92,7 +94,9 @@ static int nbc_alltoallv_init(const void* sendbuf, const int *sendcounts, const
9294 sendcounts = recvcounts ;
9395 sdispls = rdispls ;
9496 sndext = rcvext ;
97+ sdtype_size = rdtype_size ;
9598 } else {
99+ ompi_datatype_type_size (sendtype , & sdtype_size );
96100 res = ompi_datatype_type_extent (sendtype , & sndext );
97101 if (MPI_SUCCESS != res ) {
98102 NBC_Error ("MPI Error in ompi_datatype_type_extent() (%i)" , res );
@@ -106,8 +110,7 @@ static int nbc_alltoallv_init(const void* sendbuf, const int *sendcounts, const
106110 return OMPI_ERR_OUT_OF_RESOURCE ;
107111 }
108112
109-
110- if (!inplace && sendcounts [rank ] != 0 ) {
113+ if (!inplace && 0 < sendcounts [rank ] && 0 < sdtype_size ) {
111114 rbuf = (char * ) recvbuf + rdispls [rank ] * rcvext ;
112115 sbuf = (char * ) sendbuf + sdispls [rank ] * sndext ;
113116 res = NBC_Sched_copy (sbuf , false, sendcounts [rank ], sendtype ,
@@ -119,12 +122,12 @@ static int nbc_alltoallv_init(const void* sendbuf, const int *sendcounts, const
119122 }
120123
121124 if (inplace ) {
122- res = a2av_sched_inplace (rank , p , schedule , recvbuf , recvcounts ,
123- rdispls , rcvext , recvtype , gap );
125+ res = a2av_sched_inplace (rank , p , schedule , recvbuf , recvcounts , rdispls , rcvext , recvtype ,
126+ rdtype_size , gap );
124127 } else {
125128 res = a2av_sched_linear (rank , p , schedule ,
126- sendbuf , sendcounts , sdispls , sndext , sendtype ,
127- recvbuf , recvcounts , rdispls , rcvext , recvtype );
129+ sendbuf , sendcounts , sdispls , sndext , sendtype , sdtype_size ,
130+ recvbuf , recvcounts , rdispls , rcvext , recvtype , rdtype_size );
128131 }
129132 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
130133 OBJ_RELEASE (schedule );
@@ -177,10 +180,13 @@ static int nbc_alltoallv_inter_init (const void* sendbuf, const int *sendcounts,
177180 mca_coll_base_module_t * module , bool persistent )
178181{
179182 int res , rsize ;
183+ size_t sdtype_size , rdtype_size ;
180184 MPI_Aint sndext , rcvext ;
181185 NBC_Schedule * schedule ;
182186 ompi_coll_libnbc_module_t * libnbc_module = (ompi_coll_libnbc_module_t * ) module ;
183187
188+ ompi_datatype_type_size (sendtype , & sdtype_size );
189+ ompi_datatype_type_size (recvtype , & rdtype_size );
184190
185191 res = ompi_datatype_type_extent (sendtype , & sndext );
186192 if (MPI_SUCCESS != res ) {
@@ -203,7 +209,7 @@ static int nbc_alltoallv_inter_init (const void* sendbuf, const int *sendcounts,
203209
204210 for (int i = 0 ; i < rsize ; i ++ ) {
205211 /* post all sends */
206- if (sendcounts [i ] != 0 ) {
212+ if (0 < sendcounts [i ] && 0 < sdtype_size ) {
207213 char * sbuf = (char * ) sendbuf + sdispls [i ] * sndext ;
208214 res = NBC_Sched_send (sbuf , false, sendcounts [i ], sendtype , i , schedule , false);
209215 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
@@ -212,7 +218,7 @@ static int nbc_alltoallv_inter_init (const void* sendbuf, const int *sendcounts,
212218 }
213219 }
214220 /* post all receives */
215- if (recvcounts [i ] != 0 ) {
221+ if (0 < recvcounts [i ] && 0 < rdtype_size ) {
216222 char * rbuf = (char * ) recvbuf + rdispls [i ] * rcvext ;
217223 res = NBC_Sched_recv (rbuf , false, recvcounts [i ], recvtype , i , schedule , false);
218224 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
@@ -261,9 +267,9 @@ int ompi_coll_libnbc_ialltoallv_inter (const void* sendbuf, const int *sendcount
261267__opal_attribute_unused__
262268static inline int a2av_sched_linear (int rank , int p , NBC_Schedule * schedule ,
263269 const void * sendbuf , const int * sendcounts , const int * sdispls ,
264- MPI_Aint sndext , MPI_Datatype sendtype ,
270+ MPI_Aint sndext , MPI_Datatype sendtype , const size_t sdtype_size ,
265271 void * recvbuf , const int * recvcounts , const int * rdispls ,
266- MPI_Aint rcvext , MPI_Datatype recvtype ) {
272+ MPI_Aint rcvext , MPI_Datatype recvtype , const size_t rdtype_size ) {
267273 int res ;
268274
269275 for (int i = 0 ; i < p ; ++ i ) {
@@ -272,7 +278,7 @@ static inline int a2av_sched_linear(int rank, int p, NBC_Schedule *schedule,
272278 }
273279
274280 /* post send */
275- if (sendcounts [i ] != 0 ) {
281+ if (0 < sendcounts [i ] && 0 < sdtype_size ) {
276282 char * sbuf = ((char * ) sendbuf ) + (sdispls [i ] * sndext );
277283 res = NBC_Sched_send (sbuf , false, sendcounts [i ], sendtype , i , schedule , false);
278284 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
@@ -281,7 +287,7 @@ static inline int a2av_sched_linear(int rank, int p, NBC_Schedule *schedule,
281287 }
282288
283289 /* post receive */
284- if (recvcounts [i ] != 0 ) {
290+ if (0 < recvcounts [i ] && 0 < rdtype_size ) {
285291 char * rbuf = ((char * ) recvbuf ) + (rdispls [i ] * rcvext );
286292 res = NBC_Sched_recv (rbuf , false, recvcounts [i ], recvtype , i , schedule , false);
287293 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
@@ -296,17 +302,17 @@ static inline int a2av_sched_linear(int rank, int p, NBC_Schedule *schedule,
296302__opal_attribute_unused__
297303static inline int a2av_sched_pairwise (int rank , int p , NBC_Schedule * schedule ,
298304 const void * sendbuf , const int * sendcounts , const int * sdispls ,
299- MPI_Aint sndext , MPI_Datatype sendtype ,
305+ MPI_Aint sndext , MPI_Datatype sendtype , const size_t sdtype_size ,
300306 void * recvbuf , const int * recvcounts , const int * rdispls ,
301- MPI_Aint rcvext , MPI_Datatype recvtype ) {
307+ MPI_Aint rcvext , MPI_Datatype recvtype , const size_t rdtype_size ) {
302308 int res ;
303309
304310 for (int i = 1 ; i < p ; ++ i ) {
305311 int sndpeer = (rank + i ) % p ;
306312 int rcvpeer = (rank + p - i ) %p ;
307313
308314 /* post send */
309- if (sendcounts [sndpeer ] != 0 ) {
315+ if (0 < sendcounts [sndpeer ] && 0 < sdtype_size ) {
310316 char * sbuf = ((char * ) sendbuf ) + (sdispls [sndpeer ] * sndext );
311317 res = NBC_Sched_send (sbuf , false, sendcounts [sndpeer ], sendtype , sndpeer , schedule , false);
312318 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
@@ -315,7 +321,7 @@ static inline int a2av_sched_pairwise(int rank, int p, NBC_Schedule *schedule,
315321 }
316322
317323 /* post receive */
318- if (recvcounts [rcvpeer ] != 0 ) {
324+ if (0 < recvcounts [rcvpeer ] && 0 < rdtype_size ) {
319325 char * rbuf = ((char * ) recvbuf ) + (rdispls [rcvpeer ] * rcvext );
320326 res = NBC_Sched_recv (rbuf , false, recvcounts [rcvpeer ], recvtype , rcvpeer , schedule , true);
321327 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
@@ -329,7 +335,7 @@ static inline int a2av_sched_pairwise(int rank, int p, NBC_Schedule *schedule,
329335
330336static inline int a2av_sched_inplace (int rank , int p , NBC_Schedule * schedule ,
331337 void * buf , const int * counts , const int * displs ,
332- MPI_Aint ext , MPI_Datatype type , ptrdiff_t gap ) {
338+ MPI_Aint ext , MPI_Datatype type , const size_t dtype_size , ptrdiff_t gap ) {
333339 int res ;
334340
335341 for (int i = 1 ; i < (p + 1 )/2 ; i ++ ) {
@@ -338,34 +344,39 @@ static inline int a2av_sched_inplace(int rank, int p, NBC_Schedule *schedule,
338344 char * sbuf = (char * ) buf + displs [speer ] * ext ;
339345 char * rbuf = (char * ) buf + displs [rpeer ] * ext ;
340346
341- if (0 != counts [rpeer ]) {
347+ if (0 == dtype_size ) {
348+ /* Nothing to exchange */
349+ return OMPI_SUCCESS ;
350+ }
351+
352+ if (0 < counts [rpeer ]) {
342353 res = NBC_Sched_copy (rbuf , false, counts [rpeer ], type ,
343354 (void * )(- gap ), true, counts [rpeer ], type ,
344355 schedule , true);
345356 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
346357 return res ;
347358 }
348359 }
349- if (0 != counts [speer ]) {
360+ if (0 < counts [speer ]) {
350361 res = NBC_Sched_send (sbuf , false , counts [speer ], type , speer , schedule , false);
351362 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
352363 return res ;
353364 }
354365 }
355- if (0 != counts [rpeer ]) {
366+ if (0 < counts [rpeer ]) {
356367 res = NBC_Sched_recv (rbuf , false , counts [rpeer ], type , rpeer , schedule , true);
357368 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
358369 return res ;
359370 }
360371 }
361372
362- if (0 != counts [rpeer ]) {
373+ if (0 < counts [rpeer ]) {
363374 res = NBC_Sched_send ((void * )(- gap ), true, counts [rpeer ], type , rpeer , schedule , false);
364375 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
365376 return res ;
366377 }
367378 }
368- if (0 != counts [speer ]) {
379+ if (0 < counts [speer ]) {
369380 res = NBC_Sched_recv (sbuf , false, counts [speer ], type , speer , schedule , true);
370381 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
371382 return res ;
@@ -374,15 +385,17 @@ static inline int a2av_sched_inplace(int rank, int p, NBC_Schedule *schedule,
374385 }
375386 if (0 == (p %2 )) {
376387 int peer = (rank + p /2 ) % p ;
377-
378388 char * tbuf = (char * ) buf + displs [peer ] * ext ;
379- res = NBC_Sched_copy (tbuf , false, counts [peer ], type ,
380- (void * )(- gap ), true, counts [peer ], type ,
381- schedule , true);
382- if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
383- return res ;
389+
390+ if (0 < counts [peer ]) {
391+ res = NBC_Sched_copy (tbuf , false, counts [peer ], type , (void * ) (- gap ), true, counts [peer ],
392+ type , schedule , true);
393+ if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
394+ return res ;
395+ }
384396 }
385- if (0 != counts [peer ]) {
397+
398+ if (0 < counts [peer ]) {
386399 res = NBC_Sched_send ((void * )(- gap ), true , counts [peer ], type , peer , schedule , false);
387400 if (OPAL_UNLIKELY (OMPI_SUCCESS != res )) {
388401 return res ;
0 commit comments