Logo AND Algorithmique Numérique Distribuée

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