Rheolef  7.1
an efficient C++ finite element environment
csr_amux.h
Go to the documentation of this file.
1 # ifndef _SKIT_CSR_AMUX_H
2 # define _SKIT_CSR_AMUX_H
3 
24 # include "rheolef/compiler.h"
25 
26 namespace rheolef {
27 /*F:
28 NAME: csr_amux -- mat-vec product (@PACKAGE@ @VERSION@)
29 DESCRIPTION:
30  Performs the product "A*x" where "A" is a sparse matrix in
31  CSR format and "x" a dense vector.
32 ALGORITHM:
33 
34  csr_amux
35 
36  "input": the matrix in CSR format and the dense vector
37  | ia(0:nrow), ja(0:nnz-1), a(0:nnz-1),
38  | x(0:ncol-1)
39  "output": the result as dense vector
40  | y(0:nrow-1)
41  begin
42  | for i := 0 to nrow-1 do
43  | sum := 0
44  | for p := ia(i) to ia(i+1)-1 do
45  | sum := sum + a(p) * x(ja(p))
46  | endfor
47  | y(i) := sum
48  end
49 COMPLEXITY:
50  Complexity is "O(nz)" where "nz" is the number of non-zero
51  entries of "A".
52 IMPLEMENTATION:
53  "ja" and "a" arrays are merged in an array of pair.
54 
55  The "ia" is an array of pointer in the array of pair.
56 
57  Arrays are abstractred by using STL iterators.
58 
59  The operation "y := A*x" is extended to "y += A*x" and so
60  by using and abstract set-operator in
61  the instruction "y(i) := sum.
62 METHODS: @csr_amux
63 AUTHORS:
64  LMC-IMAG, 38041 Grenoble cedex 9, France
65  | Pierre.Saramito@imag.fr
66 DATE: 14 may 1999
67 END:
68 */
69 
70 //<csr_amux:
71 template <
72  class InputIterator,
73  class InputRandomAcessIterator,
74  class SetOperator,
75  class OutputIterator>
76 void
78  InputIterator ia,
79  InputIterator last_ia,
80  InputRandomAcessIterator x,
81  SetOperator set_op,
82  OutputIterator y)
83 {
84  typedef typename std::iterator_traits<InputIterator>::value_type InputIterator2;
85  typedef typename std::iterator_traits<OutputIterator>::value_type T;
86  InputIterator2 a = (*ia++);
87  while (ia != last_ia) {
88  T sum = 0;
89  InputIterator2 last_a = (*ia++);
90  while (a != last_a) {
91  sum += (*a).second * x[(*a).first];
92  ++a;
93  }
94  set_op(*y++, sum);
95  }
96 }
97 //>csr_amux:
98 //@!\vfill
99 } // namespace rheolef
100 #endif // _SKIT_CSR_AMUX_H
rheolef::csr_amux
void csr_amux(InputIterator ia, InputIterator last_ia, InputRandomAcessIterator x, SetOperator set_op, OutputIterator y)
Definition: csr_amux.h:77
a
Definition: diffusion_isotropic.h:25
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
mkgeo_ball.a
a
Definition: mkgeo_ball.sh:151
rheolef::set_op
Definition: msg_util.h:56
T
Expr1::float_type T
Definition: field_expr.h:218