Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
39inline void VecScaleAssign(double &dest, double alpha1, const double &v1)
40{
41 dest = alpha1*v1;
42}
43// and so on.
44
45
47//
48template<typename vector_t>
49inline 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//
57template<typename vector_t>
58inline 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
66template<typename vector_t>
67inline void VecScaleAdd(vector_t &dest, double alpha1, const vector_t &v1, double alpha2, const vector_t &v2);
68
70template<typename vector_t>
71inline 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
75template<typename vector_t>
76inline void VecAdd(vector_t &dest, vector_t &v);
77
79template<typename vector_t>
80inline void VecSubstract(vector_t &dest, vector_t &v);
81
82
83// VecProd
84
86template<typename vector_t>
87inline 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
93template<typename vector_t>
94inline 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
104template<typename vector_t>
105inline 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
111template<typename vector_t>
112inline 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