1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5 
6 #include "mpiimpl.h"
7 
MPIR_Barrier_intra_smp(MPIR_Comm * comm_ptr,MPIR_Errflag_t * errflag)8 int MPIR_Barrier_intra_smp(MPIR_Comm * comm_ptr, MPIR_Errflag_t * errflag)
9 {
10     int mpi_errno = MPI_SUCCESS;
11     int mpi_errno_ret = MPI_SUCCESS;
12 
13     MPIR_Assert(MPIR_Comm_is_parent_comm(comm_ptr));
14 
15     /* do the intranode barrier on all nodes */
16     if (comm_ptr->node_comm != NULL) {
17         mpi_errno = MPIR_Barrier(comm_ptr->node_comm, errflag);
18         if (mpi_errno) {
19             /* for communication errors, just record the error but continue */
20             *errflag =
21                 MPIX_ERR_PROC_FAILED ==
22                 MPIR_ERR_GET_CLASS(mpi_errno) ? MPIR_ERR_PROC_FAILED : MPIR_ERR_OTHER;
23             MPIR_ERR_SET(mpi_errno, *errflag, "**fail");
24             MPIR_ERR_ADD(mpi_errno_ret, mpi_errno);
25         }
26     }
27 
28     /* do the barrier across roots of all nodes */
29     if (comm_ptr->node_roots_comm != NULL) {
30         mpi_errno = MPIR_Barrier(comm_ptr->node_roots_comm, errflag);
31         if (mpi_errno) {
32             /* for communication errors, just record the error but continue */
33             *errflag =
34                 MPIX_ERR_PROC_FAILED ==
35                 MPIR_ERR_GET_CLASS(mpi_errno) ? MPIR_ERR_PROC_FAILED : MPIR_ERR_OTHER;
36             MPIR_ERR_SET(mpi_errno, *errflag, "**fail");
37             MPIR_ERR_ADD(mpi_errno_ret, mpi_errno);
38         }
39     }
40 
41     /* release the local processes on each node with a 1-byte
42      * broadcast (0-byte broadcast just returns without doing
43      * anything) */
44     if (comm_ptr->node_comm != NULL) {
45         int i = 0;
46         mpi_errno = MPIR_Bcast(&i, 1, MPI_BYTE, 0, comm_ptr->node_comm, errflag);
47         if (mpi_errno) {
48             /* for communication errors, just record the error but continue */
49             *errflag =
50                 MPIX_ERR_PROC_FAILED ==
51                 MPIR_ERR_GET_CLASS(mpi_errno) ? MPIR_ERR_PROC_FAILED : MPIR_ERR_OTHER;
52             MPIR_ERR_SET(mpi_errno, *errflag, "**fail");
53             MPIR_ERR_ADD(mpi_errno_ret, mpi_errno);
54         }
55     }
56 
57     if (mpi_errno_ret)
58         mpi_errno = mpi_errno_ret;
59     else if (*errflag != MPIR_ERR_NONE)
60         MPIR_ERR_SET(mpi_errno, *errflag, "**coll_fail");
61     return mpi_errno;
62 }
63