11 namespace accumulators {
22 : m_variant(rhs.m_variant)
34 struct accumulator_wrapper::merge_visitor:
public boost::static_visitor<> {
45 const P* rhs_ptr=boost::get<P>(& rhs_acc.m_variant);
46 if (!rhs_ptr)
throw std::runtime_error(
"Only accumulators of the same type can be merged" 48 detail::check_ptr(*rhs_ptr);
49 lhs_ptr->merge(**rhs_ptr);
53 merge_visitor visitor(rhs_acc);
61 struct accumulator_wrapper::copy_visitor:
public boost::static_visitor<> {
68 acc_wrap_.m_variant=T(val->clone());
74 copy_visitor vis(result);
81 copy_visitor vis(*result);
90 struct accumulator_wrapper::assign_visitor:
public boost::static_visitor<> {
92 template<
typename T>
void operator()(T & arg)
const {
93 self->m_variant = arg;
106 struct count_visitor:
public boost::static_visitor<boost::uint64_t> {
107 template<
typename T> boost::uint64_t
operator()(T
const & arg)
const {
108 detail::check_ptr(arg);
113 count_visitor visitor;
121 struct save_visitor:
public boost::static_visitor<> {
123 template<
typename T>
void operator()(T & arg)
const {
124 detail::check_ptr(arg);
137 struct load_visitor:
public boost::static_visitor<> {
139 template<
typename T>
void operator()(T
const & arg)
const {
140 detail::check_ptr(arg);
153 struct reset_visitor:
public boost::static_visitor<> {
154 template<
typename T>
void operator()(T
const & arg)
const {
155 detail::check_ptr(arg);
167 struct result_visitor:
public boost::static_visitor<> {
168 template<
typename T>
void operator()(T
const & arg) {
169 detail::check_ptr(arg);
170 value = std::shared_ptr<result_wrapper>(
new result_wrapper(arg->result()));
172 std::shared_ptr<result_wrapper> value;
175 result_visitor visitor;
177 return visitor.value;
184 struct print_visitor:
public boost::static_visitor<> {
185 print_visitor(std::ostream & o,
bool t): os(o), terse(t) {}
186 template<
typename T>
void operator()(T
const & arg)
const {
187 detail::check_ptr(arg);
188 arg->print(os, terse);
202 struct collective_merge_visitor:
public boost::static_visitor<> {
204 template<
typename T>
void operator()(T & arg)
const { arg->collective_merge(comm, root); }
205 template<
typename T>
void operator()(T
const & arg)
const { arg->collective_merge(comm, root); }
221 arg.
print(os,
false);
226 std::ostringstream ostr;
227 arg.
print(ostr,
true);
233 std::ostringstream ostr;
234 arg.
print(ostr,
false);
accumulator_wrapper()
default constructor
void operator()(T const &value)
detail::printable_type short_print(const result_wrapper &arg)
Return an "ostream-able" object to print result in a terse format.
Encapsulation of an MPI communicator and some communicator-related operations.
accumulator_wrapper & operator=(std::shared_ptr< accumulator_wrapper > const &rhs)
boost::uint64_t count() const
F::result_type apply_visitor(F &visitor, dictionary::const_iterator it)
Const-access visitor to a value by an iterator.
void load(hdf5::archive &ar)
detail::printable_type full_print(const result_wrapper &arg)
Return an "ostream-able" object to print result in a verbose format.
void merge(const accumulator_wrapper &rhs_acc)
Merge another accumulator into this one.
void save(hdf5::archive &ar) const
std::shared_ptr< result_wrapper > result() const
int rank() const
Returns process rank in this communicator.
T r(T x, T y=T(), T z=T())
accumulator_wrapper * new_clone() const
Returns a pointer to a new-allocated copy with the wrapped accumulator cloned.
accumulator_wrapper & operator<<(T const &value)
void print(std::ostream &os, bool terse=false) const
accumulator_wrapper clone() const
Returns a copy with the wrapped accumulator cloned.