Loading...
Searching...
No Matches
mpidata.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_PARALLEL_MPIDATA_HH
#define DUNE_COMMON_PARALLEL_MPIDATA_HH
#if HAVE_MPI
#include <vector>
#include <string>
#include <type_traits>
#include <dune/common/typetraits.hh>
#include <dune/common/std/type_traits.hh>
#include <dune/common/parallel/mpitraits.hh>
namespace Dune{
template<class, class = void>
struct MPIData;
template<class T>
auto getMPIData(T& t){
return MPIData<T>(t);
}
// Default implementation for static datatypes
template<class T, class Enable>
struct MPIData
{
friend auto getMPIData<T>(T&);
protected:
T& data_;
MPIData(T& t)
: data_(t)
{}
public:
void* ptr() const {
return (void*)&data_;
}
// indicates whether the datatype can be resized
static constexpr bool static_size = true;
int size() const{
return 1;
}
MPI_Datatype type() const {
return MPITraits<std::decay_t<T>>::getType();
}
};
// dummy implementation for void
template<>
struct MPIData<void>{
protected:
MPIData() {}
public:
void* ptr(){
return nullptr;
}
int size(){
return 0;
}
void get(){}
MPI_Datatype type() const{
return MPI_INT;
}
};
// specializations:
// std::vector of static sized elements or std::string
template<class T>
struct MPIData<T, std::void_t<std::tuple<decltype(std::declval<T>().data()),
decltype(std::declval<T>().size()),
typename std::decay_t<T>::value_type>>>{
private:
template<class U>
using hasResizeOp = decltype(std::declval<U>().resize(0));
protected:
friend auto getMPIData<T>(T&);
MPIData(T& t)
: data_(t)
{}
public:
static constexpr bool static_size = std::is_const<T>::value || !Std::is_detected_v<hasResizeOp, T>;
void* ptr() {
return (void*) data_.data();
}
int size() {
return data_.size();
}
MPI_Datatype type() const{
return MPITraits<typename std::decay_t<T>::value_type>::getType();
}
template<class S = T>
auto /*void*/ resize(int size)
-> std::enable_if_t<!std::is_const<S>::value || !Std::is_detected_v<hasResizeOp, S>>
{
data_.resize(size);
}
protected:
T& data_;
};
}
#endif // HAVE_MPI
#endif // DUNE_COMMON_PARALLEL_MPIDATA_HH
mpitraits.hh
Traits classes for mapping types onto MPI_Datatype.
typetraits.hh
Traits for type conversions and type information.
type_traits.hh
Dune::void_t
typename Impl::voider< Types... >::type void_t
Is void for all valid input types. The workhorse for C++11 SFINAE-techniques.
Definition typetraits.hh:40
std
STL namespace.
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::getMPIData
auto getMPIData(T &t)
Definition mpidata.hh:44
Dune::MPITraits
A traits class describing the mapping of types onto MPI_Datatypes.
Definition mpitraits.hh:41
Dune::MPIData
Definition mpidata.hh:51
Dune::MPIData::getMPIData
friend auto getMPIData(T &)
Definition mpidata.hh:44
Dune::MPIData::data_
T & data_
Definition mpidata.hh:54
Dune::MPIData::type
MPI_Datatype type() const
Definition mpidata.hh:72
Dune::MPIData::ptr
void * ptr() const
Definition mpidata.hh:61
Dune::MPIData::size
int size() const
Definition mpidata.hh:68
Dune::MPIData::static_size
static constexpr bool static_size
Definition mpidata.hh:66
Dune::MPIData::MPIData
MPIData(T &t)
Definition mpidata.hh:56
Dune::MPIData< void >::get
void get()
Definition mpidata.hh:90
Dune::MPIData< void >::MPIData
MPIData()
Definition mpidata.hh:81
Dune::MPIData< void >::size
int size()
Definition mpidata.hh:87
Dune::MPIData< void >::ptr
void * ptr()
Definition mpidata.hh:84
Dune::MPIData< void >::type
MPI_Datatype type() const
Definition mpidata.hh:91
Dune::MPIData< T, std::void_t< std::tuple< decltype(std::declval< T >().data()), decltype(std::declval< T >().size()), typename std::decay_t< T >::value_type > > >::MPIData
MPIData(T &t)
Definition mpidata.hh:108
Dune::MPIData< T, std::void_t< std::tuple< decltype(std::declval< T >().data()), decltype(std::declval< T >().size()), typename std::decay_t< T >::value_type > > >::ptr
void * ptr()
Definition mpidata.hh:113
Dune::MPIData< T, std::void_t< std::tuple< decltype(std::declval< T >().data()), decltype(std::declval< T >().size()), typename std::decay_t< T >::value_type > > >::static_size
static constexpr bool static_size
Definition mpidata.hh:112
Dune::MPIData< T, std::void_t< std::tuple< decltype(std::declval< T >().data()), decltype(std::declval< T >().size()), typename std::decay_t< T >::value_type > > >::size
int size()
Definition mpidata.hh:116
Dune::MPIData< T, std::void_t< std::tuple< decltype(std::declval< T >().data()), decltype(std::declval< T >().size()), typename std::decay_t< T >::value_type > > >::data_
T & data_
Definition mpidata.hh:131
Dune::MPIData< T, std::void_t< std::tuple< decltype(std::declval< T >().data()), decltype(std::declval< T >().size()), typename std::decay_t< T >::value_type > > >::resize
auto resize(int size) -> std::enable_if_t<!std::is_const< S >::value||!Std::is_detected_v< hasResizeOp, S > >
Definition mpidata.hh:124
Dune::MPIData< T, std::void_t< std::tuple< decltype(std::declval< T >().data()), decltype(std::declval< T >().size()), typename std::decay_t< T >::value_type > > >::type
MPI_Datatype type() const
Definition mpidata.hh:119