Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'clean_events' of github.com:Takishipp/simgrid into clean_events
[simgrid.git] / src / smpi / colls / barrier / barrier-mvapich2-pair.cpp
1 /* Copyright (c) 2013-2017. 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 namespace simgrid{
45 namespace smpi{
46 int Coll_barrier_mvapich2_pair::barrier(MPI_Comm comm)
47 {
48
49     int size, rank;
50     int d, dst, src;
51     int mpi_errno = MPI_SUCCESS;
52
53     size = comm->size();
54     /* Trivial barriers return immediately */
55     if (size == 1)
56         return MPI_SUCCESS;
57
58     rank =  comm->rank();
59     int N2_prev = 1;
60     /*  N2_prev = greatest power of two < size of Comm  */
61     for( N2_prev = 1; N2_prev <= size; N2_prev <<= 1 );
62     N2_prev >>= 1;
63
64     int surfeit = size - N2_prev;
65
66     /* Perform a combine-like operation */
67     if (rank < N2_prev) {
68         if (rank < surfeit) {
69             /* get the fanin letter from the upper "half" process: */
70             dst = N2_prev + rank;
71             Request::recv(NULL, 0, MPI_BYTE, dst, COLL_TAG_BARRIER,
72                                      comm, MPI_STATUS_IGNORE);
73         }
74
75         /* combine on embedded N2_prev power-of-two processes */
76         for (d = 1; d < N2_prev; d <<= 1) {
77             dst = (rank ^ d);
78             Request::sendrecv(NULL, 0, MPI_BYTE, dst, COLL_TAG_BARRIER, NULL,
79                                  0, MPI_BYTE, dst, COLL_TAG_BARRIER, comm,
80                                  MPI_STATUS_IGNORE);
81         }
82
83         /* fanout data to nodes above N2_prev... */
84         if (rank < surfeit) {
85             dst = N2_prev + rank;
86             Request::send(NULL, 0, MPI_BYTE, dst, COLL_TAG_BARRIER,
87                                      comm);
88         }
89     } else {
90         /* fanin data to power of 2 subset */
91         src = rank - N2_prev;
92         Request::sendrecv(NULL, 0, MPI_BYTE, src, COLL_TAG_BARRIER,
93                                      NULL, 0, MPI_BYTE, src, COLL_TAG_BARRIER,
94                                      comm, MPI_STATUS_IGNORE);
95     }
96
97     return mpi_errno;
98
99 }
100
101 }
102 }