Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8a9e54e1f97ccf0f8ff33b4dcb83f585cc4674ae
[simgrid.git] / src / smpi / colls / smpi_nbc_impl.cpp
1 /* Asynchronous parts of the basic collective algorithms, meant to be used both for the naive default implementation, but also for non blocking collectives */
2
3 /* Copyright (c) 2009-2019. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "colls_private.hpp"
9 #include "src/smpi/include/smpi_actor.hpp"
10
11 namespace simgrid{
12 namespace smpi{
13
14
15 int Colls::ibarrier(MPI_Comm comm, MPI_Request* request)
16 {
17   int i;
18   int size = comm->size();
19   int rank = comm->rank();
20   MPI_Request* requests;
21   (*request) = new Request( nullptr, 0, MPI_BYTE,
22                          rank,rank, COLL_TAG_BARRIER, comm, MPI_REQ_PERSISTENT);
23   if (rank > 0) {
24     requests = new MPI_Request[2];
25     requests[0] = Request::isend (nullptr, 0, MPI_BYTE, 0,
26                              COLL_TAG_BARRIER,
27                              comm);
28     requests[1] = Request::irecv (nullptr, 0, MPI_BYTE, 0,
29                              COLL_TAG_BARRIER,
30                              comm);
31     (*request)->set_nbc_requests(requests, 2);
32   }
33   else {
34     requests = new MPI_Request[(size-1)*2];
35     for (i = 1; i < 2*size-1; i+=2) {
36         requests[i-1] = Request::irecv(nullptr, 0, MPI_BYTE, MPI_ANY_SOURCE,
37                                  COLL_TAG_BARRIER, comm
38                                  );
39         requests[i] = Request::isend(nullptr, 0, MPI_BYTE, (i+1)/2,
40                                  COLL_TAG_BARRIER,
41                                  comm
42                                  );
43     }
44     (*request)->set_nbc_requests(requests, 2*(size-1));
45   }
46   return MPI_SUCCESS;
47 }
48
49 int Colls::ibcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm, MPI_Request* request)
50 {
51   int i;
52   int size = comm->size();
53   int rank = comm->rank();
54   MPI_Request* requests;
55   (*request) = new Request( nullptr, 0, MPI_BYTE,
56                          rank,rank, COLL_TAG_BCAST, comm, MPI_REQ_PERSISTENT);
57   if (rank != root) {
58     requests = new MPI_Request[1];
59     requests[0] = Request::irecv (buf, count, datatype, root,
60                              COLL_TAG_BCAST,
61                              comm);
62     (*request)->set_nbc_requests(requests, 1);
63   }
64   else {
65     requests = new MPI_Request[size-1];
66     int n = 0;
67     for (i = 0; i < size; i++) {
68       if(i!=root){
69         requests[n] = Request::isend(buf, count, datatype, i,
70                                  COLL_TAG_BCAST,
71                                  comm
72                                  );
73         n++;
74       }
75     }
76     (*request)->set_nbc_requests(requests, size-1);
77   }
78   return MPI_SUCCESS;
79 }
80
81 int Colls::iallgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
82                         void *recvbuf,int recvcount, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request)
83 {
84
85   const int system_tag = COLL_TAG_ALLGATHER;
86   MPI_Aint lb = 0;
87   MPI_Aint recvext = 0;
88   MPI_Request *requests;
89
90   int rank = comm->rank();
91   int size = comm->size();
92   (*request) = new Request( nullptr, 0, MPI_BYTE,
93                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
94   // FIXME: check for errors
95   recvtype->extent(&lb, &recvext);
96   // Local copy from self
97   Datatype::copy(sendbuf, sendcount, sendtype, static_cast<char *>(recvbuf) + rank * recvcount * recvext, recvcount,
98                      recvtype);
99   // Send/Recv buffers to/from others;
100   requests = new MPI_Request[2 * (size - 1)];
101   int index = 0;
102   for (int other = 0; other < size; other++) {
103     if(other != rank) {
104       requests[index] = Request::isend_init(sendbuf, sendcount, sendtype, other, system_tag,comm);
105       index++;
106       requests[index] = Request::irecv_init(static_cast<char *>(recvbuf) + other * recvcount * recvext, recvcount, recvtype,
107                                         other, system_tag, comm);
108       index++;
109     }
110   }
111   Request::startall(2 * (size - 1), requests);
112   (*request)->set_nbc_requests(requests, 2 * (size - 1));
113   return MPI_SUCCESS;
114 }
115
116 int Colls::iscatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
117                       void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request* request)
118 {
119   const int system_tag = COLL_TAG_SCATTER;
120   MPI_Aint lb = 0;
121   MPI_Aint sendext = 0;
122   MPI_Request *requests;
123
124   int rank = comm->rank();
125   int size = comm->size();
126   (*request) = new Request( nullptr, 0, MPI_BYTE,
127                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
128   if(rank != root) {
129     requests = new MPI_Request[1];
130     // Recv buffer from root
131     requests[0] = Request::irecv(recvbuf, recvcount, recvtype, root, system_tag, comm);
132     (*request)->set_nbc_requests(requests, 1);
133   } else {
134     sendtype->extent(&lb, &sendext);
135     // Local copy from root
136     if(recvbuf!=MPI_IN_PLACE){
137         Datatype::copy(static_cast<char *>(sendbuf) + root * sendcount * sendext,
138                            sendcount, sendtype, recvbuf, recvcount, recvtype);
139     }
140     // Send buffers to receivers
141     requests = new MPI_Request[size - 1];
142     int index = 0;
143     for(int dst = 0; dst < size; dst++) {
144       if(dst != root) {
145         requests[index] = Request::isend_init(static_cast<char *>(sendbuf) + dst * sendcount * sendext, sendcount, sendtype,
146                                           dst, system_tag, comm);
147         index++;
148       }
149     }
150     // Wait for completion of isend's.
151     Request::startall(size - 1, requests);
152     (*request)->set_nbc_requests(requests, size - 1);
153   }
154   return MPI_SUCCESS;
155 }
156
157 int Colls::iallgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf,
158                          int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request)
159 {
160   const int system_tag = COLL_TAG_ALLGATHERV;
161   MPI_Aint lb = 0;
162   MPI_Aint recvext = 0;
163
164   int rank = comm->rank();
165   int size = comm->size();
166   (*request) = new Request( nullptr, 0, MPI_BYTE,
167                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
168   recvtype->extent(&lb, &recvext);
169   // Local copy from self
170   Datatype::copy(sendbuf, sendcount, sendtype,
171                      static_cast<char *>(recvbuf) + displs[rank] * recvext,recvcounts[rank], recvtype);
172   // Send buffers to others;
173   MPI_Request *requests = new MPI_Request[2 * (size - 1)];
174   int index = 0;
175   for (int other = 0; other < size; other++) {
176     if(other != rank) {
177       requests[index] =
178         Request::isend_init(sendbuf, sendcount, sendtype, other, system_tag, comm);
179       index++;
180       requests[index] = Request::irecv_init(static_cast<char *>(recvbuf) + displs[other] * recvext, recvcounts[other],
181                           recvtype, other, system_tag, comm);
182       index++;
183     }
184   }
185   // Wait for completion of all comms.
186   Request::startall(2 * (size - 1), requests);
187   (*request)->set_nbc_requests(requests, 2 * (size - 1));
188   return MPI_SUCCESS;
189 }
190
191 int Colls::ialltoall( void *sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request* request){
192 int system_tag = COLL_TAG_ALLTOALL;
193   int i;
194   int count;
195   MPI_Aint lb = 0, sendext = 0, recvext = 0;
196   MPI_Request *requests;
197
198   /* Initialize. */
199   int rank = comm->rank();
200   int size = comm->size();
201   (*request) = new Request( nullptr, 0, MPI_BYTE,
202                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
203   sendtype->extent(&lb, &sendext);
204   recvtype->extent(&lb, &recvext);
205   /* simple optimization */
206   int err = Datatype::copy(static_cast<char *>(sendbuf) + rank * sendcount * sendext, sendcount, sendtype,
207                                static_cast<char *>(recvbuf) + rank * recvcount * recvext, recvcount, recvtype);
208   if (err == MPI_SUCCESS && size > 1) {
209     /* Initiate all send/recv to/from others. */
210     requests = new MPI_Request[2 * (size - 1)];
211     /* Post all receives first -- a simple optimization */
212     count = 0;
213     for (i = (rank + 1) % size; i != rank; i = (i + 1) % size) {
214       requests[count] = Request::irecv_init(static_cast<char *>(recvbuf) + i * recvcount * recvext, recvcount,
215                                         recvtype, i, system_tag, comm);
216       count++;
217     }
218     /* Now post all sends in reverse order
219      *   - We would like to minimize the search time through message queue
220      *     when messages actually arrive in the order in which they were posted.
221      * TODO: check the previous assertion
222      */
223     for (i = (rank + size - 1) % size; i != rank; i = (i + size - 1) % size) {
224       requests[count] = Request::isend_init(static_cast<char *>(sendbuf) + i * sendcount * sendext, sendcount,
225                                         sendtype, i, system_tag, comm);
226       count++;
227     }
228     /* Wait for them all. */
229     Request::startall(count, requests);
230     (*request)->set_nbc_requests(requests, count);
231   }
232   return MPI_SUCCESS;
233 }
234
235 int Colls::ialltoallv(void *sendbuf, int *sendcounts, int *senddisps, MPI_Datatype sendtype,
236                               void *recvbuf, int *recvcounts, int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm, MPI_Request *request){
237   const int system_tag = COLL_TAG_ALLTOALLV;
238   MPI_Aint lb = 0;
239   MPI_Aint sendext = 0;
240   MPI_Aint recvext = 0;
241   MPI_Request *requests;
242
243   /* Initialize. */
244   int rank = comm->rank();
245   int size = comm->size();
246   (*request) = new Request( nullptr, 0, MPI_BYTE,
247                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
248   sendtype->extent(&lb, &sendext);
249   recvtype->extent(&lb, &recvext);
250   /* Local copy from self */
251   int err = Datatype::copy(static_cast<char *>(sendbuf) + senddisps[rank] * sendext, sendcounts[rank], sendtype,
252                                static_cast<char *>(recvbuf) + recvdisps[rank] * recvext, recvcounts[rank], recvtype);
253   if (err == MPI_SUCCESS && size > 1) {
254     /* Initiate all send/recv to/from others. */
255     requests = new MPI_Request[2 * (size - 1)];
256     int count = 0;
257     /* Create all receives that will be posted first */
258     for (int i = 0; i < size; ++i) {
259       if (i != rank) {
260         requests[count] = Request::irecv_init(static_cast<char *>(recvbuf) + recvdisps[i] * recvext,
261                                           recvcounts[i], recvtype, i, system_tag, comm);
262         count++;
263       }else{
264         XBT_DEBUG("<%d> skip request creation [src = %d, recvcounts[src] = %d]", rank, i, recvcounts[i]);
265       }
266     }
267     /* Now create all sends  */
268     for (int i = 0; i < size; ++i) {
269       if (i != rank) {
270       requests[count] = Request::isend_init(static_cast<char *>(sendbuf) + senddisps[i] * sendext,
271                                         sendcounts[i], sendtype, i, system_tag, comm);
272       count++;
273       }else{
274         XBT_DEBUG("<%d> skip request creation [dst = %d, sendcounts[dst] = %d]", rank, i, sendcounts[i]);
275       }
276     }
277     /* Wait for them all. */
278     Request::startall(count, requests);
279     (*request)->set_nbc_requests(requests, count);
280   }
281   return err;
282 }
283
284 int Colls::ialltoallw(void *sendbuf, int *sendcounts, int *senddisps, MPI_Datatype* sendtypes,
285                               void *recvbuf, int *recvcounts, int *recvdisps, MPI_Datatype* recvtypes, MPI_Comm comm, MPI_Request *request){
286   const int system_tag = COLL_TAG_ALLTOALLV;
287   MPI_Request *requests;
288
289   /* Initialize. */
290   int rank = comm->rank();
291   int size = comm->size();
292   (*request) = new Request( nullptr, 0, MPI_BYTE,
293                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
294   /* Local copy from self */
295   int err = (sendcounts[rank]>0 && recvcounts[rank]) ? Datatype::copy(static_cast<char *>(sendbuf) + senddisps[rank], sendcounts[rank], sendtypes[rank],
296                                static_cast<char *>(recvbuf) + recvdisps[rank], recvcounts[rank], recvtypes[rank]): MPI_SUCCESS;
297   if (err == MPI_SUCCESS && size > 1) {
298     /* Initiate all send/recv to/from others. */
299     requests = new MPI_Request[2 * (size - 1)];
300     int count = 0;
301     /* Create all receives that will be posted first */
302     for (int i = 0; i < size; ++i) {
303       if (i != rank) {
304         requests[count] = Request::irecv_init(static_cast<char *>(recvbuf) + recvdisps[i],
305                                           recvcounts[i], recvtypes[i], i, system_tag, comm);
306         count++;
307       }else{
308         XBT_DEBUG("<%d> skip request creation [src = %d, recvcounts[src] = %d]", rank, i, recvcounts[i]);
309       }
310     }
311     /* Now create all sends  */
312     for (int i = 0; i < size; ++i) {
313       if (i != rank) {
314       requests[count] = Request::isend_init(static_cast<char *>(sendbuf) + senddisps[i] ,
315                                         sendcounts[i], sendtypes[i], i, system_tag, comm);
316       count++;
317       }else{
318         XBT_DEBUG("<%d> skip request creation [dst = %d, sendcounts[dst] = %d]", rank, i, sendcounts[i]);
319       }
320     }
321     /* Wait for them all. */
322     Request::startall(count, requests);
323     (*request)->set_nbc_requests(requests, count);
324   }
325   return err;
326 }
327
328 int Colls::igather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
329                      void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request *request)
330 {
331   const int system_tag = COLL_TAG_GATHER;
332   MPI_Aint lb = 0;
333   MPI_Aint recvext = 0;
334   MPI_Request *requests;
335
336   int rank = comm->rank();
337   int size = comm->size();
338   (*request) = new Request( nullptr, 0, MPI_BYTE,
339                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
340   if(rank != root) {
341     // Send buffer to root
342     requests = new MPI_Request[1];
343     requests[0]=Request::isend(sendbuf, sendcount, sendtype, root, system_tag, comm);
344     (*request)->set_nbc_requests(requests, 1);
345   } else {
346     recvtype->extent(&lb, &recvext);
347     // Local copy from root
348     Datatype::copy(sendbuf, sendcount, sendtype, static_cast<char*>(recvbuf) + root * recvcount * recvext,
349                        recvcount, recvtype);
350     // Receive buffers from senders
351     requests = new MPI_Request[size - 1];
352     int index = 0;
353     for (int src = 0; src < size; src++) {
354       if(src != root) {
355         requests[index] = Request::irecv_init(static_cast<char*>(recvbuf) + src * recvcount * recvext, recvcount, recvtype,
356                                           src, system_tag, comm);
357         index++;
358       }
359     }
360     // Wait for completion of irecv's.
361     Request::startall(size - 1, requests);
362     (*request)->set_nbc_requests(requests, size - 1);
363   }
364   return MPI_SUCCESS;
365 }
366
367 int Colls::igatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
368                       MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request *request)
369 {
370   int system_tag = COLL_TAG_GATHERV;
371   MPI_Aint lb = 0;
372   MPI_Aint recvext = 0;
373   MPI_Request *requests;
374   
375   int rank = comm->rank();
376   int size = comm->size();
377   (*request) = new Request( nullptr, 0, MPI_BYTE,
378                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
379   if (rank != root) {
380     // Send buffer to root
381     requests = new MPI_Request[1];
382     requests[0]=Request::isend(sendbuf, sendcount, sendtype, root, system_tag, comm);
383     (*request)->set_nbc_requests(requests, 1);
384   } else {
385     recvtype->extent(&lb, &recvext);
386     // Local copy from root
387     Datatype::copy(sendbuf, sendcount, sendtype, static_cast<char*>(recvbuf) + displs[root] * recvext,
388                        recvcounts[root], recvtype);
389     // Receive buffers from senders
390     requests = new MPI_Request[size - 1];
391     int index = 0;
392     for (int src = 0; src < size; src++) {
393       if(src != root) {
394         requests[index] = Request::irecv_init(static_cast<char*>(recvbuf) + displs[src] * recvext,
395                           recvcounts[src], recvtype, src, system_tag, comm);
396         index++;
397       }
398     }
399     // Wait for completion of irecv's.
400     Request::startall(size - 1, requests);
401     (*request)->set_nbc_requests(requests, size - 1);
402   }
403   return MPI_SUCCESS;
404 }
405 int Colls::iscatterv(void *sendbuf, int *sendcounts, int *displs, MPI_Datatype sendtype, void *recvbuf, int recvcount,
406                        MPI_Datatype recvtype, int root, MPI_Comm comm, MPI_Request *request)
407 {
408   int system_tag = COLL_TAG_SCATTERV;
409   MPI_Aint lb = 0;
410   MPI_Aint sendext = 0;
411   MPI_Request* requests;
412
413   int rank = comm->rank();
414   int size = comm->size();
415   (*request) = new Request( nullptr, 0, MPI_BYTE,
416                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
417   if(rank != root) {
418     // Recv buffer from root
419     requests = new MPI_Request[1];
420     requests[0]=Request::irecv(recvbuf, recvcount, recvtype, root, system_tag, comm);
421     (*request)->set_nbc_requests(requests, 1);
422   } else {
423     sendtype->extent(&lb, &sendext);
424     // Local copy from root
425     if(recvbuf!=MPI_IN_PLACE){
426       Datatype::copy(static_cast<char *>(sendbuf) + displs[root] * sendext, sendcounts[root],
427                        sendtype, recvbuf, recvcount, recvtype);
428     }
429     // Send buffers to receivers
430     MPI_Request *requests = new MPI_Request[size - 1];
431     int index = 0;
432     for (int dst = 0; dst < size; dst++) {
433       if (dst != root) {
434         requests[index] = Request::isend_init(static_cast<char *>(sendbuf) + displs[dst] * sendext, sendcounts[dst],
435                             sendtype, dst, system_tag, comm);
436         index++;
437       }
438     }
439     // Wait for completion of isend's.
440     Request::startall(size - 1, requests);
441     (*request)->set_nbc_requests(requests, size - 1);
442   }
443   return MPI_SUCCESS;
444 }
445
446 int Colls::ireduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root,
447                      MPI_Comm comm, MPI_Request* request)
448 {
449   const int system_tag = COLL_TAG_REDUCE;
450   MPI_Aint lb = 0;
451   MPI_Aint dataext = 0;
452   MPI_Request* requests;
453
454   char* sendtmpbuf = static_cast<char *>(sendbuf);
455
456   int rank = comm->rank();
457   int size = comm->size();
458
459   if (size <= 0)
460     return MPI_ERR_COMM;
461
462   if( sendbuf == MPI_IN_PLACE ) {
463     sendtmpbuf = static_cast<char *>(smpi_get_tmp_sendbuffer(count*datatype->get_extent()));
464     Datatype::copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
465   }
466
467   if(rank == root){
468     (*request) =  new Request( recvbuf, count, datatype,
469                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT, op);
470   }
471   else
472     (*request) = new Request( nullptr, count, datatype,
473                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT);
474
475   if(rank != root) {
476     // Send buffer to root
477     requests = new MPI_Request[1];
478     requests[0]=Request::isend(sendtmpbuf, count, datatype, root, system_tag, comm);
479     (*request)->set_nbc_requests(requests, 1);
480   } else {
481     datatype->extent(&lb, &dataext);
482     // Local copy from root
483     if (sendtmpbuf != nullptr && recvbuf != nullptr)
484       Datatype::copy(sendtmpbuf, count, datatype, recvbuf, count, datatype);
485     // Receive buffers from senders
486     MPI_Request *requests = new MPI_Request[size - 1];
487     int index = 0;
488     for (int src = 0; src < size; src++) {
489       if (src != root) {
490         requests[index] =
491           Request::irecv_init(smpi_get_tmp_sendbuffer(count * dataext), count, datatype, src, system_tag, comm);
492         index++;
493       }
494     }
495     // Wait for completion of irecv's.
496     Request::startall(size - 1, requests);
497     (*request)->set_nbc_requests(requests, size - 1);
498   }     
499   if( sendbuf == MPI_IN_PLACE ) {
500     smpi_free_tmp_buffer(sendtmpbuf);
501   }
502   return MPI_SUCCESS;
503 }
504
505 int Colls::iallreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
506                       MPI_Op op, MPI_Comm comm, MPI_Request* request)
507 {
508
509   const int system_tag = COLL_TAG_ALLREDUCE;
510   MPI_Aint lb = 0;
511   MPI_Aint dataext = 0;
512   MPI_Request *requests;
513
514   int rank = comm->rank();
515   int size = comm->size();
516   (*request) = new Request( recvbuf, count, datatype,
517                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT, op);
518   // FIXME: check for errors
519   datatype->extent(&lb, &dataext);
520   // Local copy from self
521   Datatype::copy(sendbuf, count, datatype, recvbuf, count, datatype);
522   // Send/Recv buffers to/from others;
523   requests = new MPI_Request[2 * (size - 1)];
524   int index = 0;
525   for (int other = 0; other < size; other++) {
526     if(other != rank) {
527       requests[index] = Request::isend_init(sendbuf, count, datatype, other, system_tag,comm);
528       index++;
529       requests[index] = Request::irecv_init(smpi_get_tmp_sendbuffer(count * dataext), count, datatype,
530                                         other, system_tag, comm);
531       index++;
532     }
533   }
534   Request::startall(2 * (size - 1), requests);
535   (*request)->set_nbc_requests(requests, 2 * (size - 1));
536   return MPI_SUCCESS;
537 }
538
539 int Colls::iscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request* request)
540 {
541   int system_tag = -888;
542   MPI_Aint lb      = 0;
543   MPI_Aint dataext = 0;
544
545   int rank = comm->rank();
546   int size = comm->size();
547   (*request) = new Request( recvbuf, count, datatype,
548                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT, op);
549   datatype->extent(&lb, &dataext);
550
551   // Local copy from self
552   Datatype::copy(sendbuf, count, datatype, recvbuf, count, datatype);
553
554   // Send/Recv buffers to/from others
555   MPI_Request *requests = new MPI_Request[size - 1];
556   int index = 0;
557   for (int other = 0; other < rank; other++) {
558     requests[index] = Request::irecv_init(smpi_get_tmp_sendbuffer(count * dataext), count, datatype, other, system_tag, comm);
559     index++;
560   }
561   for (int other = rank + 1; other < size; other++) {
562     requests[index] = Request::isend_init(sendbuf, count, datatype, other, system_tag, comm);
563     index++;
564   }
565   // Wait for completion of all comms.
566   Request::startall(size - 1, requests);
567   (*request)->set_nbc_requests(requests, size - 1);
568   return MPI_SUCCESS;
569 }
570
571 int Colls::iexscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, MPI_Request* request)
572 {
573   int system_tag = -888;
574   MPI_Aint lb         = 0;
575   MPI_Aint dataext    = 0;
576   int rank = comm->rank();
577   int size = comm->size();
578   (*request) = new Request( recvbuf, count, datatype,
579                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT, op);
580   datatype->extent(&lb, &dataext);
581   if(rank != 0)
582     memset(recvbuf, 0, count*dataext);
583
584   // Send/Recv buffers to/from others
585   MPI_Request *requests = new MPI_Request[size - 1];
586   int index = 0;
587   for (int other = 0; other < rank; other++) {
588     requests[index] = Request::irecv_init(smpi_get_tmp_sendbuffer(count * dataext), count, datatype, other, system_tag, comm);
589     index++;
590   }
591   for (int other = rank + 1; other < size; other++) {
592     requests[index] = Request::isend_init(sendbuf, count, datatype, other, system_tag, comm);
593     index++;
594   }
595   // Wait for completion of all comms.
596   Request::startall(size - 1, requests);
597   (*request)->set_nbc_requests(requests, size - 1);
598   return MPI_SUCCESS;
599 }
600
601 int Colls::ireduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op,
602                              MPI_Comm comm, MPI_Request* request){
603 //Version where each process performs the reduce for its own part. Alltoall pattern for comms.
604   const int system_tag = COLL_TAG_REDUCE_SCATTER;
605   MPI_Aint lb = 0;
606   MPI_Aint dataext = 0;
607   MPI_Request *requests;
608
609   int rank = comm->rank();
610   int size = comm->size();
611   int count=recvcounts[rank];
612   (*request) = new Request( recvbuf, count, datatype,
613                          rank,rank, system_tag, comm, MPI_REQ_PERSISTENT, op);
614   datatype->extent(&lb, &dataext);
615
616   // Send/Recv buffers to/from others;
617   requests = new MPI_Request[2 * (size - 1)];
618   int index = 0;
619   int recvdisp=0;
620   for (int other = 0; other < size; other++) {
621     if(other != rank) {
622       requests[index] = Request::isend_init(static_cast<char *>(sendbuf) + recvdisp * dataext, recvcounts[other], datatype, other, system_tag,comm);
623       XBT_VERB("sending with recvdisp %d", recvdisp);
624       index++;
625       requests[index] = Request::irecv_init(smpi_get_tmp_sendbuffer(count * dataext), count, datatype,
626                                         other, system_tag, comm);
627       index++;
628     }else{
629       Datatype::copy(static_cast<char *>(sendbuf) + recvdisp * dataext, count, datatype, recvbuf, count, datatype);
630     }
631     recvdisp+=recvcounts[other];
632   }
633   Request::startall(2 * (size - 1), requests);
634   (*request)->set_nbc_requests(requests, 2 * (size - 1));
635   return MPI_SUCCESS;
636 }
637
638 }
639 }