Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
oops
[simgrid.git] / src / smpi / colls / alltoallv-bruck.c
1 /* Copyright (c) 2013-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "colls_private.h"
8
9 /**
10  * Alltoall Bruck
11  *
12  * Openmpi calls this routine when the message size sent to each rank < 2000 bytes and size < 12
13  * FIXME: uh, check smpi_pmpi again, but this routine is called for > 12, not
14  * less...
15  **/
16 int smpi_coll_tuned_alltoallv_bruck(void *sendbuf, int *sendcounts, int *senddisps,
17                                    MPI_Datatype sendtype, void *recvbuf,
18                                    int *recvcounts, int *recvdisps, MPI_Datatype recvtype,
19                                    MPI_Comm comm)
20 {
21   int system_tag = COLL_TAG_ALLTOALLV;
22   int i, rank, size, err, count;
23   MPI_Aint lb;
24   MPI_Aint sendext = 0;
25   MPI_Aint recvext = 0;
26   MPI_Request *requests;
27
28   // FIXME: check implementation
29   rank = smpi_comm_rank(comm);
30   size = smpi_comm_size(comm);
31   XBT_DEBUG("<%d> algorithm alltoall_bruck() called.", rank);
32
33   smpi_datatype_extent(sendtype, &lb, &sendext);
34   smpi_datatype_extent(recvtype, &lb, &recvext);
35   /* Local copy from self */
36   err =
37       smpi_datatype_copy((char *)sendbuf + senddisps[rank] * sendext,
38                          sendcounts[rank], sendtype,
39                          (char *)recvbuf + recvdisps[rank] * recvext,
40                          recvcounts[rank], recvtype);
41   if (err == MPI_SUCCESS && size > 1) {
42     /* Initiate all send/recv to/from others. */
43
44       int bblock = 4;//MPIR_PARAM_ALLTOALL_THROTTLE
45       //if (bblock == 0) bblock = comm_size;
46
47
48      // requests = xbt_new(MPI_Request, 2 * (bblock - 1));
49       int ii, ss, dst;
50       /* post only bblock isends/irecvs at a time as suggested by Tony Ladd */
51       for (ii=0; ii<size; ii+=bblock) {
52           requests = xbt_new(MPI_Request, 2 * (bblock ));
53
54           ss = size-ii < bblock ? size-ii : bblock;
55           count = 0;
56
57           /* do the communication -- post ss sends and receives: */
58           for ( i=0; i<ss; i++ ) {
59             dst = (rank+i+ii) % size;
60               if (dst == rank) {
61                 XBT_DEBUG("<%d> skip request creation [src = %d, recvcount = %d]",
62                        rank, i, recvcounts[dst]);
63                 continue;
64               }
65
66               requests[count]=smpi_mpi_irecv((char *)recvbuf + recvdisps[dst] * recvext, recvcounts[dst],
67                                   recvtype, dst, system_tag, comm );
68               count++;
69             }
70             /* Now create all sends  */
71           for ( i=0; i<ss; i++ ) {
72               dst = (rank-i-ii+size) % size;
73               if (dst == rank) {
74                 XBT_DEBUG("<%d> skip request creation [dst = %d, sendcount = %d]",
75                        rank, i, sendcounts[dst]);
76                 continue;
77               }
78               requests[count]=smpi_mpi_isend((char *)sendbuf + senddisps[dst] * sendext, sendcounts[dst],
79                                   sendtype, dst, system_tag, comm);
80               count++;
81             }
82             /* Wait for them all. */
83             //smpi_mpi_startall(count, requests);
84             XBT_DEBUG("<%d> wait for %d requests", rank, count);
85             smpi_mpi_waitall(count, requests, MPI_STATUSES_IGNORE);
86             xbt_free(requests);
87
88           }
89
90   }
91   return MPI_SUCCESS;
92 }