~ubuntu-branches/ubuntu/trusty/rheolef/trusty

« back to all changes in this revision

Viewing changes to skit/plib2/polymorphic_array.h

  • Committer: Package Import Robot
  • Author(s): Pierre Saramito
  • Date: 2012-04-06 09:12:21 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120406091221-m58me99p1nxqui49
Tags: 6.0-1
* New upstream release 6.0 (major changes):
  - massively distributed and parallel support
  - full FEM characteristic method (Lagrange-Gakerkin method) support
  - enhanced users documentation 
  - source code supports g++-4.7 (closes: #667356)
* debian/control: dependencies for MPI distributed solvers added
* debian/rules: build commands simplified
* debian/librheolef-dev.install: man1/* to man9/* added
* debian/changelog: package description rewritted (closes: #661689)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef BOOST_PP_IS_ITERATING
2
 
#ifndef _RHEOLEF_POLYMORPHIC_ARRAY_H
3
 
#define _RHEOLEF_POLYMORPHIC_ARRAY_H
4
 
///
5
 
/// This file is part of Rheolef.
6
 
///
7
 
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
8
 
///
9
 
/// Rheolef is free software; you can redistribute it and/or modify
10
 
/// it under the terms of the GNU General Public License as published by
11
 
/// the Free Software Foundation; either version 2 of the License, or
12
 
/// (at your option) any later version.
13
 
///
14
 
/// Rheolef is distributed in the hope that it will be useful,
15
 
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
/// GNU General Public License for more details.
18
 
///
19
 
/// You should have received a copy of the GNU General Public License
20
 
/// along with Rheolef; if not, write to the Free Software
21
 
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 
///
23
 
/// =========================================================================
24
 
 
25
 
#include "rheolef/polymorphic_traits.h"
26
 
#include "rheolef/polymorphic_data_vector.h"
27
 
#include "rheolef/polymorphic_data_map.h"
28
 
#include "rheolef/polymorphic_map.h"
29
 
 
30
 
#ifdef _RHEOLEF_HAVE_MPI
31
 
#include "rheolef/polymorphic_scatter_message.h"
32
 
#include "rheolef/mpi_scatter_init.h"
33
 
#endif // _RHEOLEF_HAVE_MPI
34
 
 
35
 
#include <list>
36
 
 
37
 
namespace rheolef {
38
 
namespace mpl = boost::mpl;
39
 
 
40
 
template <class T, class V, int NV>
41
 
struct polymorphic_array_seq_rep {};
42
 
 
43
 
/// @brief array element output helper
44
 
template <class T>
45
 
struct _polymorphic_array_put_element_type {
46
 
  std::ostream& operator() (std::ostream& os, const T& x) { return os << x; }
47
 
};
48
 
 
49
 
#ifdef _RHEOLEF_HAVE_MPI
50
 
 
51
 
template <class T, class V, int NV>
52
 
struct polymorphic_array_mpi_rep {};
53
 
 
54
 
template <class Stash, class Message, int NV>
55
 
struct mpi_polymorphic_assembly_begin_t {};
56
 
 
57
 
template <class Container, class Message, int NV>
58
 
struct mpi_polymorphic_assembly_end_t {};
59
 
 
60
 
template <class Container, class Message, class Buffer, class Tag, int NV>
61
 
struct mpi_polymorphic_scatter_begin_t {};
62
 
 
63
 
template <class Container, class Message, class Tag, int NV>
64
 
struct mpi_polymorphic_scatter_begin_global_t {};
65
 
 
66
 
template <class Container, class Message, class Buffer, int NV>
67
 
struct mpi_polymorphic_scatter_end_t {};
68
 
 
69
 
#endif // _RHEOLEF_HAVE_MPI
70
 
 
71
 
// ----------------------------------------------------------
72
 
// run here the recursive inclusion of this file:
73
 
// ----------------------------------------------------------
74
 
// _RHEOLEF_POLYMORPHIC_MAX_SIZE was defined by "polymorphic_data_vector.h"
75
 
#define BOOST_PP_ITERATION_LIMITS (0, _RHEOLEF_POLYMORPHIC_MAX_SIZE)
76
 
#define BOOST_PP_FILENAME_1    "rheolef/polymorphic_array.h" // this file
77
 
#include BOOST_PP_ITERATE()
78
 
 
79
 
} // namespace rheolef
80
 
#endif // _RHEOLEF_POLYMORPHIC_ARRAY_H
81
 
#else  // BOOST_PP_IS_ITERATING
82
 
// ----------------------------------------------------------
83
 
// here, this file is recursively included with growing "N" :
84
 
// ----------------------------------------------------------
85
 
#define N    BOOST_PP_ITERATION()
86
 
 
87
 
/*Class:polymorphic_array
88
 
NAME:  polymorphic_array - an array of derived classes (@PACKAGE@-@VERSION@)
89
 
SYNOPSYS:
90
 
  @example
91
 
  template <class T, class V> class polymorphic_array_seq_rep;
92
 
  @end example
93
 
DESCRIPTION:       
94
 
 Geometric entities of finite elements are implemented by using
95
 
 a polymorphic hierarchy of classes: the base class @code{geo_element} 
96
 
 is a pure virtual methods. Then, derived classes, such as 
97
 
 @code{geo_element_t} for a triangle, are introduced with a storage
98
 
 zone for the indexes of its vertices in the mesh (See "geo"(3)).
99
 
 
100
 
 Each element has a fixed size storage zone: a buffer of a
101
 
 particular element type can be efficiently exchanged with MPI.
102
 
 
103
 
 Here is an atempt to generalize the distributed array<T>,
104
 
 with reference counting, to the polymorphic case. The base
105
 
 class is denoted as T and the derived ones are included as
106
 
 a vector of type V, e.g. V=mpl::vctor<T0,T1,T2>.
107
 
 
108
 
TODO:
109
 
 Here, class Ti are suposed to have a method :
110
 
        size_type variant() const;
111
 
 that returns the class index i=0..n_variant-1.
112
 
 A more general approch should us run-time type identification.
113
 
 
114
 
 Finally, the container should honor an optional Allocator template class parameter.
115
 
SEE ALSO: "geo"(3) "geo_element"(3)
116
 
AUTHORS:
117
 
   LJK-IMAG, 38041 Grenoble cedex 9, France
118
 
   | Pierre.Saramito@imag.fr
119
 
DATE:   15 december 2010
120
 
End:
121
 
*/
122
 
 
123
 
// -------------------------------------------------------------
124
 
// representation classes
125
 
// -------------------------------------------------------------
126
 
template <class T, class V>
127
 
class polymorphic_array_seq_rep<T,V,N> {
128
 
public:
129
 
 
130
 
// typedefs:
131
 
 
132
 
    static const size_t                                   _n_variant  = mpl::size<V>::value; // should be = N
133
 
    typedef typename std::vector<int>::size_type          size_type;
134
 
    typedef T                                             element_type;
135
 
    typedef          polymorphic_data_map<T,V,N>          data_type;   // extensible area
136
 
    typedef          polymorphic_data_vector<T,V,N>       buffer_type; // contiguous area ; for mpi
137
 
 
138
 
#define _RHEOLEF_typedef(z,k,unused)                                    \
139
 
    typedef typename mpl::at_c<V,k>::type                 T##k;         \
140
 
    typedef typename data_type::map##k##_type             map##k##_type;
141
 
    BOOST_PP_REPEAT(N, _RHEOLEF_typedef, ~)
142
 
#undef _RHEOLEF_typedef
143
 
 
144
 
    struct const_reference {
145
 
        const_reference (const polymorphic_pair_type<T,V,N>& x) : _x(x) {}
146
 
        operator const T& () const { return _x.get_reference(); }
147
 
      // data:
148
 
      protected:
149
 
        const polymorphic_pair_type<T,V,N>& _x;
150
 
    };
151
 
    struct const_iterator {
152
 
      typedef typename std::vector<polymorphic_pair_type<T,V,N> >::const_iterator  raw_iterator;
153
 
      typedef std::bidirectional_iterator_tag        iterator_category;
154
 
      typedef typename raw_iterator::value_type      value_type;
155
 
      typedef typename raw_iterator::difference_type difference_type;
156
 
      typedef typename raw_iterator::pointer         pointer;
157
 
      typedef typename polymorphic_array_seq_rep<T,V,N>::const_reference reference;
158
 
 
159
 
      const_iterator (raw_iterator ri) : _ri(ri) {}
160
 
      const_reference operator* () const { return const_reference(*_ri); }
161
 
      const_iterator& operator++ () { ++_ri; return *this; }
162
 
      const_iterator& operator-- () { --_ri; return *this; }
163
 
      const_iterator  operator++ (int) {
164
 
                const_iterator tmp = *this;
165
 
                ++_ri;
166
 
                return tmp;
167
 
      }
168
 
      const_iterator  operator-- (int) {
169
 
                const_iterator tmp = *this;
170
 
                --_ri;
171
 
                return tmp;
172
 
      }
173
 
      bool operator== (const_iterator j) const { return _ri == j._ri; }
174
 
      bool operator!= (const_iterator j) const { return _ri != j._ri; }
175
 
    protected:
176
 
      raw_iterator  _ri;
177
 
    };
178
 
    struct reference {
179
 
      reference (polymorphic_array_seq_rep<T,V,N>& x, size_type index)
180
 
       : _x(x), _index(index) {}
181
 
      operator const T& () const { return _x.rhs (_index); }
182
 
      operator       T& ()       { return _x.rhs_non_const (_index); }
183
 
 
184
 
      size_type variant() const { return _x.variant(_index); }
185
 
 
186
 
#define _RHEOLEF_assign(z,k,unused)                             \
187
 
      reference& operator= (const T##k& value) {                \
188
 
        _x.assign (_index, value);                              \
189
 
        return *this;                                           \
190
 
      }
191
 
      BOOST_PP_REPEAT(N, _RHEOLEF_assign, ~)
192
 
#undef _RHEOLEF_assign
193
 
 
194
 
#ifdef TODO
195
 
      reference& operator= (const_reference ref);
196
 
#endif // TODO
197
 
    // data:
198
 
    protected:
199
 
      polymorphic_array_seq_rep<T,V,N>& _x;
200
 
      size_type                         _index;
201
 
    };
202
 
    struct iterator {
203
 
      typedef std::bidirectional_iterator_tag iterator_category;
204
 
      typedef T                               value_type;
205
 
      typedef std::ptrdiff_t                  difference_type;
206
 
      typedef T&                              pointer;
207
 
      typedef typename polymorphic_array_seq_rep<T,V,N>::reference reference;
208
 
 
209
 
      iterator (polymorphic_array_seq_rep<T,V,N>& x, size_type index)
210
 
         : _x(x), _index(index) {}
211
 
      operator const_iterator() const { return const_iterator (_x._ptr.begin() + _index); }
212
 
      reference operator* () const { return reference(_x,_index); }
213
 
      iterator& operator++ () { ++_index; return *this; }
214
 
      iterator& operator-- () { --_index; return *this; }
215
 
      iterator  operator++ (int) {
216
 
                iterator tmp = *this;
217
 
                ++_index;
218
 
                return tmp;
219
 
      }
220
 
      iterator  operator-- (int) {
221
 
                iterator tmp = *this;
222
 
                --_index;
223
 
                return tmp;
224
 
      }
225
 
      bool operator== (iterator j) const { return _index == j._index; }
226
 
      bool operator!= (iterator j) const { return _index != j._index; }
227
 
      // data:
228
 
    protected:
229
 
      polymorphic_array_seq_rep<T,V,N>& _x;
230
 
      size_type                         _index;
231
 
    };
232
 
 
233
 
// allocators:
234
 
 
235
 
    polymorphic_array_seq_rep (size_type loc_size = 0);
236
 
    polymorphic_array_seq_rep (const distributor& ownership);
237
 
    polymorphic_array_seq_rep (const array_seq_rep<T>& x);
238
 
    void resize (const distributor& ownership);
239
 
    void resize (size_type loc_size);
240
 
 
241
 
// accessors
242
 
 
243
 
  size_type     size() const { return _ptr.size(); }
244
 
  size_type dis_size() const { return size(); }
245
 
  reference       operator[] (size_type index)       { return       reference (*this, index); }
246
 
  const_reference operator[] (size_type index) const { return const_reference (_ptr[index]); }
247
 
  size_type       variant    (size_type index) const { return _ptr[index].variant(); }
248
 
  const_iterator begin () const { return const_iterator (_ptr.begin()); }
249
 
  const_iterator end   () const { return const_iterator (_ptr.end()); }
250
 
  iterator begin () { return iterator (*this, 0); }
251
 
  iterator end   () { return iterator (*this, _ptr.size()); }
252
 
  const distributor&  ownership() const { return _ownership; }
253
 
  const communicator&  comm() const { return ownership().comm(); }
254
 
 
255
 
#define _RHEOLEF_set(z,k,unused)                                                \
256
 
  void set_dis_entry (size_type index, const T##k& value) { assign (index, value); }
257
 
  BOOST_PP_REPEAT(N, _RHEOLEF_set, ~)
258
 
#undef _RHEOLEF_set
259
 
 
260
 
// i/o
261
 
 
262
 
  idiststream& get_values (idiststream& ips);
263
 
  odiststream& put_values (odiststream& ops) const;
264
 
  template <class PutFunction> odiststream& put_values (odiststream& opsa, PutFunction put_element) const;
265
 
  void dump (std::string name) const;
266
 
 
267
 
// internal:
268
 
protected:
269
 
  const T& rhs     (size_type index) const { return _ptr [index].get_reference(); }
270
 
  T& rhs_non_const (size_type index)       { return _ptr [index].get_reference(); }
271
 
  void erase (size_type index);
272
 
  void update_ptr();
273
 
 
274
 
#define _RHEOLEF_load(z,k,unused)                                       \
275
 
  void load (const std::vector<std::pair<size_type,T##k> >& buffer);    \
276
 
  void assign (size_type index, const T##k& value);
277
 
  BOOST_PP_REPEAT(N, _RHEOLEF_load, ~)
278
 
#undef _RHEOLEF_load
279
 
 
280
 
// data:
281
 
 
282
 
protected:
283
 
  friend class polymorphic_map_rep<T,V,N>;
284
 
  distributor                                 _ownership;
285
 
  std::vector<polymorphic_pair_type<T,V,N> >  _ptr;
286
 
  data_type                                   _data;
287
 
};
288
 
#ifdef _RHEOLEF_HAVE_MPI
289
 
template <class T, class V>
290
 
class polymorphic_array_mpi_rep<T,V,N> : public polymorphic_array_seq_rep<T,V,N> {
291
 
public:
292
 
 
293
 
// typedefs:
294
 
 
295
 
  static const size_t  _n_variant  = mpl::size<V>::value; // should be = N
296
 
  typedef polymorphic_array_seq_rep<T,V,N>   seq;
297
 
  typedef typename seq::size_type        size_type;
298
 
  typedef T                              element_type;
299
 
  typedef typename seq::data_type        data_type;
300
 
  typedef typename seq::buffer_type      buffer_type;
301
 
  typedef typename seq::reference        reference;
302
 
  typedef typename seq::const_reference  const_reference;
303
 
  typedef typename seq::iterator         iterator;
304
 
  typedef typename seq::const_iterator   const_iterator;
305
 
 
306
 
#define _RHEOLEF_typedef(z,k,unused)                                    \
307
 
    typedef typename mpl::at_c<V,k>::type                 T##k;         \
308
 
    typedef typename data_type::map##k##_type             map##k##_type;
309
 
    BOOST_PP_REPEAT(N, _RHEOLEF_typedef, ~)
310
 
#undef _RHEOLEF_typedef
311
 
 
312
 
// allocators:
313
 
 
314
 
#ifdef TO_CLEAN
315
 
  polymorphic_array_mpi_rep (size_type dis_size = 0, size_type loc_size = distributor::decide); 
316
 
  void resize (size_type dis_size = 0, size_type loc_size = distributor::decide);
317
 
#endif // TO_CLEAN
318
 
 
319
 
  polymorphic_array_mpi_rep (const distributor& ownership);
320
 
  void resize               (const distributor& ownership);
321
 
  polymorphic_array_mpi_rep (const polymorphic_array_mpi_rep<T,V,N>& x);
322
 
 
323
 
// accessors & modifiers:
324
 
 
325
 
  size_type size()     const { return polymorphic_array_seq_rep<T,V,N>::size(); }
326
 
  size_type dis_size() const { return ownership().dis_size(); }
327
 
 
328
 
  const distributor&  ownership() const { return polymorphic_array_seq_rep<T,V,N>::ownership(); }
329
 
  const communicator& comm() const { return ownership().comm(); }
330
 
 
331
 
  const_reference operator[] (size_type index) const {
332
 
        return polymorphic_array_seq_rep<T,V,N>::operator[] (index);
333
 
  }
334
 
  reference operator[] (size_type index) {
335
 
        return polymorphic_array_seq_rep<T,V,N>::operator[] (index);
336
 
  }
337
 
  const_iterator begin () const { return seq::begin(); }
338
 
  const_iterator end   () const { return seq::end(); }
339
 
        iterator begin ()       { return seq::begin(); }
340
 
        iterator end   ()       { return seq::end(); }
341
 
 
342
 
#define _RHEOLEF_set(z,k,unused)                                \
343
 
  void set_dis_entry (size_type dis_index, const T##k& value);
344
 
  BOOST_PP_REPEAT(N, _RHEOLEF_set, ~)
345
 
#undef _RHEOLEF_set
346
 
 
347
 
  void dis_entry_assembly_begin ();
348
 
  void dis_entry_assembly_end ();
349
 
 
350
 
  void repartition (                                          // old_numbering for *this
351
 
        const array_mpi_rep<size_type>&     partition,        // old_ownership
352
 
        polymorphic_array_mpi_rep<T,V,N>&   new_array,        // new_ownership (created)
353
 
        array_mpi_rep<size_type>&           old_numbering,    // new_ownership
354
 
        array_mpi_rep<size_type>&           new_numbering) const; // old_ownership
355
 
 
356
 
  template<class Set>
357
 
  void get_dis_entry (const Set& ext_idx_set, polymorphic_map_rep<T,V,N>& ext_idx_map) const;
358
 
 
359
 
// i/o
360
 
 
361
 
  idiststream& get_values (idiststream& ips);
362
 
  odiststream& put_values (odiststream& ops) const;
363
 
  template <class Permutation>
364
 
  odiststream& permuted_put_values (odiststream& ops, const Permutation& perm) const;
365
 
  template <class Permutation, class PutFunction>
366
 
  odiststream& permuted_put_values (odiststream& ops, const Permutation& perm,
367
 
                                PutFunction put_element) const;
368
 
  void dump (std::string name) const;
369
 
 
370
 
protected:
371
 
  typedef polymorphic_data_map<T,V,_n_variant>   stash_type;
372
 
  struct message_type {
373
 
    boost::array<std::list<std::pair<size_t,mpi::request> >,_n_variant>   waits;
374
 
    polymorphic_data_vector<T,V,_n_variant>                               data;
375
 
  };
376
 
// data:
377
 
  stash_type                          _stash;
378
 
  message_type                        _send;
379
 
  message_type                        _receive;
380
 
  boost::array<size_type,_n_variant>  _receive_max_size;
381
 
};
382
 
#endif // _RHEOLEF_HAVE_MPI
383
 
 
384
 
#ifndef _RHEOLEF_POLYMORPHIC_ARRAY
385
 
#define _RHEOLEF_POLYMORPHIC_ARRAY
386
 
// -------------------------------------------------------------
387
 
// wrapper class: sequential polymorphic_array 
388
 
// -------------------------------------------------------------
389
 
template <class T, class M = rheo_default_memory_model, class V = typename polymorphic_traits<T>::derived_type>
390
 
struct polymorphic_array {};
391
 
 
392
 
//<polymorphic_array:
393
 
template <class T, class V>
394
 
class polymorphic_array<T,sequential,V> : public smart_pointer<polymorphic_array_seq_rep<T,V,mpl::size<V>::value> > {
395
 
public:
396
 
 
397
 
// typedefs:
398
 
 
399
 
    static const size_t _n_variant  = mpl::size<V>::value;
400
 
 
401
 
    typedef sequential                                    memory_type;
402
 
    typedef polymorphic_array_seq_rep<T,V,_n_variant>     rep;
403
 
    typedef smart_pointer<rep>                            base;
404
 
    typedef typename rep::size_type                       size_type;
405
 
    typedef typename rep::reference                       reference;
406
 
    typedef typename rep::const_reference                 const_reference;
407
 
    typedef typename rep::iterator                        iterator;
408
 
    typedef typename rep::const_iterator                  const_iterator;
409
 
 
410
 
// constructors:
411
 
 
412
 
    polymorphic_array (size_type n = 0);
413
 
    void resize       (size_type n);
414
 
    polymorphic_array (const distributor& ownership);
415
 
    void resize       (const distributor& ownership);
416
 
 
417
 
// accessors & modifiers:
418
 
 
419
 
    size_type       size () const;
420
 
    size_type       dis_size() const;
421
 
    reference       operator[] (size_type i);
422
 
    const_reference operator[] (size_type i) const;
423
 
    const_iterator begin () const;
424
 
    const_iterator end   () const;
425
 
          iterator begin ();
426
 
          iterator end   ();
427
 
 
428
 
    const distributor&  ownership() const;
429
 
    const communicator& comm() const;
430
 
 
431
 
// i/o:
432
 
 
433
 
    idiststream& get_values (idiststream& ips);
434
 
    odiststream& put_values (odiststream& ops) const;
435
 
    template <class PutFunction> odiststream& put_values (odiststream& ops, PutFunction put_element) const;
436
 
    void dump (std::string name) const;
437
 
};
438
 
template <class T, class V>
439
 
odiststream& operator<< (odiststream& ops, const polymorphic_array<T,sequential,V>& x);
440
 
 
441
 
template <class T, class V>
442
 
idiststream& operator>> (idiststream& ips, polymorphic_array<T,sequential,V>& x);
443
 
//>polymorphic_array:
444
 
 
445
 
template <class T, class V>
446
 
inline
447
 
polymorphic_array<T,sequential,V>::polymorphic_array (const distributor& ownership)
448
 
 : base (new_macro(rep(ownership)))
449
 
{
450
 
}
451
 
template <class T, class V>
452
 
inline
453
 
polymorphic_array<T,sequential,V>::polymorphic_array (size_type n)
454
 
 : base (new_macro(rep(n)))
455
 
{
456
 
}
457
 
template <class T, class V>
458
 
inline
459
 
void
460
 
polymorphic_array<T,sequential,V>::resize (size_type n)
461
 
{
462
 
    return base::data().resize(n);
463
 
}
464
 
template <class T, class V>
465
 
inline
466
 
void
467
 
polymorphic_array<T,sequential,V>::resize (const distributor& ownership)
468
 
{
469
 
    return base::data().resize(ownership);
470
 
}
471
 
template <class T, class V>
472
 
inline
473
 
typename polymorphic_array<T,sequential,V>::size_type
474
 
polymorphic_array<T,sequential,V>::size () const
475
 
{
476
 
    return base::data().size();
477
 
}
478
 
template <class T, class V>
479
 
inline
480
 
typename polymorphic_array<T,sequential,V>::size_type
481
 
polymorphic_array<T,sequential,V>::dis_size () const
482
 
{
483
 
    return base::data().dis_size();
484
 
}
485
 
template <class T, class V>
486
 
inline
487
 
typename polymorphic_array<T,sequential,V>::reference
488
 
polymorphic_array<T,sequential,V>::operator[] (size_type i) 
489
 
{
490
 
    return base::data().operator[] (i);
491
 
}
492
 
template <class T, class V>
493
 
inline
494
 
typename polymorphic_array<T,sequential,V>::const_reference
495
 
polymorphic_array<T,sequential,V>::operator[] (size_type i) const
496
 
{
497
 
    return base::data().operator[] (i);
498
 
}
499
 
template <class T, class V>
500
 
inline
501
 
typename polymorphic_array<T,sequential,V>::iterator
502
 
polymorphic_array<T,sequential,V>::begin ()
503
 
{
504
 
    return base::data().begin();
505
 
}
506
 
template <class T, class V>
507
 
inline
508
 
typename polymorphic_array<T,sequential,V>::iterator
509
 
polymorphic_array<T,sequential,V>::end ()
510
 
{
511
 
    return base::data().end();
512
 
}
513
 
template <class T, class V>
514
 
inline
515
 
typename polymorphic_array<T,sequential,V>::const_iterator
516
 
polymorphic_array<T,sequential,V>::begin () const
517
 
{
518
 
    return base::data().begin();
519
 
}
520
 
template <class T, class V>
521
 
inline
522
 
typename polymorphic_array<T,sequential,V>::const_iterator
523
 
polymorphic_array<T,sequential,V>::end () const
524
 
{
525
 
    return base::data().end();
526
 
}
527
 
template <class T, class V>
528
 
inline
529
 
const distributor&
530
 
polymorphic_array<T,sequential,V>::ownership () const
531
 
{
532
 
    return base::data().ownership();
533
 
}
534
 
template <class T, class V>
535
 
inline
536
 
const communicator&
537
 
polymorphic_array<T,sequential,V>::comm() const
538
 
{
539
 
    return base::data().comm();
540
 
}
541
 
template <class T, class V>
542
 
inline
543
 
idiststream&
544
 
polymorphic_array<T,sequential,V>::get_values(idiststream& ips)
545
 
{
546
 
    return base::data().get_values(ips);
547
 
}
548
 
template <class T, class V>
549
 
template <class PutFunction>
550
 
inline
551
 
odiststream&
552
 
polymorphic_array<T,sequential,V>::put_values(odiststream& ops, PutFunction put_element) const
553
 
{
554
 
    return base::data().put_values (ops, put_element);
555
 
}
556
 
template <class T, class V>
557
 
inline
558
 
odiststream&
559
 
polymorphic_array<T,sequential,V>::put_values(odiststream& ops) const
560
 
{
561
 
    return base::data().put_values(ops);
562
 
}
563
 
template <class T, class V>
564
 
inline
565
 
void
566
 
polymorphic_array<T,sequential,V>::dump(std::string name) const
567
 
{
568
 
    return base::data().dump (name);
569
 
}
570
 
template <class T, class V>
571
 
inline
572
 
odiststream& 
573
 
operator<< (odiststream& ops, const polymorphic_array<T,sequential,V>& x) {
574
 
     return x.put_values (ops);
575
 
}
576
 
template <class T, class V>
577
 
inline
578
 
idiststream& 
579
 
operator>> (idiststream& ips, polymorphic_array<T,sequential,V>& x) {
580
 
     return x.get_values(ips);
581
 
}
582
 
// -------------------------------------------------------------
583
 
// wrapper class: distributed polymorphic_array 
584
 
// -------------------------------------------------------------
585
 
#ifdef _RHEOLEF_HAVE_MPI
586
 
 
587
 
//<polymorphic_array:
588
 
template <class T, class V>
589
 
class polymorphic_array<T,distributed,V> : public smart_pointer<polymorphic_array_mpi_rep<T,V,mpl::size<V>::value> > {
590
 
public:
591
 
 
592
 
// typedefs:
593
 
 
594
 
    static const size_t _n_variant  = mpl::size<V>::value;
595
 
 
596
 
    typedef distributed                                   memory_type;
597
 
    typedef polymorphic_array_mpi_rep<T,V,_n_variant>     rep;
598
 
    typedef smart_pointer<rep>                            base;
599
 
    typedef typename rep::size_type                       size_type;
600
 
    typedef typename rep::reference                       reference;
601
 
    typedef typename rep::const_reference                 const_reference;
602
 
    typedef typename rep::iterator                        iterator;
603
 
    typedef typename rep::const_iterator                  const_iterator;
604
 
 
605
 
// constructors:
606
 
 
607
 
#ifdef TO_CLEAN
608
 
    polymorphic_array (size_type n = 0);
609
 
    void resize       (size_type n);
610
 
#endif // TO_CLEAN
611
 
    polymorphic_array (const distributor& ownership = distributor());
612
 
    void resize       (const distributor& ownership);
613
 
 
614
 
// accessors & modifiers:
615
 
 
616
 
    size_type       size () const;
617
 
    size_type       dis_size () const;
618
 
    reference       operator[] (size_type i);
619
 
    const_reference operator[] (size_type i) const;
620
 
    const_iterator begin () const;
621
 
    const_iterator end   () const;
622
 
          iterator begin ();
623
 
          iterator end   ();
624
 
 
625
 
    const distributor&  ownership() const;
626
 
    const communicator& comm() const;
627
 
 
628
 
    void dis_entry_assembly_begin ();
629
 
    void dis_entry_assembly_end ();
630
 
 
631
 
    void repartition (                                        // old_numbering for *this
632
 
        const array<size_type,distributed>& partition,        // old_ownership
633
 
        polymorphic_array<T,distributed,V>& new_array,        // new_ownership (created)
634
 
        array<size_type,distributed>&       old_numbering,    // new_ownership
635
 
        array<size_type,distributed>&       new_numbering) const; // old_ownership
636
 
 
637
 
  template<class Set>
638
 
  void get_dis_entry (const Set& ext_idx_set, polymorphic_map<T,V>& ext_idx_map) const;
639
 
 
640
 
// i/o:
641
 
 
642
 
    idiststream& get_values (idiststream& ips);
643
 
    odiststream& put_values (odiststream& ops) const;
644
 
    template <class Permutation>
645
 
    odiststream& permuted_put_values (odiststream& ops, const Permutation& perm) const;
646
 
    template <class Permutation, class PutFunction>
647
 
    odiststream& permuted_put_values (odiststream& ops, const Permutation& perm,
648
 
                                PutFunction put_element) const;
649
 
    void dump (std::string name) const;
650
 
};
651
 
template <class T, class V>
652
 
odiststream& operator<< (odiststream& ops, const polymorphic_array<T,distributed,V>& x);
653
 
 
654
 
template <class T, class V>
655
 
idiststream& operator>> (idiststream& ips, polymorphic_array<T,distributed,V>& x);
656
 
//>polymorphic_array:
657
 
 
658
 
#ifdef TO_CLEAN
659
 
template <class T, class V>
660
 
inline
661
 
polymorphic_array<T,distributed,V>::polymorphic_array (size_type n)
662
 
 : base (new_macro(rep(n)))
663
 
{
664
 
}
665
 
template <class T, class V>
666
 
inline
667
 
void
668
 
polymorphic_array<T,distributed,V>::resize (size_type n)
669
 
{
670
 
    return base::data().resize(n);
671
 
}
672
 
#endif // TO_CLEAN
673
 
template <class T, class V>
674
 
inline
675
 
polymorphic_array<T,distributed,V>::polymorphic_array (const distributor& ownership)
676
 
 : base (new_macro(rep(ownership)))
677
 
{
678
 
}
679
 
template <class T, class V>
680
 
inline
681
 
void
682
 
polymorphic_array<T,distributed,V>::resize (const distributor& ownership)
683
 
{
684
 
    return base::data().resize(ownership);
685
 
}
686
 
template <class T, class V>
687
 
inline
688
 
typename polymorphic_array<T,distributed,V>::size_type
689
 
polymorphic_array<T,distributed,V>::size () const
690
 
{
691
 
    return base::data().size();
692
 
}
693
 
template <class T, class V>
694
 
inline
695
 
typename polymorphic_array<T,distributed,V>::size_type
696
 
polymorphic_array<T,distributed,V>::dis_size () const
697
 
{
698
 
    return base::data().dis_size();
699
 
}
700
 
template <class T, class V>
701
 
inline
702
 
typename polymorphic_array<T,distributed,V>::reference
703
 
polymorphic_array<T,distributed,V>::operator[] (size_type i) 
704
 
{
705
 
    return base::data().operator[] (i);
706
 
}
707
 
template <class T, class V>
708
 
inline
709
 
typename polymorphic_array<T,distributed,V>::const_reference
710
 
polymorphic_array<T,distributed,V>::operator[] (size_type i) const
711
 
{
712
 
    return base::data().operator[] (i);
713
 
}
714
 
template <class T, class V>
715
 
inline
716
 
typename polymorphic_array<T,distributed,V>::iterator
717
 
polymorphic_array<T,distributed,V>::begin ()
718
 
{
719
 
    return base::data().begin();
720
 
}
721
 
template <class T, class V>
722
 
inline
723
 
typename polymorphic_array<T,distributed,V>::iterator
724
 
polymorphic_array<T,distributed,V>::end ()
725
 
{
726
 
    return base::data().end();
727
 
}
728
 
template <class T, class V>
729
 
inline
730
 
typename polymorphic_array<T,distributed,V>::const_iterator
731
 
polymorphic_array<T,distributed,V>::begin () const
732
 
{
733
 
    return base::data().begin();
734
 
}
735
 
template <class T, class V>
736
 
inline
737
 
typename polymorphic_array<T,distributed,V>::const_iterator
738
 
polymorphic_array<T,distributed,V>::end () const
739
 
{
740
 
    return base::data().end();
741
 
}
742
 
template <class T, class V>
743
 
inline
744
 
const distributor&
745
 
polymorphic_array<T,distributed,V>::ownership () const
746
 
{
747
 
    return base::data().ownership();
748
 
}
749
 
template <class T, class V>
750
 
inline
751
 
const communicator&
752
 
polymorphic_array<T,distributed,V>::comm() const
753
 
{
754
 
    return base::data().comm();
755
 
}
756
 
template <class T, class V>
757
 
inline
758
 
idiststream&
759
 
polymorphic_array<T,distributed,V>::get_values(idiststream& ips)
760
 
{
761
 
    return base::data().get_values(ips);
762
 
}
763
 
template <class T, class V>
764
 
inline
765
 
odiststream&
766
 
polymorphic_array<T,distributed,V>::put_values(odiststream& ops) const
767
 
{
768
 
    return base::data().put_values(ops);
769
 
}
770
 
template <class T, class V>
771
 
inline
772
 
void
773
 
polymorphic_array<T,distributed,V>::dis_entry_assembly_begin ()
774
 
{
775
 
    return base::data().dis_entry_assembly_begin();
776
 
}
777
 
template <class T, class V>
778
 
inline
779
 
void
780
 
polymorphic_array<T,distributed,V>::dis_entry_assembly_end ()
781
 
{
782
 
    return base::data().dis_entry_assembly_end();
783
 
}
784
 
template <class T, class V>
785
 
template <class Permutation>
786
 
inline
787
 
odiststream&
788
 
polymorphic_array<T,distributed,V>::permuted_put_values (
789
 
    odiststream& ops, 
790
 
    const Permutation& perm) const
791
 
{
792
 
    return base::data().permuted_put_values (ops, perm);
793
 
}
794
 
template <class T, class V>
795
 
template <class Permutation, class PutFunction>
796
 
inline
797
 
odiststream&
798
 
polymorphic_array<T,distributed,V>::permuted_put_values (
799
 
    odiststream& ops, 
800
 
    const Permutation& perm,
801
 
    PutFunction put_element) const
802
 
{
803
 
    return base::data().permuted_put_values (ops, perm, put_element);
804
 
}
805
 
template <class T, class V>
806
 
inline
807
 
void
808
 
polymorphic_array<T,distributed,V>::dump(std::string name) const
809
 
{
810
 
    return base::data().dump (name);
811
 
}
812
 
template <class T, class V>
813
 
inline
814
 
odiststream& 
815
 
operator<< (odiststream& ops, const polymorphic_array<T,distributed,V>& x) {
816
 
     return x.put_values (ops);
817
 
}
818
 
template <class T, class V>
819
 
inline
820
 
idiststream& 
821
 
operator>> (idiststream& ips, polymorphic_array<T,distributed,V>& x) {
822
 
     return x.get_values (ips);
823
 
}
824
 
template <class T, class V>
825
 
inline
826
 
void
827
 
polymorphic_array<T,distributed,V>::repartition (
828
 
        const array<size_type,distributed>& partition,  
829
 
        polymorphic_array<T,distributed,V>& new_array,   
830
 
        array<size_type,distributed>&       old_numbering,
831
 
        array<size_type,distributed>&       new_numbering) const
832
 
{
833
 
    base::data().repartition (
834
 
        partition.data(),
835
 
        new_array.data(),
836
 
        old_numbering.data(),
837
 
        new_numbering.data());
838
 
}
839
 
template <class T, class V>
840
 
template<class Set>
841
 
inline
842
 
void
843
 
polymorphic_array<T,distributed,V>::get_dis_entry (
844
 
        const Set&            ext_idx_set,
845
 
        polymorphic_map<T,V>& ext_idx_map) const
846
 
{
847
 
    base::data().get_dis_entry (ext_idx_set, ext_idx_map.data());
848
 
}
849
 
#endif // _RHEOLEF_HAVE_MPI
850
 
 
851
 
 
852
 
#endif // _RHEOLEF_POLYMORPHIC_ARRAY
853
 
// -------------------------------------------------------------
854
 
// not inlined : longer code
855
 
// -------------------------------------------------------------
856
 
#include "rheolef/polymorphic_array_seq.icc"
857
 
#include "rheolef/polymorphic_array_mpi.icc"
858
 
 
859
 
#endif // BOOST_PP_IS_ITERATING