Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:52:44

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file corecel/sys/detail/MpiCommunicatorImpl.hh
0006 //! \brief Type definitions for MPI parallel operations (MPI optional)
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Config.hh"
0011 
0012 #if CELERITAS_USE_MPI
0013 #    include <mpi.h>
0014 #endif
0015 
0016 namespace celeritas
0017 {
0018 namespace detail
0019 {
0020 //---------------------------------------------------------------------------//
0021 #if CELERITAS_USE_MPI
0022 
0023 //! Opaque MPI communicator
0024 using MpiComm = MPI_Comm;
0025 
0026 #else
0027 
0028 //!@{
0029 //! Mock MPI communicator
0030 struct MpiComm
0031 {
0032     int value_;
0033 };
0034 
0035 constexpr inline bool operator==(MpiComm a, MpiComm b)
0036 {
0037     return a.value_ == b.value_;
0038 }
0039 
0040 constexpr inline bool operator!=(MpiComm a, MpiComm b)
0041 {
0042     return !(a == b);
0043 }
0044 //!@}
0045 
0046 #endif
0047 
0048 //---------------------------------------------------------------------------//
0049 //! Used for invalid comm handles
0050 inline MpiComm mpi_comm_null()
0051 {
0052 #if CELERITAS_USE_MPI
0053     return MPI_COMM_NULL;
0054 #else
0055     return {0};
0056 #endif
0057 }
0058 
0059 //! Communicator for all processes
0060 inline MpiComm mpi_comm_world()
0061 {
0062 #if CELERITAS_USE_MPI
0063     return MPI_COMM_WORLD;
0064 #else
0065     return {1};
0066 #endif
0067 }
0068 
0069 //! Communicator with only the local process
0070 inline MpiComm mpi_comm_self()
0071 {
0072 #if CELERITAS_USE_MPI
0073     return MPI_COMM_SELF;
0074 #else
0075     return {-1};
0076 #endif
0077 }
0078 
0079 //---------------------------------------------------------------------------//
0080 }  // namespace detail
0081 }  // namespace celeritas