1 #ifndef _RHEOLEF_HACK_ARRAY_H
2 #define _RHEOLEF_HACK_ARRAY_H
33 #include "rheolef/disarray.h"
40 template <
class T,
class Ref,
class Ptr,
class Raw,
class RawIterator>
50 typedef typename std::iterator_traits<RawIterator>::difference_type
difference_type;
77 template <
class T,
class A>
90 typedef typename generic_value_type::raw_type
raw_type;
119 const T* q = (
const T*)
p;
136 template <
class GetFunction> idiststream&
get_values (idiststream& ips, GetFunction get_element);
155 #ifdef _RHEOLEF_HAVE_MPI
156 template <
class T,
class A>
163 typedef typename base::base raw_base;
166 typedef typename base::allocator_type allocator_type;
167 typedef typename base::generic_value_type generic_value_type;
168 typedef typename base::automatic_value_type automatic_value_type;
169 typedef typename base::raw_type raw_type;
170 typedef typename base::parameter_type parameter_type;
171 typedef typename base::reference reference;
172 typedef typename base::const_reference const_reference;
173 typedef typename base::iterator iterator;
176 typedef std::map <size_type, automatic_value_type> scatter_map_type;
179 struct dis_reference {
180 dis_reference (hack_array_mpi_rep<T,A>& x,
size_type dis_i)
181 : _x(x), _dis_i(dis_i) {}
183 dis_reference& operator= (
const generic_value_type&
value) {
184 _x.set_dis_entry (_dis_i,
value);
189 hack_array_mpi_rep<T,A>& _x;
195 hack_array_mpi_rep (
const A& alloc = A());
196 hack_array_mpi_rep (
const distributor& ownership,
const parameter_type& param,
const A& alloc = A());
197 void resize (
const distributor& ownership,
const parameter_type& param);
201 A get_allocator()
const {
return base::get_allocator(); }
202 const distributor& ownership()
const {
return base::_ownership; }
203 const communicator& comm()
const {
return ownership().comm(); }
204 size_type dis_size ()
const {
return ownership().dis_size(); }
206 size_type size()
const {
return base::size(); }
207 const generic_value_type& operator[] (
size_type ie)
const {
return base::operator[] (ie); }
208 generic_value_type& operator[] (
size_type ie) {
return base::operator[] (ie); }
210 iterator begin() {
return base::begin(); }
211 const_iterator begin()
const {
return base::begin(); }
212 iterator end() {
return base::end(); }
213 const_iterator end()
const {
return base::end(); }
215 dis_reference dis_entry (
size_type dis_i) {
return dis_reference (*
this, dis_i); }
217 void dis_entry_assembly_begin ();
218 void dis_entry_assembly_end ();
219 void dis_entry_assembly () { dis_entry_assembly_begin (); dis_entry_assembly_end (); }
221 template<
class Set,
class Map>
222 void append_dis_entry (
const Set& ext_idx_set, Map& ext_idx_map)
const;
224 template<
class Set,
class Map>
225 void get_dis_entry (
const Set& ext_idx_set, Map& ext_idx_map)
const {
227 append_dis_entry (ext_idx_set, ext_idx_map);
231 void append_dis_indexes (
const Set& ext_idx_set)
const { append_dis_entry (ext_idx_set, _ext_x); }
234 void set_dis_indexes (
const Set& ext_idx_set) { get_dis_entry (ext_idx_set, _ext_x); }
236 void update_dis_entries()
const;
238 const_reference dis_at (
size_type dis_i)
const;
242 const disarray_rep<size_type,distributed,A2>& partition,
243 hack_array_mpi_rep<T,A>& new_array,
244 disarray_rep<size_type,distributed,A2>& old_numbering,
245 disarray_rep<size_type,distributed,A2>& new_numbering)
const;
248 void permutation_apply (
249 const disarray_rep<size_type,distributed,>& new_numbering,
250 disarray_rep<T,distributed>& new_array)
const;
252 void reverse_permutation (
253 disarray_rep<size_type,distributed>& inew2dis_iold)
const;
257 const scatter_map_type& get_dis_map_entries()
const {
return _ext_x; }
261 idiststream& get_values (idiststream& ips);
262 odiststream& put_values (odiststream& ops)
const;
263 template <
class GetFunction> idiststream& get_values (idiststream& ips, GetFunction get_element);
264 template <
class PutFunction> odiststream& put_values (odiststream& ops, PutFunction put_element)
const;
266 template <
class PutFunction,
class Permutation>
267 odiststream& permuted_put_values (
269 const Permutation& perm,
270 PutFunction put_element)
const;
273 void set_dis_entry (
size_type dis_i,
const generic_value_type& val);
277 typedef std::map <size_type, raw_type> stash_map_type;
281 struct message_type {
282 std::list<std::pair<size_type,mpi::request> > waits;
283 std::vector<std::pair<size_type,raw_type> > data;
284 message_type() : waits(), data() {}
290 stash_map_type _stash;
292 message_type _receive;
294 mutable scatter_map_type _ext_x;
345 template <
class T,
class M = rheo_default_memory_model,
class A = std::allocator<T> >
350 typedef typename std::vector<T,A>::iterator
iterator;
354 template <
class T,
class A>
408 template<
class SetOp>
410 template<
class SetOp>
412 template<
class SetOp>
418 template<
class RepSize>
420 const RepSize& partition,
422 RepSize& old_numbering,
423 RepSize& new_numbering)
const
424 {
return base::data().repartition (partition, new_array, old_numbering, new_numbering); }
426 template<
class RepSize>
427 void permutation_apply (
428 const RepSize& new_numbering,
429 hack_array<T,sequential,A>& new_array)
const
430 {
return base::data().permutation_apply (new_numbering, new_array); }
436 idiststream&
get_values (idiststream& ips) {
return base::data().get_values(ips); }
437 template <
class GetFunction>
438 idiststream&
get_values (idiststream& ips, GetFunction get_element) {
return base::data().get_values(ips, get_element); }
439 template <
class PutFunction>
442 void dump (std::string
name)
const {
return base::data().dump(
name); }
446 template <
class T,
class A>
453 template <
class T,
class A>
459 :
base(new_macro(
rep(loc_size,param,alloc)))
462 template <
class T,
class A>
468 :
base(new_macro(
rep(ownership,param,alloc)))
471 template <
class T,
class A>
478 base::data().resize (loc_size,param);
480 template <
class T,
class A>
487 base::data().resize (ownership,param);
490 #ifdef _RHEOLEF_HAVE_MPI
492 template <
class T,
class A>
498 typedef hack_array_mpi_rep<T,A> rep;
504 typedef typename rep::reference reference;
505 typedef typename rep::dis_reference dis_reference;
506 typedef typename rep::iterator
iterator;
507 typedef typename rep::parameter_type parameter_type;
508 typedef typename rep::const_reference const_reference;
510 typedef typename rep::scatter_map_type scatter_map_type;
516 void resize (
const distributor& ownership,
const parameter_type& param);
520 A get_allocator()
const {
return base::data().get_allocator(); }
521 size_type size ()
const {
return base::data().size(); }
522 size_type dis_size ()
const {
return base::data().dis_size(); }
523 const distributor& ownership()
const {
return base::data().ownership(); }
524 const communicator& comm()
const {
return base::data().
comm(); }
526 reference operator[] (
size_type i) {
return base::data().operator[] (i); }
527 const_reference operator[] (
size_type i)
const {
return base::data().operator[] (i); }
529 iterator begin() {
return base::data().begin(); }
531 iterator end() {
return base::data().end(); }
536 template<
class Set,
class Map>
537 void append_dis_entry (
const Set& ext_idx_set, Map& ext_idx_map)
const { base::data().append_dis_entry (ext_idx_set, ext_idx_map); }
539 template<
class Set,
class Map>
540 void get_dis_entry (
const Set& ext_idx_set, Map& ext_idx_map)
const { base::data().get_dis_entry (ext_idx_set, ext_idx_map); }
543 void append_dis_indexes (
const Set& ext_idx_set)
const { base::data().append_dis_indexes (ext_idx_set); }
546 void set_dis_indexes (
const Set& ext_idx_set) { base::data().set_dis_indexes (ext_idx_set); }
548 const_reference dis_at (
size_type dis_i)
const {
return base::data().dis_at (dis_i); }
551 const scatter_map_type& get_dis_map_entries()
const {
return base::data().get_dis_map_entries(); }
553 void update_dis_entries()
const { base::data().update_dis_entries(); }
557 dis_reference dis_entry (
size_type dis_i) {
return base::data().dis_entry(dis_i); }
559 void dis_entry_assembly() {
return base::data().dis_entry_assembly(); }
561 template<
class SetOp>
562 void dis_entry_assembly (SetOp my_set_op) {
return base::data().dis_entry_assembly (my_set_op); }
563 template<
class SetOp>
564 void dis_entry_assembly_begin (SetOp my_set_op) {
return base::data().dis_entry_assembly_begin (my_set_op); }
565 template<
class SetOp>
566 void dis_entry_assembly_end (SetOp my_set_op) {
return base::data().dis_entry_assembly_end (my_set_op); }
570 template<
class RepSize>
572 const RepSize& partition,
573 hack_array<T,distributed>& new_array,
574 RepSize& old_numbering,
575 RepSize& new_numbering)
const
576 {
return base::data().repartition (partition.data(), new_array.data(), old_numbering.data(), new_numbering.data()); }
579 template<
class RepSize>
580 void permutation_apply (
581 const RepSize& new_numbering,
582 hack_array<T,distributed,A>& new_array)
const
583 { base::data().permutation_apply (new_numbering.data(), new_array.data()); }
585 void reverse_permutation (
586 hack_array<size_type,distributed,A>& inew2dis_iold)
const
587 { base::data().reverse_permutation (inew2dis_iold.data()); }
592 odiststream& put_values (odiststream& ops)
const {
return base::data().put_values(ops); }
593 idiststream& get_values (idiststream& ips) {
return base::data().get_values(ips); }
595 void dump (std::string
name)
const {
return base::data().dump(
name); }
598 template <
class GetFunction>
599 idiststream& get_values (idiststream& ips, GetFunction get_element)
600 {
return base::data().get_values(ips, get_element); }
601 template <
class PutFunction>
602 odiststream& put_values (odiststream& ops, PutFunction put_element)
const
603 {
return base::data().put_values(ops, put_element); }
605 template <
class PutFunction,
class Permutation>
606 odiststream& permuted_put_values (
608 const Permutation& perm,
609 PutFunction put_element)
const
610 {
return base::data().permuted_put_values (ops, perm.data(), put_element); }
613 template <
class T,
class A>
615 hack_array<T,distributed,A>::hack_array (
617 : base(new_macro(rep(alloc)))
620 template <
class T,
class A>
622 hack_array<T,distributed,A>::hack_array (
623 const distributor& ownership,
624 const parameter_type& param,
626 : base(new_macro(rep(ownership,param,alloc)))
629 template <
class T,
class A>
632 hack_array<T,distributed,A>::resize (
633 const distributor& ownership,
634 const parameter_type& param)
636 base::data().resize (ownership,param);
643 template <
class T,
class A>
650 template <
class T,
class A>
657 #ifdef _RHEOLEF_HAVE_MPI
658 template <
class T,
class A>
661 operator >> (idiststream& ips, hack_array<T,distributed,A>& x)
663 return x.get_values(ips);
665 template <
class T,
class A>
668 operator << (odiststream& ops,
const hack_array<T,distributed,A>& x)
670 return x.put_values(ops);
679 #include "rheolef/hack_array_seq.icc"
680 #include "rheolef/hack_array_mpi.icc"
field::size_type size_type
see the distributor page for the full documentation
size_type dis_size() const
global and local sizes
size_type size(size_type iproc) const
const communicator_type & comm() const
idiststream & get_values(idiststream &ips, GetFunction get_element)
rep::const_iterator const_iterator
void dis_entry_assembly(SetOp my_set_op)
const_reference dis_at(size_type dis_i) const
rep::dis_reference dis_reference
const_iterator begin() const
size_type dis_size() const
void dis_entry_assembly()
dis_reference dis_entry(size_type dis_i)
rep::value_type value_type
void dis_entry_assembly_begin(SetOp my_set_op)
void append_dis_indexes(const Set &ext_idx_set) const
rep::parameter_type parameter_type
odiststream & put_values(odiststream &ops) const
const distributor & ownership() const
odiststream & put_values(odiststream &ops, PutFunction put_element) const
smart_pointer< rep > base
rep::const_reference const_reference
idiststream & get_values(idiststream &ips)
hack_array_seq_rep< T, A > rep
const_iterator end() const
void update_dis_entries() const
const communicator & comm() const
void dis_entry_assembly_end(SetOp my_set_op)
T::generic_type value_type
T::automatic_type automatic_value_type
const_iterator begin() const
size_type dis_size() const
disarray_rep< typename T::raw_type, sequential, A > base
odiststream & put_values(odiststream &ops) const
const generic_value_type & operator[](size_type ie) const
hack_array_seq_rep(const A &alloc=A())
hack_array_iterator< generic_value_type, const generic_value_type &, const generic_value_type *, raw_type, const raw_type * > const_iterator
base::size_type size_type
parameter_type _parameter
const distributor & ownership() const
void resize(const distributor &ownership, const parameter_type ¶m)
T::parameter_type parameter_type
hack_array_iterator< generic_value_type, generic_value_type &, generic_value_type *, raw_type, raw_type * > iterator
const_iterator end() const
const communicator & comm() const
void _init(const distributor &ownership, const parameter_type ¶m)
T::generic_type generic_value_type
generic_value_type::raw_type raw_type
idiststream & get_values(idiststream &ips)
const value_type & const_reference
std::vector< T, A >::iterator iterator
std::vector< T, A >::const_iterator const_iterator
std::vector< T, A >::size_type size_type
odiststream: see the diststream page for the full documentation
see the smart_pointer page for the full documentation
typename Expr1::memory_type memory_type
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format format format format format format format format format format format format format format format format format dump
This file is part of Rheolef.
std::istream & operator>>(std::istream &is, const catchmark &m)
std::ostream & operator<<(std::ostream &os, const catchmark &m)
hack_array_iterator< T, T &, T *, Raw, Raw * > _iterator
hack_array_iterator(RawIterator raw_iter, size_type incr)
std::bidirectional_iterator_tag iterator_category
reference operator[](size_type i) const
_self operator+(size_type n) const
_self & operator+=(size_type n)
std::iterator_traits< RawIterator >::difference_type difference_type
hack_array_iterator< T, Ref, Ptr, Raw, RawIterator > _self
_self & operator-=(size_type n)
bool operator==(const _self &y) const
bool operator!=(const _self &y) const
_self operator-(size_type n) const
reference operator*() const
hack_array_iterator(const _iterator &y)
pointer operator->() const