rheolef  6.6
csr_concat.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_CSR_CONCAT_H
2 #define _RHEOLEF_CSR_CONCAT_H
3 #include "rheolef/csr.h"
4 
5 namespace rheolef {
6 
7 // A = {a, u}; // matrix & vector
8 // A = {trans(u), 3.2}; // trans(vector) & scalar
9 template <class T, class M>
10 struct vec_trans {
12  vec_trans (const vec<T,M>& w) : v(w) {}
13 };
14 template <class T, class M>
15 inline
16 vec_trans<T,M>
17 trans (const vec<T,M>& w) {
18  return vec_trans<T,M> (w);
19 }
20 template <class T, class M>
22  std::vector<vec<T,M> > v;
23  vector_vec_trans (const std::vector<vec<T,M> >& w) : v(w) {}
24 };
25 template <class T, class M>
26 inline
27 vector_vec_trans<T,M>
28 trans (const std::vector<vec<T,M> >& w) {
29  return vector_vec_trans<T,M> (w);
30 }
31 
32 template <class T, class M>
33 struct csr_concat_value {
35  csr_concat_value (int x) : s(x), v(), vv(), m(), variant(scalar) {}
36 #ifdef _RHEOLEF_HAVE_QD
37  csr_concat_value (double x) : s(x), v(), vv(), m(), variant(scalar) {}
38 #endif // _RHEOLEF_HAVE_QD
39  csr_concat_value (const T& x) : s(x), v(), vv(), m(), variant(scalar) {}
40  csr_concat_value (const vec<T,M>& x) : s(), v(x), vv(), m(), variant(vector) {}
41  csr_concat_value (const vec_trans<T,M>& vt) : s(), v(vt.v), vv(), m(), variant(vector_transpose) {}
42  csr_concat_value (const std::vector<vec<T,M> >& x) : s(), v(), vv(x), m(), variant(vector_vec) {}
44  csr_concat_value (const csr<T,M>& x) : s(), v(), vv(), m(x), variant(matrix) {}
45 
46 public:
47  T s;
49  std::vector<vec<T,M> > vv;
52 };
53 
54 template <class T, class M>
55 struct csr_concat_line {
56  typedef typename csr<T,M>::size_type size_type;
58  csr_concat_line () : _l() {}
59 
60 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_LIST
61  csr_concat_line (const std::initializer_list<value_type>& il) : _l() {
62 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
63  typedef typename std::initializer_list<value_type>::const_iterator const_iterator;
64 #else // _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
65  typedef const value_type* const_iterator;
66 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
67  for (const_iterator iter = il.begin(); iter != il.end(); ++iter) {
68  _l.push_back(*iter);
69  }
70  }
71 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_LIST
72 
73  void push_back (const value_type& x) { _l.push_back (x); }
74 
75  friend std::ostream& operator<< (std::ostream& o, const csr_concat_line<T,M>& x) {
76  std::cout << "{";
77  for(typename std::list<value_type>::const_iterator iter = x._l.begin(); iter != x._l.end(); ++iter) {
78  std::cout << *iter << " ";
79  }
80  return std::cout << "}";
81  }
82  static void set_sizes (
83  std::pair<size_type,size_type>& row_sizes,
84  std::pair<size_type,size_type>& col_sizes,
85  const std::pair<size_type,size_type>& new_row_sizes,
86  const std::pair<size_type,size_type>& new_col_sizes);
87 
88  static void finalize_sizes (
89  std::pair<size_type,size_type>& sizes,
90  const communicator& comm);
91 
92  static void finalize_sizes (
93  std::vector<std::pair<size_type,size_type> >& sizes,
94  const communicator& comm);
95 
96  void build_csr_pass0 (
97  std::pair<size_type,size_type>& row_sizes,
98  std::vector<std::pair<size_type,size_type> >& col_sizes,
99  communicator& comm) const;
100 
101  void build_csr_pass1 (
102  const std::pair<size_type,size_type>& row_sizes,
103  const std::vector<std::pair<size_type,size_type> >& col_sizes,
104  const communicator& comm,
105  distributor& row_ownership,
106  distributor& col_ownership,
107  std::vector<distributor>& col_start_by_component) const;
108 
109  void build_csr_pass2 (
110  asr<T,M>& a,
111  const std::vector<std::pair<size_type,size_type> >& col_sizes,
112  const std::vector<distributor>& col_start_by_component,
113  size_type row_start_comp_i = 0,
114  size_type row_start_comp_dis_i = 0) const;
115 
116  csr<T,M> build_csr () const;
117 
118 protected:
119  std::list<value_type> _l;
120 };
121 
122 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_LIST
123 #define RHEOLEF_csr_cstor(M) \
124 template <class T> \
125 inline \
126 csr<T,M>::csr (const std::initializer_list<csr_concat_value<T,M> >& init_list) \
127 { \
128  csr_concat_line<T,M> cc (init_list); \
129  csr<T,M>::operator= (cc.build_csr()); \
130 }
131 RHEOLEF_csr_cstor(sequential)
132 #ifdef _RHEOLEF_HAVE_MPI
133 RHEOLEF_csr_cstor(distributed)
134 #endif // _RHEOLEF_HAVE_MPI
135 #undef RHEOLEF_csr_cstor
136 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_LIST
137 
138 template <class T, class M>
139 struct csr_concat {
140  typedef typename csr<T,M>::size_type size_type;
143  csr_concat () : _l() {}
144 
145 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_LIST
146  csr_concat (const std::initializer_list<line_type>& il) : _l() {
147 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
148  typedef typename std::initializer_list<line_type>::const_iterator const_iterator;
149 #else // _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
150  typedef const line_type* const_iterator;
151 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
152  for(const_iterator iter = il.begin(); iter != il.end(); ++iter) {
153  _l.push_back(*iter);
154  }
155  }
156 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_LIST
157 
158  void push_back (const line_type& line) { _l.push_back(line); }
159 
160 #ifdef TO_CLEAN
161  friend std::ostream& operator<< (std::ostream& o, const csr_concat<T,M>& x) {
162  std::cout << "{";
163  for(typename std::list<line_type>::const_iterator iter = x._l.begin(); iter != x._l.end(); ++iter) {
164  std::cout << *iter << " ";
165  }
166  return std::cout << "}";
167  }
168 #endif // TO_CLEAN
169 
170  csr<T,M> build_csr () const;
171 
172 protected:
173  std::list<line_type> _l;
174 };
175 
176 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_LIST
177 #define RHEOLEF_csr_cstor(M) \
178 template <class T> \
179 inline \
180 csr<T,M>::csr (const std::initializer_list<csr_concat_line<T,M> >& init_list) \
181 { \
182  csr_concat<T,M> cc (init_list); \
183  csr<T,M>::operator= (cc.build_csr()); \
184 }
185 RHEOLEF_csr_cstor(sequential)
186 #ifdef _RHEOLEF_HAVE_MPI
187 RHEOLEF_csr_cstor(distributed)
188 #endif // _RHEOLEF_HAVE_MPI
189 #undef RHEOLEF_csr_cstor
190 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_LIST
191 
192 } // namespace rheolef
193 #endif // _RHEOLEF_CSR_CONCAT_H
distributor - data distribution table
Definition: distributor.h:19
csr< T, M > build_csr() const
Definition: csr_concat.cc:301
csr_concat_value(const vec_trans< T, M > &vt)
Definition: csr_concat.h:41
csr_concat_value(const vec< T, M > &x)
Definition: csr_concat.h:40
csr< T, M >::size_type size_type
Definition: csr_concat.h:140
const communicator & comm() const
Definition: diststream.h:240
static void set_sizes(std::pair< size_type, size_type > &row_sizes, std::pair< size_type, size_type > &col_sizes, const std::pair< size_type, size_type > &new_row_sizes, const std::pair< size_type, size_type > &new_col_sizes)
Definition: csr_concat.cc:9
irheostream, orheostream - large data streams
Definition: compiler.h:7
void build_csr_pass0(std::pair< size_type, size_type > &row_sizes, std::vector< std::pair< size_type, size_type > > &col_sizes, communicator &comm) const
Definition: csr_concat.cc:59
csr_concat_value< T, M > value_type
Definition: csr_concat.h:57
csr_concat_value(const csr< T, M > &x)
Definition: csr_concat.h:44
csr_concat_line< T, M > line_type
Definition: csr_concat.h:141
vec_trans(const vec< T, M > &w)
Definition: csr_concat.h:12
void build_csr_pass2(asr< T, M > &a, const std::vector< std::pair< size_type, size_type > > &col_sizes, const std::vector< distributor > &col_start_by_component, size_type row_start_comp_i=0, size_type row_start_comp_dis_i=0) const
Definition: csr_concat.cc:172
csr_concat_value(const std::vector< vec< T, M > > &x)
Definition: csr_concat.h:42
void build_csr_pass1(const std::pair< size_type, size_type > &row_sizes, const std::vector< std::pair< size_type, size_type > > &col_sizes, const communicator &comm, distributor &row_ownership, distributor &col_ownership, std::vector< distributor > &col_start_by_component) const
Definition: csr_concat.cc:151
csr< T, M >::size_type size_type
Definition: csr_concat.h:56
static void finalize_sizes(std::pair< size_type, size_type > &sizes, const communicator &comm)
Definition: csr_concat.cc:37
std::list< line_type > _l
Definition: csr_concat.h:173
void push_back(const value_type &x)
Definition: csr_concat.h:73
vector_vec_trans(const std::vector< vec< T, M > > &w)
Definition: csr_concat.h:23
csr_concat_value(const T &x)
Definition: csr_concat.h:39
vec< T, M > v
Definition: csr_concat.h:11
std::list< value_type > _l
Definition: csr_concat.h:119
vec - vector in distributed environment
Definition: vec.h:44
csr< T, M > build_csr() const
Definition: csr_concat.cc:281
csr_concat_value(const vector_vec_trans< T, M > &vt)
Definition: csr_concat.h:43
csr< T, sequential > trans(const csr< T, sequential > &a)
Definition: csr.h:383
void push_back(const line_type &line)
Definition: csr_concat.h:158
csr - compressed sparse row matrix
Definition: asr.h:8
asr - associative sparse matrix
Definition: asr.h:26
csr_concat_value< T, M > value_type
Definition: csr_concat.h:142
std::vector< vec< T, M > > vv
Definition: csr_concat.h:49
std::vector< vec< T, M > > v
Definition: csr_concat.h:22