rheolef  6.3
doc/pexamples/aa.cc
Go to the documentation of this file.
1 
2 template <class T, class M>
3 struct csr_concat {
4  typedef typename csr<T,M>::size_type size_type;
5  typedef csr_concat_line<T,M> line_type;
6  typedef csr_concat_value<T,M> value_type;
7  csr_concat () : _l() {}
8  csr_concat (const std::initializer_list<line_type>& il) : _l() {
9 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
10  typedef typename std::initializer_list<line_type>::const_iterator const_iterator;
11 #else // _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
12  typedef const line_type* const_iterator;
13 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_ITERATOR
14  for(const_iterator iter = il.begin(); iter != il.end(); ++iter) {
15  _l.push_back(*iter);
16  }
17  }
18  friend std::ostream& operator<< (std::ostream& o, const csr_concat<T,M>& x) {
19  std::cout << "{";
20  for(typename std::list<line_type>::const_iterator iter = x._l.begin(); iter != x._l.end(); ++iter) {
21  std::cout << *iter << " ";
22  }
23  return std::cout << "}";
24  }
25  void build_csr_pass1 (distributor& row_ownership, distributor& col_ownership) const;
26  csr<T,M> build_csr_pass2 (asr<T,M>& a) const;
27  csr<T,M> build_csr () const;
28 
29 protected:
30  std::list<line_type> _l;
31 };
32 template <class T, class M>
33 csr<T,M>
35 {
36  distributor col_ownership;
37  bool has_col = false;
38  size_type nrow = 0;
39  size_type dis_nrow = 0;
40  std::list<std::pair<size_type,size_type> > nrow_list;
41  for(typename std::list<line_type>::const_iterator iter = _l.begin(); iter != _l.end(); ++iter) {
42  const line_type& line = *iter;
43  distributor row_line_ownership;
44  distributor col_line_ownership;
45  line.build_csr_pass1 (row_line_ownership, col_line_ownership);
46  if (!has_col) {
47  has_col = true;
48  col_ownership = col_line_ownership;
49  } else {
50  check_macro (col_line_ownership == col_ownership,
51  "matrix initializer list: matrix col argument [0:" <<col_line_ownership.dis_size() << "["
52  << " has incomptible size: expect [0:" <<col_ownership.dis_size() << "[");
53  }
54  nrow_list.push_back (std::make_pair(row_line_ownership.size(), row_line_ownership.dis_size()));
55  nrow += row_line_ownership.size();
56  dis_nrow += row_line_ownership.dis_size();
57  }
58  communicator comm = col_ownership.comm();
59  distributor row_ownership (dis_nrow, comm, nrow);
60  asr<T,M> a (row_ownership, col_ownership);
61  size_type block_i = 0;
62  size_type block_dis_i = 0;
63  typename std::list<std::pair<size_type,size_type> >::const_iterator iter_nrow = nrow_list.begin();
64  for(typename std::list<line_type>::const_iterator iter = _l.begin(); iter != _l.end(); ++iter, ++iter_nrow) {
65  const line_type& line = *iter;
66  line.build_csr_pass2 (a, block_i, block_dis_i);
67  block_i += (*iter_nrow).first;
68  block_dis_i += (*iter_nrow).second;
69  }
70  a.dis_entry_assembly();
71  return csr<T,M>(a);
72 }
73 #define RHEOLEF_csr_cstor(M) \
74 template <class T> \
75 inline \
76 csr<T,M>::csr (const std::initializer_list<csr_concat_line<T,M> >& init_list) \
77 { \
78  csr_concat<T,M> cc (init_list); \
79  csr<T,M>::operator= (cc.build_csr()); \
80 }
81 RHEOLEF_csr_cstor(sequential)
82 #ifdef _RHEOLEF_HAVE_MPI
84 #endif // _RHEOLEF_HAVE_MPI
85 #undef RHEOLEF_csr_cstor
86 
87 } // namespace rheolef
88 #endif // _RHEOLEF_CSR_CONCAT_H
89