/usr/include/dune/common/parallel/plocalindex.hh is in libdune-common-dev 2.3.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// $Id$
#ifndef DUNE_PLOCALINDEX_HH
#define DUNE_PLOCALINDEX_HH
#include "localindex.hh"
#include "indexset.hh"
#include "mpitraits.hh"
#include <iostream>
namespace Dune
{
/** @addtogroup Common_Parallel
*
* @{
*/
/**
* @file
* @brief Provides classes for use as the local index in ParallelIndexSet for distributed computing.
* @author Markus Blatt
*/
template<class T> class ParallelLocalIndex;
/**
* @brief Print the local index to a stream.
* @param os The output stream to print to.
* @param index The index to print.
*/
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;
}
/**
* @brief An index present on the local process with an additional attribute flag.
*/
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:
/**
* @brief The type of the attributes.
* Normally this will be an enumeration like
* <pre>
* enum Attributes{owner, border, overlap};
* </pre>
*/
typedef T Attribute;
/**
* @brief Constructor.
*
* The local index will be initialized to 0.
* @param attribute The attribute of the index.
* @param isPublic True if the index might also be
* known to other processes.
*/
ParallelLocalIndex(const Attribute& attribute, bool isPublic);
/**
* @brief Constructor.
*
* @param localIndex The local index.
* @param attribute The attribute of the index.
* @param isPublic True if the index might also be
* known to other processes.
*/
ParallelLocalIndex(size_t localIndex, const Attribute& attribute, bool isPublic=true);
/**
* @brief Parameterless constructor.
*
* Needed for use in container classes.
*/
ParallelLocalIndex();
#if 0
/**
* @brief Constructor.
* @param globalIndex The global index.
* @param attribute The attribute of the index.
* @param local The local index.
* @param isPublic True if the index might also be
* known to other processes.
*
*/
ParallelLocalIndex(const Attribute& attribute, size_t local, bool isPublic);
#endif
/**
* @brief Get the attribute of the index.
* @return The associated attribute.
*/
inline const Attribute attribute() const;
/**
* @brief Set the attribute of the index.
* @param attribute The associated attribute.
*/
inline void setAttribute(const Attribute& attribute);
/**
* @brief get the local index.
* @return The local index.
*/
inline size_t local() const;
/**
* @brief Convert to the local index represented by an int.
*/
inline operator size_t() const;
/**
* @brief Assign a new local index.
*
* @param index The new local index.
*/
inline ParallelLocalIndex<Attribute>& operator=(size_t index);
/**
* @brief Check whether the index might also be known other processes.
* @return True if the index might be known to other processors.
*/
inline bool isPublic() const;
/**
* @brief Get the state.
* @return The state.
*/
inline LocalIndexState state() const;
/**
* @brief Set the state.
* @param state The state to set.
*/
inline void setState(const LocalIndexState& state);
private:
/** @brief The local index. */
size_t localIndex_;
/** @brief An attribute for the index. */
char attribute_;
/** @brief True if the index is also known to other processors. */
char public_;
/**
* @brief The state of the index.
*
* Has to be one of LocalIndexState!
* @see LocalIndexState.
*/
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
//! \todo Please doc me!
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[3];
MPI_Aint disp[3];
MPI_Datatype types[3] = {MPI_LB, MPITraits<char>::getType(), MPI_UB};
ParallelLocalIndex<T> rep[2];
length[0]=length[1]=length[2]=1;
MPI_Address(rep, disp); // lower bound of the datatype
MPI_Address(&(rep[0].attribute_), disp+1);
MPI_Address(rep+1, disp+2); // upper bound of the datatype
for(int i=2; i >= 0; --i)
disp[i] -= disp[0];
MPI_Type_struct(3, length, disp, types, &type);
MPI_Type_commit(&type);
}
return type;
}
template<typename T>
MPI_Datatype MPITraits<ParallelLocalIndex<T> >::type = MPI_DATATYPE_NULL;
#endif
/** @} */
} // namespace Dune
#endif
|