Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e23944f1f6966cd9663960af68015f63366bbe5c
[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 #define MCA_COLL_BASE_TAG_ALLTOALL 101
21
22 int smpi_coll_tuned_alltoall_ompi_pairwise(void *sbuf, int scount, 
23                                             MPI_Datatype sdtype,
24                                             void* rbuf, int rcount,
25                                             MPI_Datatype rdtype,
26                                             MPI_Comm comm)
27 {
28     int rank, size, step;
29     int sendto, recvfrom;
30     void * tmpsend, *tmprecv;
31     MPI_Aint lb, sext, rext;
32
33     size = smpi_comm_size(comm);
34     rank = smpi_comm_rank(comm);
35
36     XBT_VERB(
37                  "coll:tuned:alltoall_ompi_pairwise rank %d", rank);
38
39     smpi_datatype_extent (sdtype, &lb, &sext);
40     smpi_datatype_extent (rdtype, &lb, &rext);
41
42     
43     /* Perform pairwise exchange - starting from 1 so the local copy is last */
44     for (step = 1; step < size + 1; step++) {
45
46         /* Determine sender and receiver for this step. */
47         sendto  = (rank + step) % size;
48         recvfrom = (rank + size - step) % size;
49
50         /* Determine sending and receiving locations */
51         tmpsend = (char*)sbuf + sendto * sext * scount;
52         tmprecv = (char*)rbuf + recvfrom * rext * rcount;
53
54         /* send and receive */
55         smpi_mpi_sendrecv( tmpsend, scount, sdtype, sendto, 
56                                         MCA_COLL_BASE_TAG_ALLTOALL,
57                                         tmprecv, rcount, rdtype, recvfrom, 
58                                         MCA_COLL_BASE_TAG_ALLTOALL,
59                                         comm, MPI_STATUS_IGNORE);
60     }
61
62     return MPI_SUCCESS;
63 }