Rheolef  7.1
an efficient C++ finite element environment
vec_concat.cc
Go to the documentation of this file.
1 // build vec from initializer lists
22 //
23 #include "rheolef/vec_concat.h"
24 
25 namespace rheolef { namespace details {
26 
27 template <class T, class M>
28 vec<T,M>
30 {
31  // scalars are attributed to iproc0
32  communicator comm;
33  size_type my_proc = comm.rank();
34  size_type iproc0 = constraint_process_rank (comm);
35  // ------------------------------------
36  // first pass: compute the vector size
37  // ------------------------------------
38  size_type s_sz = 0;
39  size_type v_sz = 0;
40  size_type v_dis_sz = 0;
41  for(typename std::list<value_type>::const_iterator iter = _l.begin(); iter != _l.end(); ++iter) {
42  const vec_concat_value<T,M>& x = *iter;
43  switch (x.variant) {
44  case value_type::scalar:
45  s_sz++;
46  break;
47  case value_type::scalars:
48  s_sz += x.ss.size();
49  break;
50  case value_type::vector:
51  comm = x.v.ownership().comm();
52  v_sz += x.v.ownership().size();
53  v_dis_sz += x.v.ownership().dis_size();
54  break;
55  }
56  }
57  v_dis_sz += s_sz;
58  if (my_proc == iproc0) { v_sz += s_sz; }
59  distributor ownership (v_dis_sz, comm, v_sz);
60  // ------------------------
61  // second pass: copy values
62  // ------------------------
63  vec<T,M> u (ownership);
64  typename vec<T,M>::iterator pu = u.begin();
65  for(typename std::list<value_type>::const_iterator iter = _l.begin(); iter != _l.end(); ++iter) {
66  const vec_concat_value<T,M>& x = *iter;
67  switch (x.variant) {
68  case value_type::scalar:
69  if (my_proc == iproc0) {
70  *pu++ = x.s;
71  }
72  break;
73  case value_type::scalars:
74  if (my_proc == iproc0) {
75  for (typename std::vector<T>::const_iterator
76  iter = x.ss.begin(),
77  last = x.ss.end(); iter != last; ++iter, ++pu) {
78  *pu = *iter;
79  }
80  }
81  break;
82  case value_type::vector:
83  for (typename vec<T,M>::const_iterator
84  iter = x.v.begin(),
85  last = x.v.end(); iter != last; ++iter, ++pu) {
86  *pu = *iter;
87  }
88  break;
89  }
90  }
91  return u;
92 }
93 // ----------------------------------------------------------------------------
94 // instanciation in library
95 // ----------------------------------------------------------------------------
96 #define _RHEOLEF_instanciation(T,M) \
97 template class vec_concat<T,M>;
98 
99 _RHEOLEF_instanciation(Float,sequential)
100 #ifdef _RHEOLEF_HAVE_MPI
102 #endif // _RHEOLEF_HAVE_MPI
103 
104 }} // namespace rheolef::details
rheolef::vec::const_iterator
base::const_iterator const_iterator
Definition: vec.h:92
rheolef::details::vec_concat::size_type
vec< T, M >::size_type size_type
Definition: vec_concat.h:64
rheolef::details::vec_concat_value::s
T s
Definition: vec_concat.h:54
rheolef::details::vec_concat::build_vec
vec< T, M > build_vec() const
Definition: vec_concat.cc:29
rheolef::details::vec_concat_value::variant
variant_type variant
Definition: vec_concat.h:57
rheolef::distributor
see the distributor page for the full documentation
Definition: distributor.h:62
rheolef::details::vec_concat_value::ss
std::vector< T > ss
Definition: vec_concat.h:55
rheolef::vec
see the vec page for the full documentation
Definition: vec.h:79
rheolef::space_constant::scalar
@ scalar
Definition: space_constant.h:136
rheolef::vec::iterator
base::iterator iterator
Definition: vec.h:91
rheolef::details::vec_concat_value
Definition: vec_concat.h:37
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
u
Definition: leveque.h:25
Float
see the Float page for the full documentation
u
Float u(const point &x)
Definition: transmission_error.cc:26
rheolef::space_constant::vector
@ vector
Definition: space_constant.h:137
rheolef::details::_RHEOLEF_instanciation
_RHEOLEF_instanciation(Float, sequential) _RHEOLEF_instanciation(Float
rheolef::distributed
distributed
Definition: asr.cc:228
rheolef::details::vec_concat_value::v
vec< T, M > v
Definition: vec_concat.h:56