ug4
blas_vec_interface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3  * Author: Martin Rupp
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef BLAS_VEC_INTERFACE_H_
34 #define BLAS_VEC_INTERFACE_H_
35 
36 
37 // specializations for double
39 inline void VecScaleAssign(double &dest, double alpha1, const double &v1)
40 {
41  dest = alpha1*v1;
42 }
43 // and so on.
44 
45 
47 //
48 template<typename vector_t>
49 inline void VecScaleAssign(vector_t &dest, double alpha1, const vector_t &v1)
50 {
51  for(size_t i=0; i<dest.size(); i++)
52  VecScaleAssign(dest[i], alpha1, v1[i]);
53 }
54 
56 //
57 template<typename vector_t>
58 inline void VecAssign(vector_t &dest, const vector_t &v1)
59 {
60  for(size_t i=0; i<dest.size(); i++)
61  dest[i]=v1[i];
62 }
63 
64 
66 template<typename vector_t>
67 inline void VecScaleAdd(vector_t &dest, double alpha1, const vector_t &v1, double alpha2, const vector_t &v2);
68 
70 template<typename vector_t>
71 inline void VecScaleAdd(vector_t &dest, double alpha1, const vector_t &v1, double alpha2, const vector_t &v2, double alpha3, const vector_t &v3);
72 
73 
75 template<typename vector_t>
76 inline void VecAdd(vector_t &dest, vector_t &v);
77 
79 template<typename vector_t>
80 inline void VecSubstract(vector_t &dest, vector_t &v);
81 
82 
83 // VecProd
84 
86 template<typename vector_t>
87 inline void VecProdAdd(const vector_t &a, const vector_t &b, double &sum)
88 {
89  for(size_t i=0; i<a.size(); i++) VecProdAdd(a[i], b[i], sum);
90 }
91 
93 template<typename vector_t>
94 inline double VecProd(const vector_t &a, const vector_t &b)
95 {
96  double sum=0;
97  VecProdAdd(a, b, sum);
98  return sum;
99 }
100 
101 // VecNorm
102 
104 template<typename vector_t>
105 inline void VecNormSquaredAdd(const vector_t &a, const vector_t &b, double &sum)
106 {
107  for(int i=0; i<a.size(); i++) VecNormSquaredAdd(a[i], sum);
108 }
109 
111 template<typename vector_t>
112 inline double VecNormSquared(const vector_t &a, const vector_t &b)
113 {
114  double sum=0;
115  VecNormSquaredAdd(a, sum);
116  return sum;
117 }
118 
119 #endif /* BLAS_VEC_INTERFACE_H_ */
void VecScaleAdd(vector_t &dest, double alpha1, const vector_t &v1, double alpha2, const vector_t &v2)
calculates dest = alpha1*v1 + alpha2*v2
void VecAdd(vector_t &dest, vector_t &v)
calculates dest = dest + v
void VecAssign(vector_t &dest, const vector_t &v1)
calculates dest = v1
Definition: blas_vec_interface.h:58
double VecProd(const vector_t &a, const vector_t &b)
returns scal<a, b>
Definition: blas_vec_interface.h:94
void VecProdAdd(const vector_t &a, const vector_t &b, double &sum)
calculates s += scal<a, b>
Definition: blas_vec_interface.h:87
double VecNormSquared(const vector_t &a, const vector_t &b)
returns norm_2^2(a)
Definition: blas_vec_interface.h:112
void VecSubstract(vector_t &dest, vector_t &v)
calculates dest = dest - v
void VecNormSquaredAdd(const vector_t &a, const vector_t &b, double &sum)
calculates s += norm_2^2(a)
Definition: blas_vec_interface.h:105
void VecScaleAssign(double &dest, double alpha1, const double &v1)
calculates dest = alpha1*v1. for doubles
Definition: blas_vec_interface.h:39