Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3cccebb01121a7be1ff5626d2fb5dee72051fa45
[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_NON_PERSISTENT);
23   (*request)->ref();
24   if (rank > 0) {
25     requests = new MPI_Request[2];
26     requests[0] = Request::isend (nullptr, 0, MPI_BYTE, 0,
27                              COLL_TAG_BARRIER,
28                              comm);
29     requests[1] = Request::irecv (nullptr, 0, MPI_BYTE, 0,
30                              COLL_TAG_BARRIER,
31                              comm);
32     (*request)->set_nbc_requests(requests, 2);
33   }
34   else {
35     requests = new MPI_Request[(size-1)*2];
36     for (i = 1; i < 2*size-1; i+=2) {
37         requests[i-1] = Request::irecv(nullptr, 0, MPI_BYTE, MPI_ANY_SOURCE,
38                                  COLL_TAG_BARRIER, comm
39                                  );
40         requests[i] = Request::isend(nullptr, 0, MPI_BYTE, (i+1)/2,
41                                  COLL_TAG_BARRIER,
42                                  comm
43                                  );
44     }
45     (*request)->set_nbc_requests(requests, 2*(size-1));
46   }
47   return MPI_SUCCESS;
48 }
49
50 }
51 }