Loading...
Searching...
No Matches
plocalindex.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_PLOCALINDEX_HH
#define DUNE_COMMON_PARALLEL_PLOCALINDEX_HH
#include <iostream>
#if HAVE_MPI
#include <mpi.h>
#endif
#include <dune/common/parallel/indexset.hh>
#include <dune/common/parallel/localindex.hh>
#include <dune/common/parallel/mpitraits.hh>
namespace Dune
{
template<class T> class ParallelLocalIndex;
template<class T>
std::ostream& operator<<(std::ostream& os, const ParallelLocalIndex<T>& index)
{
os<<"{local="<<index.localIndex_<<", attr="<<T(index.attribute_)<<", public="
<<(index.public_ ? true : false)<<"}";
return os;
}
template<typename T>
class ParallelLocalIndex
{
#if HAVE_MPI
// friend declaration needed for MPITraits
friend struct MPITraits<ParallelLocalIndex<T> >;
#endif
friend std::ostream& operator<< <>(std::ostream& os, const ParallelLocalIndex<T>& index);
public:
typedef T Attribute;
ParallelLocalIndex(const Attribute& attribute, bool isPublic);
ParallelLocalIndex(size_t localIndex, const Attribute& attribute, bool isPublic=true);
ParallelLocalIndex();
#if 0
ParallelLocalIndex(const Attribute& attribute, size_t local, bool isPublic);
#endif
inline const Attribute attribute() const;
inline void setAttribute(const Attribute& attribute);
inline size_t local() const;
inline operator size_t() const;
inline ParallelLocalIndex<Attribute>& operator=(size_t index);
inline bool isPublic() const;
inline LocalIndexState state() const;
inline void setState(const LocalIndexState& state);
private:
size_t localIndex_;
char attribute_;
char public_;
char state_;
};
template<typename T>
bool operator==(const ParallelLocalIndex<T>& p1,
const ParallelLocalIndex<T>& p2)
{
if(p1.local()!=p2.local())
return false;
if(p1.attribute()!=p2.attribute())
return false;
if(p1.isPublic()!=p2.isPublic())
return false;
return true;
}
template<typename T>
bool operator!=(const ParallelLocalIndex<T>& p1,
const ParallelLocalIndex<T>& p2)
{
return !(p1==p2);
}
template<typename T>
struct LocalIndexComparator<ParallelLocalIndex<T> >
{
static bool compare(const ParallelLocalIndex<T>& t1,
const ParallelLocalIndex<T>& t2){
return t1.attribute()<t2.attribute();
}
};
#if HAVE_MPI
template<typename T>
class MPITraits<ParallelLocalIndex<T> >
{
public:
static MPI_Datatype getType();
private:
static MPI_Datatype type;
};
#endif
template<class T>
ParallelLocalIndex<T>::ParallelLocalIndex(const T& attribute, bool isPublic)
: localIndex_(0), attribute_(static_cast<char>(attribute)),
public_(static_cast<char>(isPublic)), state_(static_cast<char>(VALID))
{}
template<class T>
ParallelLocalIndex<T>::ParallelLocalIndex(size_t local, const T& attribute, bool isPublic)
: localIndex_(local), attribute_(static_cast<char>(attribute)),
public_(static_cast<char>(isPublic)), state_(static_cast<char>(VALID))
{}
template<class T>
ParallelLocalIndex<T>::ParallelLocalIndex()
: localIndex_(0), attribute_(), public_(static_cast<char>(false)),
state_(static_cast<char>(VALID))
{}
template<class T>
inline const T ParallelLocalIndex<T>::attribute() const
{
return T(attribute_);
}
template<class T>
inline void
ParallelLocalIndex<T>::setAttribute(const Attribute& attribute)
{
attribute_ = attribute;
}
template<class T>
inline size_t ParallelLocalIndex<T>::local() const
{
return localIndex_;
}
template<class T>
inline ParallelLocalIndex<T>::operator size_t() const
{
return localIndex_;
}
template<class T>
inline ParallelLocalIndex<T>&
ParallelLocalIndex<T>::operator=(size_t index)
{
localIndex_=index;
return *this;
}
template<class T>
inline bool ParallelLocalIndex<T>::isPublic() const
{
return static_cast<bool>(public_);
}
template<class T>
inline LocalIndexState ParallelLocalIndex<T>::state() const
{
return LocalIndexState(state_);
}
template<class T>
inline void ParallelLocalIndex<T>::setState(const LocalIndexState& state)
{
state_=static_cast<char>(state);
}
#if HAVE_MPI
template<typename T>
MPI_Datatype MPITraits<ParallelLocalIndex<T> >::getType()
{
if(type==MPI_DATATYPE_NULL) {
int length = 1;
MPI_Aint base, disp;
MPI_Datatype types[1] = {MPITraits<char>::getType()};
ParallelLocalIndex<T> rep;
MPI_Get_address(&rep, &base);
MPI_Get_address(&(rep.attribute_), &disp);
disp -= base;
MPI_Datatype tmp;
MPI_Type_create_struct(1, &length, &disp, types, &tmp);
MPI_Type_create_resized(tmp, 0, sizeof(ParallelLocalIndex<T>), &type);
MPI_Type_commit(&type);
MPI_Type_free(&tmp);
}
return type;
}
template<typename T>
MPI_Datatype MPITraits<ParallelLocalIndex<T> >::type = MPI_DATATYPE_NULL;
#endif // HAVE_MPI
} // namespace Dune
#endif // DUNE_COMMON_PARALLEL_PLOCALINDEX_HH
mpitraits.hh
Traits classes for mapping types onto MPI_Datatype.
indexset.hh
Provides a map between global and local indices.
localindex.hh
Provides classes for use as the local index in ParallelIndexSet.
Dune::operator<<
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition bigunsignedint.hh:301
Dune::ParallelLocalIndex::isPublic
bool isPublic() const
Check whether the index might also be known other processes.
Definition plocalindex.hh:273
Dune::ParallelLocalIndex::setAttribute
void setAttribute(const Attribute &attribute)
Set the attribute of the index.
Definition plocalindex.hh:247
Dune::ParallelLocalIndex::local
size_t local() const
get the local index.
Definition plocalindex.hh:253
Dune::LocalIndexState
LocalIndexState
The states available for the local indices.
Definition localindex.hh:28
Dune::ParallelLocalIndex::setState
void setState(const LocalIndexState &state)
Set the state.
Definition plocalindex.hh:285
Dune::MPITraits< ParallelLocalIndex< T > >::getType
static MPI_Datatype getType()
Definition plocalindex.hh:293
Dune::ParallelLocalIndex::operator=
ParallelLocalIndex< Attribute > & operator=(size_t index)
Assign a new local index.
Definition plocalindex.hh:266
Dune::ParallelLocalIndex::state
LocalIndexState state() const
Get the state.
Definition plocalindex.hh:279
Dune::ParallelLocalIndex::ParallelLocalIndex
ParallelLocalIndex(const Attribute &attribute, bool isPublic)
Constructor.
Definition plocalindex.hh:221
Dune::ParallelLocalIndex::ParallelLocalIndex
ParallelLocalIndex()
Parameterless constructor.
Definition plocalindex.hh:234
Dune::ParallelLocalIndex::attribute
const Attribute attribute() const
Get the attribute of the index.
Definition plocalindex.hh:240
Dune::VALID
@ VALID
Definition localindex.hh:28
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::operator!=
constexpr auto operator!=(const HybridMultiIndex< S... > &lhs, const HybridMultiIndex< T... > &rhs)
Compare two HybridMultiIndexs for inequality.
Definition hybridmultiindex.hh:441
Dune::operator==
constexpr bool operator==(const HybridMultiIndex< S... > &lhs, const HybridMultiIndex< T... > &rhs)
Compare two HybridMultiIndexs for value equality.
Definition hybridmultiindex.hh:404
Dune::MPITraits
A traits class describing the mapping of types onto MPI_Datatypes.
Definition mpitraits.hh:41
Dune::MPITraits::getType
static MPI_Datatype getType()
Definition mpitraits.hh:48
Dune::LocalIndexComparator
Definition indexset.hh:615
Dune::ParallelLocalIndex
An index present on the local process with an additional attribute flag.
Definition plocalindex.hh:52
Dune::ParallelLocalIndex::Attribute
T Attribute
The type of the attributes. Normally this will be an enumeration like.
Definition plocalindex.hh:67
Dune::LocalIndexComparator< ParallelLocalIndex< T > >::compare
static bool compare(const ParallelLocalIndex< T > &t1, const ParallelLocalIndex< T > &t2)
Definition plocalindex.hh:198
Dune::type