~ubuntu-branches/ubuntu/trusty/rheolef/trusty

« back to all changes in this revision

Viewing changes to skit/plib2/csr_cumul_trans_mult.h

  • Committer: Package Import Robot
  • Author(s): Pierre Saramito
  • Date: 2012-04-06 09:12:21 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120406091221-m58me99p1nxqui49
Tags: 6.0-1
* New upstream release 6.0 (major changes):
  - massively distributed and parallel support
  - full FEM characteristic method (Lagrange-Gakerkin method) support
  - enhanced users documentation 
  - source code supports g++-4.7 (closes: #667356)
* debian/control: dependencies for MPI distributed solvers added
* debian/rules: build commands simplified
* debian/librheolef-dev.install: man1/* to man9/* added
* debian/changelog: package description rewritted (closes: #661689)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ifndef _SKIT_CSR_CUMUL_TRANS_MULT_H
 
2
# define _SKIT_CSR_CUMUL_TRANS_MULT_H
 
3
///
 
4
/// This file is part of Rheolef.
 
5
///
 
6
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
 
7
///
 
8
/// Rheolef is free software; you can redistribute it and/or modify
 
9
/// it under the terms of the GNU General Public License as published by
 
10
/// the Free Software Foundation; either version 2 of the License, or
 
11
/// (at your option) any later version.
 
12
///
 
13
/// Rheolef is distributed in the hope that it will be useful,
 
14
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
/// GNU General Public License for more details.
 
17
///
 
18
/// You should have received a copy of the GNU General Public License
 
19
/// along with Rheolef; if not, write to the Free Software
 
20
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
/// 
 
22
/// =========================================================================
 
23
//
 
24
// CSR: Compressed Sparse Row format
 
25
//
 
26
// algorithm-oriented generic library
 
27
// inspired from sparskit2 fortran library
 
28
//  
 
29
// author: Pierre.Saramito@imag.fr
 
30
//  
 
31
// date: 12 november 1997
 
32
//  
 
33
//@!\vfill\listofalgorithms
 
34
/*@! 
 
35
 \vfill \pagebreak \mbox{} \vfill \begin{algorithm}[h]
 
36
  \caption{{\tt trans\_mult}: sparse matrix $y += a^T*x$, where $x,y$ are dense vectors.}
 
37
  \begin{algorithmic}
 
38
    \INPUT {sparse matrix a and dense vector x}
 
39
      ia(0:nrowa), ja(0:nnza-1), a(0:nnza-1),
 
40
      x(0:nrowa)
 
41
    \ENDINPUT
 
42
    \OUTPUT {number of non-null elements in $z=x\pm y$}
 
43
      y(0:ncola)
 
44
    \ENDOUTPUT
 
45
    \NOTE {}
 
46
      The $y$ vector may be set to zero before the call in order to 
 
47
      compute $y := a^T*x$
 
48
    \ENDNOTE
 
49
    \BEGIN 
 
50
      \FORTO {i := 0}{nrowa-1}
 
51
          \FORTO {p := ia(i)}{ia(i+1)-1}
 
52
              y(ja(p)) += a(p) * x(i)
 
53
          \ENDFOR
 
54
      \ENDFOR
 
55
    \END
 
56
 \end{algorithmic} \end{algorithm}
 
57
 \vfill \pagebreak \mbox{} \vfill
 
58
*/
 
59
namespace rheolef { 
 
60
 
 
61
template <
 
62
    class InputIterator1,
 
63
    class InputIterator3,
 
64
    class SetOperator,
 
65
    class RandomAccessMutableIterator>
 
66
void
 
67
csr_cumul_trans_mult (
 
68
    InputIterator1 ia,
 
69
    InputIterator1 last_ia,
 
70
    InputIterator3 x,
 
71
    SetOperator set_op, // set_op: += or -= but not = because may cumul
 
72
    RandomAccessMutableIterator y)
 
73
{
 
74
    typedef typename std::iterator_traits<InputIterator1>::value_type InputIterator2;
 
75
    typedef typename std::iterator_traits<RandomAccessMutableIterator>::value_type T;
 
76
    InputIterator2 a = (*ia++);
 
77
    while (ia != last_ia) {
 
78
        T xi = *x++;
 
79
        InputIterator2 last_a = (*ia++);
 
80
        while (a != last_a) {
 
81
            set_op (y [(*a).first], (*a).second * xi);
 
82
            ++a;
 
83
        }
 
84
    }
 
85
}
 
86
//@!\vfill
 
87
}// namespace rheolef
 
88
# endif // _SKIT_CSR_CUMUL_TRANS_MULT_H