Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:49

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