File mpitypeconstants.h
File List > code_source > templat > include > TempLat > parallel > mpi > mpitypeconstants.h
Go to the documentation of this file
#ifndef TEMPLAT_PARALLEL_MPI_MPITYPECONSTANTS_H
#define TEMPLAT_PARALLEL_MPI_MPITYPECONSTANTS_H
/* This file is part of TempLat, available at https://cosmolattice.github.io/templat .
Copyright 2021-2026 The TempLat authors, see AUTHORS.md.
Released under the MIT license, see LICENSE.md. */
// File info: Main contributor(s): Wessel Valkenburg, Year: 2019
#include <type_traits>
#include <concepts>
#ifdef HAVE_MPI
#include <mpi.h>
#else
typedef int MPI_Comm;
#ifndef MPI_COMM_WORLD
#define MPI_COMM_WORLD 1
#endif
#ifndef MPI_COMM_NULL
#define MPI_COMM_NULL 1
#endif
typedef int MPI_Op;
typedef int MPI_Datatype;
typedef int MPI_Status;
#endif
namespace TempLat
{
#ifdef HAVE_MPI
template <typename T>
requires std::is_same_v<char, T>
constexpr MPI_Datatype MPITypeSelect()
{
return MPI_CHAR;
}
template <typename T>
requires std::is_same_v<bool, T>
constexpr MPI_Datatype MPITypeSelect()
{
return MPI_CXX_BOOL;
}
template <typename T>
requires std::is_same_v<float, T>
constexpr MPI_Datatype MPITypeSelect()
{
return MPI_FLOAT;
}
template <typename T>
requires std::is_same_v<T, double>
constexpr MPI_Datatype MPITypeSelect()
{
return MPI_DOUBLE;
}
template <typename T>
requires std::is_same_v<int, T>
constexpr MPI_Datatype MPITypeSelect()
{
return MPI_INT;
}
template <typename T>
requires std::is_same_v<long int, T>
constexpr MPI_Datatype MPITypeSelect()
{
return MPI_LONG;
}
template <typename T>
requires std::is_same_v<long long int, T>
constexpr MPI_Datatype MPITypeSelect()
{
return MPI_LONG_LONG_INT;
}
template <typename T>
requires std::is_same_v<unsigned long int, T>
constexpr MPI_Datatype MPITypeSelect()
{
return MPI_UNSIGNED_LONG;
}
template <typename T>
requires std::is_same_v<unsigned long long int, T>
constexpr MPI_Datatype MPITypeSelect()
{
return MPI_UNSIGNED_LONG_LONG;
}
template <typename T>
concept HasToMPIDataType = requires {
{ T::getMPIType() } -> std::same_as<MPI_Datatype>;
};
template <typename T>
requires HasToMPIDataType<T>
constexpr MPI_Datatype MPITypeSelect()
{
return T::getMPIType();
}
#else
template <typename T> constexpr MPI_Datatype MPITypeSelect() { return 0; }
// maximum
#define MPI_MAX 0
// minimum
#define MPI_MIN 0
// sum
#define MPI_SUM 0
// product
#define MPI_PROD 0
// logical and
#define MPI_LAND 0
// bit-wise and
#define MPI_BAND 0
// logical or
#define MPI_LOR 0
// bit-wise or
#define MPI_BOR 0
// logical xor
#define MPI_LXOR 0
// bit-wise xor
#define MPI_BXOR 0
// max value and location
#define MPI_MAXLOC 0
// min value and location
#define MPI_MINLOC 0
#endif
class MPITypeConstants
{
};
} // namespace TempLat
#endif