Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New collectives for mvapich2 selector : allgatherv, allreduce, alltoallv, barrier
[simgrid.git] / src / smpi / colls / barrier-mvapich2-pair.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 /*
8  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
9  *                         University Research and Technology
10  *                         Corporation.  All rights reserved.
11  * Copyright (c) 2004-2006 The University of Tennessee and The University
12  *                         of Tennessee Research Foundation.  All rights
13  *                         reserved.
14  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
15  *                         University of Stuttgart.  All rights reserved.
16  * Copyright (c) 2004-2005 The Regents of the University of California.
17  *                         All rights reserved.
18  * Copyright (c) 2008      Sun Microsystems, Inc.  All rights reserved.
19  *
20  * Additional copyrights may follow
21  */
22  
23  /* -*- Mode: C; c-basic-offset:4 ; -*- */
24 /*
25  *
26  *  (C) 2001 by Argonne National Laboratory.
27  *      See COPYRIGHT in top-level directory.
28  */
29
30 /* Copyright (c) 2001-2014, The Ohio State University. All rights
31  * reserved.
32  *
33  * This file is part of the MVAPICH2 software package developed by the
34  * team members of The Ohio State University's Network-Based Computing
35  * Laboratory (NBCL), headed by Professor Dhabaleswar K. (DK) Panda.
36  *
37  * For detailed copyright and licensing information, please refer to the
38  * copyright file COPYRIGHT in the top level MVAPICH2 directory.
39  *
40  */
41
42 #include "colls_private.h"
43 #include "coll_tuned_topo.h"
44
45 int smpi_coll_tuned_barrier_mvapich2_pair(MPI_Comm comm)
46 {
47
48     int size, rank;
49     int d, dst, src;
50     int mpi_errno = MPI_SUCCESS;
51
52     size = smpi_comm_size(comm);
53     /* Trivial barriers return immediately */
54     if (size == 1)
55         return MPI_SUCCESS;
56
57     rank =  smpi_comm_rank(comm);
58     int N2_prev = 1;
59     /*  N2_prev = greatest power of two < size of Comm  */
60     for( N2_prev = 1; N2_prev <= size; N2_prev <<= 1 );
61     N2_prev >>= 1;
62     
63     int surfeit = size - N2_prev;
64
65     /* Perform a combine-like operation */
66     if (rank < N2_prev) {
67         if (rank < surfeit) {
68             /* get the fanin letter from the upper "half" process: */
69             dst = N2_prev + rank;
70             smpi_mpi_recv(NULL, 0, MPI_BYTE, dst, COLL_TAG_BARRIER,
71                                      comm, MPI_STATUS_IGNORE);
72         }
73
74         /* combine on embedded N2_prev power-of-two processes */
75         for (d = 1; d < N2_prev; d <<= 1) {
76             dst = (rank ^ d);
77             smpi_mpi_sendrecv(NULL, 0, MPI_BYTE, dst, COLL_TAG_BARRIER, NULL,
78                                  0, MPI_BYTE, dst, COLL_TAG_BARRIER, comm,
79                                  MPI_STATUS_IGNORE);
80         }
81
82         /* fanout data to nodes above N2_prev... */
83         if (rank < surfeit) {
84             dst = N2_prev + rank;
85             smpi_mpi_send(NULL, 0, MPI_BYTE, dst, COLL_TAG_BARRIER,
86                                      comm);
87         }
88     } else {
89         /* fanin data to power of 2 subset */
90         src = rank - N2_prev;
91         smpi_mpi_sendrecv(NULL, 0, MPI_BYTE, src, COLL_TAG_BARRIER,
92                                      NULL, 0, MPI_BYTE, src, COLL_TAG_BARRIER,
93                                      comm, MPI_STATUS_IGNORE);
94     }
95
96     return mpi_errno;
97
98 }