msg_util.h
Go to the documentation of this file.
#ifndef _RHEO_MSG_UTIL_H
#define _RHEO_MSG_UTIL_H
//
// message exchange basic algorithms
// implemented with MPI
//
// author: Pierre.Saramito@imag.fr
//
// date: 17 december 1998
//
# include "rheolef/distributed.h"
namespace rheolef {
// bugs in MPI...
#ifndef RHEO_MPI_PRUDENCE
#define RHEO_MPI_PRUDENCE 0
#endif
// there is a non-standard SGI extension like that:
template <class T1, class T2>
struct select1st : std::unary_function<std::pair<T1,T2>, T1> {
T1 operator() (const std::pair<T1,T2>& x) const { return x.first; }
};
template <class T1, class T2>
struct select2nd : std::unary_function<std::pair<T1,T2>, T2> {
T2 operator() (const std::pair<T1,T2>& x) const { return x.second; }
};
// always true predicate
template <class T>
struct always_true : std::unary_function<T,bool> {
bool operator()(const T& x) const { return true; }
};
// operator :=
template <class T1, class T2>
struct set_op : std::binary_function<T1,T2,T1> {
T1& operator()(T1& x, const T2& y) const { return x = y; }
};
// operator +=
template <class T1, class T2>
struct set_add_op : std::binary_function<T1,T2,T1> {
T1& operator()(T1& x, const T2& y) const { return x += y; }
};
// dummy iterator, when an iterator is required but
// we have no usage.
template <class T, class Distance = std::ptrdiff_t>
class dummy_iterator : public std::iterator<std::input_iterator_tag, T, Distance, const T*, const T&> {
public:
dummy_iterator<T,Distance>& operator++() { return *this; }
dummy_iterator<T,Distance> operator++(int) { return *this; }
T& operator*() { return _dummy; }
const T& operator*() const { return _dummy; }
dummy_iterator() : _dummy() {}
protected:
T _dummy;
};
// index iterator, simulates array[i] = i
template <class Size, class Distance = std::ptrdiff_t>
class index_iterator : public std::iterator<std::input_iterator_tag, Size, Distance, const Size*, const Size&> {
public:
index_iterator& operator++() { _i++; return *this; }
index_iterator operator++(int) {
index_iterator<Size,Distance> tmp = *this;
_i++;
return tmp;
}
const Size& operator*() const { return _i; }
const Size& operator[](const Size& i) const { return i; }
bool operator==(const index_iterator<Size,Distance>& x) const{
return x._i == _i; }
bool operator!=(const index_iterator<Size,Distance>& x) const{
return !(x._i == _i); }
index_iterator(Size i0 = 0) : _i(i0) {}
protected:
Size _i;
};
// f1(pair x) = x.first
template <class Pair>
struct first_op
: public std::unary_function<Pair,typename Pair::first_type> {
typename std::unary_function<Pair,typename Pair::first_type>::result_type
operator()(const Pair& x) const {
return x.first; }
};
// f2(pair x) = x.second
template <class Pair>
struct second_op
: public std::unary_function<Pair, typename Pair::second_type> {
typename std::unary_function<Pair,typename Pair::second_type>::result_type
operator()(const Pair& x) const {
return x.second; }
};
// pair<const uint, T> and pair<uint, T> are not compatible
// for some C++; so convert it explicitly:
template<class Pair1, class Pair2>
struct pair_identity : public std::unary_function<Pair1, Pair2> {
Pair2 operator()(const Pair1& x) const {
return Pair2(x.first, x.second); }
};
// wrapper iterator class that applies an operator
template <class Iterator, class Operator>
class apply_iterator : public std::iterator_traits<Iterator> {
public:
typedef typename Operator::result_type value_type;
apply_iterator(Iterator i1, Operator op1)
: i(i1), op(op1) {}
apply_iterator& operator++() {
i++; return *this; }
apply_iterator operator++(int) {
apply_iterator t = *this; i++; return t; }
value_type operator*() const { return op(*i); }
bool operator== (apply_iterator<Iterator,Operator> b) const{ return (i == b.i); }
bool operator!= (apply_iterator<Iterator,Operator> b) const{ return (i != b.i); }
protected:
Iterator i;
Operator op;
};
template <class Iterator, class Operator>
inline
apply_iterator<Iterator,Operator>
make_apply_iterator(Iterator i, Operator op) {
return apply_iterator<Iterator,Operator>(i,op);
}
// some c++ cannot convert pair<const I,T> to pair<I,T>:
template <class InputIterator, class OutputIterator>
OutputIterator
msg_pair_copy(InputIterator input, InputIterator last,
OutputIterator result) {
while (input != last) {
(*result).first = (*input).first;
(*result++).second = (*input++).second;
}
return result;
}
} // namespace rheolef
#endif // _RHEO_MSG_UTIL_H
rheolef::apply_iterator
Definition: msg_util.h:123
rheolef::apply_iterator::operator==
bool operator==(apply_iterator< Iterator, Operator > b) const
Definition: msg_util.h:133
rheolef::apply_iterator::op
Operator op
Definition: msg_util.h:137
rheolef::apply_iterator::i
Iterator i
Definition: msg_util.h:136
rheolef::apply_iterator::operator!=
bool operator!=(apply_iterator< Iterator, Operator > b) const
Definition: msg_util.h:134
rheolef::apply_iterator::apply_iterator
apply_iterator(Iterator i1, Operator op1)
Definition: msg_util.h:126
rheolef::apply_iterator::operator++
apply_iterator & operator++()
Definition: msg_util.h:128
rheolef::apply_iterator::operator*
value_type operator*() const
Definition: msg_util.h:132
rheolef::apply_iterator::operator++
apply_iterator operator++(int)
Definition: msg_util.h:130
rheolef::apply_iterator::value_type
Operator::result_type value_type
Definition: msg_util.h:125
rheolef::dummy_iterator
Definition: msg_util.h:67
rheolef::dummy_iterator::operator++
dummy_iterator< T, Distance > operator++(int)
Definition: msg_util.h:70
rheolef::dummy_iterator::operator*
const T & operator*() const
Definition: msg_util.h:72
rheolef::dummy_iterator::_dummy
T _dummy
Definition: msg_util.h:75
rheolef::dummy_iterator::dummy_iterator
dummy_iterator()
Definition: msg_util.h:73
rheolef::dummy_iterator::operator*
T & operator*()
Definition: msg_util.h:71
rheolef::dummy_iterator::operator++
dummy_iterator< T, Distance > & operator++()
Definition: msg_util.h:69
rheolef::index_iterator
Definition: msg_util.h:79
rheolef::index_iterator::_i
Size _i
Definition: msg_util.h:95
rheolef::index_iterator::operator[]
const Size & operator[](const Size &i) const
Definition: msg_util.h:88
rheolef::index_iterator::operator!=
bool operator!=(const index_iterator< Size, Distance > &x) const
Definition: msg_util.h:91
rheolef::index_iterator::operator*
const Size & operator*() const
Definition: msg_util.h:87
rheolef::index_iterator::operator==
bool operator==(const index_iterator< Size, Distance > &x) const
Definition: msg_util.h:89
rheolef::index_iterator::index_iterator
index_iterator(Size i0=0)
Definition: msg_util.h:93
rheolef::index_iterator::operator++
index_iterator operator++(int)
Definition: msg_util.h:82
rheolef::index_iterator::operator++
index_iterator & operator++()
Definition: msg_util.h:81
T
Expr1::float_type T
Definition: field_expr.h:261
mkgeo_ball.b
int b
Definition: mkgeo_ball.sh:152
mkgeo_ball.tmp
tmp
Definition: mkgeo_ball.sh:380
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::msg_pair_copy
OutputIterator msg_pair_copy(InputIterator input, InputIterator last, OutputIterator result)
Definition: msg_util.h:148
rheolef::make_apply_iterator
apply_iterator< Iterator, Operator > make_apply_iterator(Iterator i, Operator op)
Definition: msg_util.h:142
rheolef::always_true
Definition: msg_util.h:51
rheolef::always_true::operator()
bool operator()(const T &x) const
Definition: msg_util.h:52
rheolef::first_op
Definition: msg_util.h:101
rheolef::first_op::operator()
std::unary_function< Pair, typename Pair::first_type >::result_type operator()(const Pair &x) const
Definition: msg_util.h:103
rheolef::pair_identity
Definition: msg_util.h:117
rheolef::pair_identity::operator()
Pair2 operator()(const Pair1 &x) const
Definition: msg_util.h:118
rheolef::second_op
Definition: msg_util.h:109
rheolef::second_op::operator()
std::unary_function< Pair, typename Pair::second_type >::result_type operator()(const Pair &x) const
Definition: msg_util.h:111
rheolef::select1st
Definition: msg_util.h:41
rheolef::select1st::operator()
T1 operator()(const std::pair< T1, T2 > &x) const
Definition: msg_util.h:42
rheolef::select2nd
Definition: msg_util.h:45
rheolef::select2nd::operator()
T2 operator()(const std::pair< T1, T2 > &x) const
Definition: msg_util.h:46
rheolef::set_add_op
Definition: msg_util.h:61
rheolef::set_add_op::operator()
T1 & operator()(T1 &x, const T2 &y) const
Definition: msg_util.h:62
rheolef::set_op
Definition: msg_util.h:56
rheolef::set_op::operator()
T1 & operator()(T1 &x, const T2 &y) const
Definition: msg_util.h:57