Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'dvfs'
[simgrid.git] / src / smpi / colls / alltoall-ompi-pairwise.c
1 /*
2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3  *                         University Research and Technology
4  *                         Corporation.  All rights reserved.
5  * Copyright (c) 2004-2006 The University of Tennessee and The University
6  *                         of Tennessee Research Foundation.  All rights
7  *                         reserved.
8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9  *                         University of Stuttgart.  All rights reserved.
10  * Copyright (c) 2004-2005 The Regents of the University of California.
11  *                         All rights reserved.
12  * $COPYRIGHT$
13  *
14  * Additional copyrights may follow
15  *
16  * $HEADER$
17  */
18
19 #include "colls_private.h"
20
21 int smpi_coll_tuned_alltoall_ompi_pairwise(void *sbuf, int scount, 
22                                             MPI_Datatype sdtype,
23                                             void* rbuf, int rcount,
24                                             MPI_Datatype rdtype,
25                                             MPI_Comm comm)
26 {
27     int rank, size, step;
28     int sendto, recvfrom;
29     void * tmpsend, *tmprecv;
30     MPI_Aint lb, sext, rext;
31
32     size = smpi_comm_size(comm);
33     rank = smpi_comm_rank(comm);
34
35     XBT_VERB(
36                  "coll:tuned:alltoall_ompi_pairwise rank %d", rank);
37
38     smpi_datatype_extent (sdtype, &lb, &sext);
39     smpi_datatype_extent (rdtype, &lb, &rext);
40
41     
42     /* Perform pairwise exchange - starting from 1 so the local copy is last */
43     for (step = 1; step < size + 1; step++) {
44
45         /* Determine sender and receiver for this step. */
46         sendto  = (rank + step) % size;
47         recvfrom = (rank + size - step) % size;
48
49         /* Determine sending and receiving locations */
50         tmpsend = (char*)sbuf + sendto * sext * scount;
51         tmprecv = (char*)rbuf + recvfrom * rext * rcount;
52
53         /* send and receive */
54         smpi_mpi_sendrecv( tmpsend, scount, sdtype, sendto, 
55                                         COLL_TAG_ALLTOALL,
56                                         tmprecv, rcount, rdtype, recvfrom, 
57                                         COLL_TAG_ALLTOALL,
58                                         comm, MPI_STATUS_IGNORE);
59     }
60
61     return MPI_SUCCESS;
62 }