Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git] / src / smpi / colls / barrier / barrier-mpich-smp.cpp
1 /* Copyright (c) 2013-2019. 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{
19 namespace smpi{
20 int Coll_barrier_mpich_smp::barrier(MPI_Comm comm)
21 {
22     int mpi_errno = MPI_SUCCESS;
23     int mpi_errno_ret = MPI_SUCCESS;
24     MPI_Comm shmem_comm = MPI_COMM_NULL, leader_comm = MPI_COMM_NULL;
25     int local_rank = -1;
26     
27     if(comm->get_leaders_comm()==MPI_COMM_NULL){
28       comm->init_smp();
29     }
30
31     shmem_comm = comm->get_intra_comm();
32     local_rank = shmem_comm->rank();
33     /* do the intranode barrier on all nodes */
34     if (shmem_comm != NULL) {
35         mpi_errno = Coll_barrier_mpich::barrier(shmem_comm);
36         if (mpi_errno) {
37           mpi_errno_ret+=mpi_errno;
38         }
39     }
40
41     leader_comm = comm->get_leaders_comm();
42     /* do the barrier across roots of all nodes */
43     if (leader_comm != NULL && local_rank == 0) {
44         mpi_errno = Coll_barrier_mpich::barrier(leader_comm);
45         if (mpi_errno) {
46           mpi_errno_ret+=mpi_errno;
47         }
48     }
49
50     /* release the local processes on each node with a 1-byte
51      * broadcast (0-byte broadcast just returns without doing
52      * anything) */
53     if (shmem_comm != NULL) {
54         int i = 0;
55         mpi_errno = Coll_bcast_mpich::bcast(&i, 1, MPI_BYTE, 0, shmem_comm);
56         if (mpi_errno) {
57           mpi_errno_ret+=mpi_errno;
58         }
59     }
60
61     if (mpi_errno_ret)
62         mpi_errno = mpi_errno_ret;
63     return mpi_errno;
64 }
65
66 }
67 }
68