Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add allgatherv algo from ompi
[simgrid.git] / src / smpi / colls / alltoallv-bruck.c
1 #include "colls_private.h"
2
3 /**
4  * Alltoall Bruck
5  *
6  * Openmpi calls this routine when the message size sent to each rank < 2000 bytes and size < 12
7  * FIXME: uh, check smpi_pmpi again, but this routine is called for > 12, not
8  * less...
9  **/
10 int smpi_coll_tuned_alltoallv_bruck(void *sendbuf, int *sendcounts, int *senddisps,
11                                    MPI_Datatype sendtype, void *recvbuf,
12                                    int *recvcounts, int *recvdisps, MPI_Datatype recvtype,
13                                    MPI_Comm comm)
14 {
15   int system_tag = 777;
16   int i, rank, size, err, count;
17   MPI_Aint lb;
18   MPI_Aint sendext = 0;
19   MPI_Aint recvext = 0;
20   MPI_Request *requests;
21
22   // FIXME: check implementation
23   rank = smpi_comm_rank(comm);
24   size = smpi_comm_size(comm);
25   XBT_DEBUG("<%d> algorithm alltoall_bruck() called.", rank);
26
27   err = smpi_datatype_extent(sendtype, &lb, &sendext);
28   err = smpi_datatype_extent(recvtype, &lb, &recvext);
29   /* Local copy from self */
30   err =
31       smpi_datatype_copy((char *)sendbuf + senddisps[rank] * sendext, 
32                          sendcounts[rank], sendtype, 
33                          (char *)recvbuf + recvdisps[rank] * recvext,
34                          recvcounts[rank], recvtype);
35   if (err == MPI_SUCCESS && size > 1) {
36     /* Initiate all send/recv to/from others. */
37     requests = xbt_new(MPI_Request, 2 * (size - 1));
38     count = 0;
39     /* Create all receives that will be posted first */
40     for (i = 0; i < size; ++i) {
41       if (i == rank) {
42         XBT_DEBUG("<%d> skip request creation [src = %d, recvcount = %d]",
43                rank, i, recvcounts[i]);
44         continue;
45       }
46       requests[count] =
47           smpi_irecv_init((char *)recvbuf + recvdisps[i] * recvext, recvcounts[i],
48                           recvtype, i, system_tag, comm);
49       count++;
50     }
51     /* Now create all sends  */
52     for (i = 0; i < size; ++i) {
53       if (i == rank) {
54         XBT_DEBUG("<%d> skip request creation [dst = %d, sendcount = %d]",
55                rank, i, sendcounts[i]);
56         continue;
57       }
58       requests[count] =
59           smpi_isend_init((char *)sendbuf + senddisps[i] * sendext, sendcounts[i],
60                           sendtype, i, system_tag, comm);
61       count++;
62     }
63     /* Wait for them all. */
64     smpi_mpi_startall(count, requests);
65     XBT_DEBUG("<%d> wait for %d requests", rank, count);
66     smpi_mpi_waitall(count, requests, MPI_STATUS_IGNORE);
67     xbt_free(requests);
68   }
69   return MPI_SUCCESS;
70 }