Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
eee6c2f6abb96f91fd61eeae0495d7d394d0b459
[simgrid.git] / src / smpi / colls / barrier / barrier-mpich-smp.cpp
1 /* Copyright (c) 2013-2022. 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 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
8 /*
9  *
10  *  (C) 2001 by Argonne National Laboratory.
11  *      See COPYRIGHT in top-level directory.
12  */
13
14
15 #include "../coll_tuned_topo.hpp"
16 #include "../colls_private.hpp"
17
18 namespace simgrid::smpi {
19 int barrier__mpich_smp(MPI_Comm comm)
20 {
21     int mpi_errno = MPI_SUCCESS;
22     int mpi_errno_ret = MPI_SUCCESS;
23     MPI_Comm shmem_comm = MPI_COMM_NULL, leader_comm = MPI_COMM_NULL;
24     int local_rank = -1;
25
26     if(comm->get_leaders_comm()==MPI_COMM_NULL){
27       comm->init_smp();
28     }
29
30     shmem_comm = comm->get_intra_comm();
31     local_rank = shmem_comm->rank();
32     /* do the intranode barrier on all nodes */
33     if (shmem_comm != nullptr) {
34       mpi_errno = barrier__mpich(shmem_comm);
35       if (mpi_errno) {
36         mpi_errno_ret += mpi_errno;
37       }
38     }
39
40     leader_comm = comm->get_leaders_comm();
41     /* do the barrier across roots of all nodes */
42     if (leader_comm != nullptr && local_rank == 0) {
43       mpi_errno = barrier__mpich(leader_comm);
44       if (mpi_errno) {
45         mpi_errno_ret += mpi_errno;
46       }
47     }
48
49     /* release the local processes on each node with a 1-byte
50      * broadcast (0-byte broadcast just returns without doing
51      * anything) */
52     if (shmem_comm != nullptr) {
53       int i     = 0;
54       mpi_errno = bcast__mpich(&i, 1, MPI_BYTE, 0, shmem_comm);
55       if (mpi_errno) {
56         mpi_errno_ret += mpi_errno;
57       }
58     }
59
60     if (mpi_errno_ret)
61         mpi_errno = mpi_errno_ret;
62     return mpi_errno;
63 }
64
65 } // namespace simgrid::smpi