Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / smpi / colls / barrier / barrier-mvapich2-pair.cpp
1 /* Copyright (c) 2013-2023. 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 "../coll_tuned_topo.hpp"
43 #include "../colls_private.hpp"
44 #include "smpi_actor.hpp"
45 namespace simgrid::smpi {
46 int barrier__mvapich2_pair(MPI_Comm comm)
47 {
48
49     int size, rank;
50     int d, dst, src;
51     int mpi_errno = MPI_SUCCESS;
52     int tag = smpi_process()->finalizing() ? COLL_TAG_BARRIER-1: COLL_TAG_BARRIER;
53
54     size = comm->size();
55     /* Trivial barriers return immediately */
56     if (size == 1)
57         return MPI_SUCCESS;
58
59     rank =  comm->rank();
60     int N2_prev = 1;
61     /*  N2_prev = greatest power of two < size of Comm  */
62     for( N2_prev = 1; N2_prev <= size; N2_prev <<= 1 );
63     N2_prev >>= 1;
64
65     int surfeit = size - N2_prev;
66
67     /* Perform a combine-like operation */
68     if (rank < N2_prev) {
69         if (rank < surfeit) {
70             /* get the fanin letter from the upper "half" process: */
71             dst = N2_prev + rank;
72             Request::recv(nullptr, 0, MPI_BYTE, dst, tag, 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(nullptr, 0, MPI_BYTE, dst, tag, nullptr, 0, MPI_BYTE, dst, tag,
79                               comm, MPI_STATUS_IGNORE);
80         }
81
82         /* fanout data to nodes above N2_prev... */
83         if (rank < surfeit) {
84             dst = N2_prev + rank;
85             Request::send(nullptr, 0, MPI_BYTE, dst, tag, comm);
86         }
87     } else {
88         /* fanin data to power of 2 subset */
89         src = rank - N2_prev;
90         Request::sendrecv(nullptr, 0, MPI_BYTE, src, tag, nullptr, 0, MPI_BYTE, src, tag,
91                           comm, MPI_STATUS_IGNORE);
92     }
93
94     return mpi_errno;
95
96 }
97
98 } // namespace simgrid::smpi