Nektar++
library
LibUtilities
BasicUtils
VDmath.hpp
Go to the documentation of this file.
1
///////////////////////////////////////////////////////////////////////////////
2
//
3
// File DVmath.hpp
4
//
5
// For more information, please see: http://www.nektar.info
6
//
7
// The MIT License
8
//
9
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10
// Department of Aeronautics, Imperial College London (UK), and Scientific
11
// Computing and Imaging Institute, University of Utah (USA).
12
//
13
// Permission is hereby granted, free of charge, to any person obtaining a
14
// copy of this software and associated documentation files (the "Software"),
15
// to deal in the Software without restriction, including without limitation
16
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
// and/or sell copies of the Software, and to permit persons to whom the
18
// Software is furnished to do so, subject to the following conditions:
19
//
20
// The above copyright notice and this permission notice shall be included
21
// in all copies or substantial portions of the Software.
22
//
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29
// DEALINGS IN THE SOFTWARE.
30
//
31
// Description: Collection of templated functions for distributed vector
32
// mathematics
33
//
34
///////////////////////////////////////////////////////////////////////////////
35
36
#ifndef NEKTAR_LIB_LIBUTILITIES_BASSICUTILS_VECTORDISTMATH_HPP
37
#define NEKTAR_LIB_LIBUTILITIES_BASSICUTILS_VECTORDISTMATH_HPP
38
39
#include <
LibUtilities/Communication/Comm.h
>
40
41
namespace
VDmath
42
{
43
/// \brief vvtvp (vector times vector times vector): z = w*x*y
44
template
<
class
T> T
Ddot2
(
Nektar::LibUtilities::CommSharedPtr
& pComm,
45
int
n,
46
const
T *w,
47
const
T *x,
48
const
int
*y)
49
{
50
T sum = 0;
51
52
while
( n-- )
53
{
54
sum += (*y == 1 ? (*w) * (*x) : 0 );
55
++w;
56
++x;
57
++y;
58
}
59
pComm->AllReduce(sum,
Nektar::LibUtilities::ReduceSum
);
60
return
sum;
61
}
62
63
/// \brief vvtvp (vector times vector times vector): z = w*x*y
64
template
<
class
T> T
Ddot2
(
Nektar::LibUtilities::CommSharedPtr
& pComm,
65
int
n,
66
const
T *w,
const
int
incw,
67
const
T *x,
const
int
incx,
68
const
int
*y,
const
int
incy)
69
{
70
T sum = 0;
71
72
while
( n-- )
73
{
74
sum += (*y == 1 ? (*w) * (*x) : 0.0 );
75
w += incw;
76
x += incx;
77
y += incy;
78
}
79
pComm->AllReduce(sum,
Nektar::LibUtilities::ReduceSum
);
80
return
sum;
81
}
82
}
83
#endif
/* DVMATH_HPP_ */
Nektar::LibUtilities::ReduceSum
Definition:
Comm.h:67
Nektar::LibUtilities::CommSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition:
Comm.h:53
VDmath
Definition:
VDmath.hpp:41
Comm.h
VDmath::Ddot2
T Ddot2(Nektar::LibUtilities::CommSharedPtr &pComm, int n, const T *w, const T *x, const int *y)
vvtvp (vector times vector times vector): z = w*x*y
Definition:
VDmath.hpp:44
Generated on Wed Jan 20 2021 03:33:43 for Nektar++ by
1.8.13