Rheolef  7.2
an efficient C++ finite element environment
asr_to_csr_dist_logical.h
Go to the documentation of this file.
1 #ifndef _ASR_TO_CSR_DIST_LOGICAL_H
2 #define _ASR_TO_CSR_DIST_LOGICAL_H
23 
24 namespace rheolef {
25 /*F:
26 NAME: asr_to_csr_dist_logical -- sparse matrix convertion (@PACKAGE@ @VERSION@)
27 DESCRIPTION:
28  Logical pass for the
29  distributed "asr" to the distributed "csr" sparse matrix format
30  conversion.
31  Build the set of column indexes out of
32  the current processor range, and return the
33  size of this set.
34 ALGORITHM:
35  asr_to_csr_dist_logical
36 
37  "input": the sparse asr matrix
38  | ia(0:2*nrow+1), a(0:nnz-1), is_dia(.)
39  "output": the external column set
40  | colext(0:ncolext-1)
41  begin
42  | for i := 0 to nrow-1 do
43  | for p := ia(2*i) to ia(2*i+1)-1 do
44  | if not is_dia(a(p)) then
45  | colext(ncolext) := a(p)
46  | ncolext := ncolext + 1
47  | endif
48  | endfor
49  | endfor
50  end
51 NOTE:
52  Practical implementation build the sorted set
53  "colext" by using STL set.
54 
55  The predicate "is_dia" returns true when the matrix entry
56  has its column in the local column range of the processor.
57 COMPLEXITY:
58  Time and memory complexity is O(nnz + ncolext*log(ncolext)).
59 METHODS: @asr_to_csr_dist_logical
60 AUTHORS:
61  LMC-IMAG, 38041 Grenoble cedex 9, France
62  | Pierre.Saramito@imag.fr
63 DATE: 22 march 1999
64 END:
65 */
66 
67 //<asr_to_csr_dist_logical:
68 template <
69  class InputPtrIterator,
70  class Predicate,
71  class Set>
72 typename Set::value_type
74  InputPtrIterator iter_ptr_a,
75  InputPtrIterator last_ptr_a,
76  Predicate is_dia,
77  Set& colext)
78 {
79  typedef typename std::iterator_traits<InputPtrIterator>::value_type Row;
80  typedef typename Row::const_iterator InputDataIterator;
81  typedef typename Set::value_type Size;
82 
83  Size nnzext = 0;
84  while (iter_ptr_a != last_ptr_a) {
85  InputDataIterator iter_data_a = (*iter_ptr_a).begin();
86  InputDataIterator last_data_a = (*iter_ptr_a).end();
87  iter_ptr_a++;
88  while (iter_data_a != last_data_a) {
89  if (!is_dia(*iter_data_a)) {
90  colext.insert((*iter_data_a).first);
91  nnzext++;
92  }
93  iter_data_a++;
94  }
95  }
96  return nnzext;
97 }
98 template <class Size, class Pair>
99 struct is_dia_t : public std::unary_function<Pair, bool> {
100  bool operator()(const Pair& x) const {
101  return x.first >= j1 && x.first < j2; }
102  is_dia_t(Size k1, Size k2) : j1(k1), j2(k2) {}
103  Size j1, j2;
104 };
105 } // namespace rheolef
106 //>asr_to_csr_dist_logical:
107 #endif // _ASR_TO_CSR_DIST_LOGICAL_H
This file is part of Rheolef.
Set::value_type asr_to_csr_dist_logical(InputPtrIterator iter_ptr_a, InputPtrIterator last_ptr_a, Predicate is_dia, Set &colext)
bool operator()(const Pair &x) const
is_dia_t(Size k1, Size k2)