Loading...
Searching...
No Matches
scatter_message.h
Go to the documentation of this file.
#ifndef _RHEOLEF_SCATTER_MESSAGE_H
#define _RHEOLEF_SCATTER_MESSAGE_H
//
// create distributed to sequential scatter context
// inspirated from petsc-2.0/vpscat.c: VecScatterCreate_PtoS(...)
//
#include "rheolef/compiler.h"
#ifdef _RHEOLEF_HAVE_MPI
namespace rheolef {
template<class Container, bool T_is_MPI_simple = false>
class scatter_message {};
// =====================================================================================
// when Container::value_type is a fixed-size type (i.e. a simple MPI data type)
// =====================================================================================
template<class Container>
class scatter_message<Container,false> {
public:
typedef typename Container::size_type size_type;
typedef typename Container::value_type value_type;
typedef typename Container::allocator_type allocator_type;
typedef value_type base_value_type;
// data:
protected:
value_type _init_value;
Container _values; // n_data
std::vector<size_type> _indices; // n_data
std::vector<size_type> _procs; // n_proc
std::vector<size_type> _starts; // n_proc+1
public:
// data accessors:
const Container& values () const { return _values; }
Container& values () { return _values; }
const std::vector<size_type>& indices() const { return _indices; }
std::vector<size_type>& indices() { return _indices; }
const std::vector<size_type>& procs () const { return _procs; }
std::vector<size_type>& procs () { return _procs; }
const std::vector<size_type>& starts () const { return _starts; }
std::vector<size_type>& starts () { return _starts; }
std::list<std::pair<size_type,mpi::request> > requests; // n_proc
std::vector<mpi::status> sstatus; // n_status
std::vector<size_type> local_slots; // n_local
std::vector<size_type> local_slots_nonmatching;
bool local_nonmatching_computed;// n_local_nonmatching
size_type local_n_nonmatching;
bool local_is_copy;
size_type local_copy_start;
size_type local_copy_length;
// allocator:
scatter_message(const value_type& init_value = value_type(), const allocator_type& alloc = allocator_type())
: _init_value (init_value),
_values(alloc),
_indices(),
_procs(),
_starts(),
requests(),
sstatus(),
local_slots(),
local_slots_nonmatching(),
local_nonmatching_computed(false),
local_n_nonmatching(0),
local_is_copy(false),
local_copy_start(0),
local_copy_length(0)
{}
void resize (size_type n_data, size_type nproc) {
_values.resize (n_data, _init_value);
_indices.resize (n_data);
_procs.resize (nproc);
_starts.resize (nproc+1);
}
template <class InputIterator>
void load_values (InputIterator x);
template<class OutputIterator, class SetOp>
void store_values (OutputIterator y, size_type i_receive, SetOp op) const;
// accessors:
size_type n_proc() const { return _procs.size(); }
size_type n_data() const { return _indices.size(); }
size_type n_status() const { return sstatus.size(); }
size_type n_local() const { return local_slots.size(); }
size_type n_local_nonmatching() const { return local_slots_nonmatching.size(); }
};
// =====================================================================================
// when Container::value_type is also a container variable-sized type (e.g. index_set)
// =====================================================================================
template<class Container>
class scatter_message<Container,true> : public scatter_message<std::vector<typename Container::size_type>, false> {
public:
typedef scatter_message<std::vector<typename Container::size_type>, false> base;
typedef typename base::size_type size_type;
typedef typename Container::value_type value_type; // e.g. index_set
typedef typename value_type::value_type base_value_type; // e.g. size_type when value_type=index_set
// data:
protected:
std::vector<base_value_type> _multi_values; // n_multi_data
std::vector<size_type> _multi_indices; // n_multi_data
std::vector<size_type> _multi_procs; // n_multi_proc
std::vector<size_type> _multi_starts; // n_multi_proc+1
std::vector<size_type> _ptr; // n_data+1
std::vector<size_type> _multi_irecv2base_irecv; // empty-msg, when zero data sz
public:
// data accessors:
const std::vector<base_value_type>& values () const { return _multi_values; }
std::vector<base_value_type>& values () { return _multi_values; }
const std::vector<size_type>& indices() const { return _multi_indices; }
std::vector<size_type>& indices() { return _multi_indices; }
const std::vector<size_type>& procs () const { return _multi_procs; }
std::vector<size_type>& procs () { return _multi_procs; }
const std::vector<size_type>& starts () const { return _multi_starts; }
std::vector<size_type>& starts () { return _multi_starts; }
base& get_base() { return *this; }
// allocators:
scatter_message()
: base(),
_multi_values(),
_multi_indices(),
_multi_procs(),
_multi_starts(),
_ptr(),
_multi_irecv2base_irecv()
{}
void multi_init ();
template <class InputIterator>
void load_values (InputIterator x);
template<class OutputIterator, class SetOp>
void store_values (OutputIterator y, size_type i_receive, SetOp op) const;
// accessors:
size_type n_proc() const { return _multi_procs.size(); }
size_type n_data() const { return _multi_indices.size(); }
};
} // namespace rheolef
// -------------------------------------------------------------
// not inlined : longer code
// -------------------------------------------------------------
#include "rheolef/scatter_message.icc"
#endif // _RHEOLEF_HAVE_MPI
#endif // _RHEOLEF_SCATTER_MESSAGE_H
size_type
field::size_type size_type
Definition branch.cc:430
rheolef::scatter_message< Container, false >::indices
const std::vector< size_type > & indices() const
Definition scatter_message.h:58
rheolef::scatter_message< Container, false >::values
Container & values()
Definition scatter_message.h:57
rheolef::scatter_message< Container, false >::n_local
size_type n_local() const
Definition scatter_message.h:111
rheolef::scatter_message< Container, false >::size_type
Container::size_type size_type
Definition scatter_message.h:41
rheolef::scatter_message< Container, false >::_procs
std::vector< size_type > _procs
Definition scatter_message.h:51
rheolef::scatter_message< Container, false >::starts
const std::vector< size_type > & starts() const
Definition scatter_message.h:62
rheolef::scatter_message< Container, false >::n_data
size_type n_data() const
Definition scatter_message.h:109
rheolef::scatter_message< Container, false >::scatter_message
scatter_message(const value_type &init_value=value_type(), const allocator_type &alloc=allocator_type())
Definition scatter_message.h:78
rheolef::scatter_message< Container, false >::values
const Container & values() const
Definition scatter_message.h:56
rheolef::scatter_message< Container, false >::value_type
Container::value_type value_type
Definition scatter_message.h:42
rheolef::scatter_message< Container, false >::starts
std::vector< size_type > & starts()
Definition scatter_message.h:63
rheolef::scatter_message< Container, false >::local_nonmatching_computed
bool local_nonmatching_computed
Definition scatter_message.h:70
rheolef::scatter_message< Container, false >::procs
const std::vector< size_type > & procs() const
Definition scatter_message.h:60
rheolef::scatter_message< Container, false >::allocator_type
Container::allocator_type allocator_type
Definition scatter_message.h:43
rheolef::scatter_message< Container, false >::local_n_nonmatching
size_type local_n_nonmatching
Definition scatter_message.h:71
rheolef::scatter_message< Container, false >::local_slots
std::vector< size_type > local_slots
Definition scatter_message.h:68
rheolef::scatter_message< Container, false >::sstatus
std::vector< mpi::status > sstatus
Definition scatter_message.h:66
rheolef::scatter_message< Container, false >::n_local_nonmatching
size_type n_local_nonmatching() const
Definition scatter_message.h:112
rheolef::scatter_message< Container, false >::local_copy_length
size_type local_copy_length
Definition scatter_message.h:74
rheolef::scatter_message< Container, false >::resize
void resize(size_type n_data, size_type nproc)
Definition scatter_message.h:94
rheolef::scatter_message< Container, false >::requests
std::list< std::pair< size_type, mpi::request > > requests
Definition scatter_message.h:65
rheolef::scatter_message< Container, false >::indices
std::vector< size_type > & indices()
Definition scatter_message.h:59
rheolef::scatter_message< Container, false >::n_status
size_type n_status() const
Definition scatter_message.h:110
rheolef::scatter_message< Container, false >::local_copy_start
size_type local_copy_start
Definition scatter_message.h:73
rheolef::scatter_message< Container, false >::local_is_copy
bool local_is_copy
Definition scatter_message.h:72
rheolef::scatter_message< Container, false >::_values
Container _values
Definition scatter_message.h:49
rheolef::scatter_message< Container, false >::n_proc
size_type n_proc() const
Definition scatter_message.h:108
rheolef::scatter_message< Container, false >::procs
std::vector< size_type > & procs()
Definition scatter_message.h:61
rheolef::scatter_message< Container, false >::_indices
std::vector< size_type > _indices
Definition scatter_message.h:50
rheolef::scatter_message< Container, false >::_starts
std::vector< size_type > _starts
Definition scatter_message.h:52
rheolef::scatter_message< Container, false >::local_slots_nonmatching
std::vector< size_type > local_slots_nonmatching
Definition scatter_message.h:69
rheolef::scatter_message< Container, false >::base_value_type
value_type base_value_type
Definition scatter_message.h:44
rheolef::scatter_message< Container, false >::_init_value
value_type _init_value
Definition scatter_message.h:48
rheolef::scatter_message< Container, true >::indices
const std::vector< size_type > & indices() const
Definition scatter_message.h:140
rheolef::scatter_message< Container, true >::_multi_starts
std::vector< size_type > _multi_starts
Definition scatter_message.h:131
rheolef::scatter_message< Container, true >::base
scatter_message< std::vector< typename Container::size_type >, false > base
Definition scatter_message.h:120
rheolef::scatter_message< Container, true >::starts
const std::vector< size_type > & starts() const
Definition scatter_message.h:144
rheolef::scatter_message< Container, true >::values
std::vector< base_value_type > & values()
Definition scatter_message.h:138
rheolef::scatter_message< Container, true >::n_data
size_type n_data() const
Definition scatter_message.h:172
rheolef::scatter_message< Container, true >::value_type
Container::value_type value_type
Definition scatter_message.h:123
rheolef::scatter_message< Container, true >::starts
std::vector< size_type > & starts()
Definition scatter_message.h:145
rheolef::scatter_message< Container, true >::procs
const std::vector< size_type > & procs() const
Definition scatter_message.h:142
rheolef::scatter_message< Container, true >::_multi_values
std::vector< base_value_type > _multi_values
Definition scatter_message.h:128
rheolef::scatter_message< Container, true >::values
const std::vector< base_value_type > & values() const
Definition scatter_message.h:137
rheolef::scatter_message< Container, true >::size_type
base::size_type size_type
Definition scatter_message.h:122
rheolef::scatter_message< Container, true >::get_base
base & get_base()
Definition scatter_message.h:147
rheolef::scatter_message< Container, true >::indices
std::vector< size_type > & indices()
Definition scatter_message.h:141
rheolef::scatter_message< Container, true >::_multi_procs
std::vector< size_type > _multi_procs
Definition scatter_message.h:130
rheolef::scatter_message< Container, true >::scatter_message
scatter_message()
Definition scatter_message.h:151
rheolef::scatter_message< Container, true >::_ptr
std::vector< size_type > _ptr
Definition scatter_message.h:132
rheolef::scatter_message< Container, true >::_multi_indices
std::vector< size_type > _multi_indices
Definition scatter_message.h:129
rheolef::scatter_message< Container, true >::base_value_type
value_type::value_type base_value_type
Definition scatter_message.h:124
rheolef::scatter_message< Container, true >::_multi_irecv2base_irecv
std::vector< size_type > _multi_irecv2base_irecv
Definition scatter_message.h:133
rheolef::scatter_message< Container, true >::n_proc
size_type n_proc() const
Definition scatter_message.h:171
rheolef::scatter_message< Container, true >::procs
std::vector< size_type > & procs()
Definition scatter_message.h:143
rheolef::scatter_message
Definition scatter_message.h:33
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39