Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
csr_amux.h
Go to the documentation of this file.
1# ifndef _SKIT_CSR_AMUX_H
2# define _SKIT_CSR_AMUX_H
23
24# include "rheolef/compiler.h"
25
26namespace rheolef {
27/*F:
28NAME: csr_amux -- mat-vec product (@PACKAGE@ @VERSION@)
29DESCRIPTION:
30 Performs the product "A*x" where "A" is a sparse matrix in
31 CSR format and "x" a dense vector.
32ALGORITHM:
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
49COMPLEXITY:
50 Complexity is "O(nz)" where "nz" is the number of non-zero
51 entries of "A".
52IMPLEMENTATION:
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.
62METHODS: @csr_amux
63AUTHORS:
64 LMC-IMAG, 38041 Grenoble cedex 9, France
65 | Pierre.Saramito@imag.fr
66DATE: 14 may 1999
67END:
68*/
69
70//<csr_amux:
71template <
72 class InputIterator,
73 class InputRandomAcessIterator,
74 class SetOperator,
75 class OutputIterator>
76void
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
Expr1::float_type T
Definition field_expr.h:230
This file is part of Rheolef.
void csr_amux(InputIterator ia, InputIterator last_ia, InputRandomAcessIterator x, SetOperator set_op, OutputIterator y)
Definition csr_amux.h:77