escript  Revision_
PasoUtil.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2020 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14 * Development from 2019 by School of Earth and Environmental Sciences
15 **
16 *****************************************************************************/
17 
18 
19 #ifndef __PASO_UTIL_H__
20 #define __PASO_UTIL_H__
21 
22 /****************************************************************************/
23 
24 /* Some utility routines: */
25 
26 /****************************************************************************/
27 
28 /* Copyrights by ACcESS Australia, 2003,2004,2005 */
29 /* author: l.gross@uq.edu.au */
30 
31 /****************************************************************************/
32 
33 #include "Paso.h"
34 
35 namespace paso {
36 
37 namespace util {
38 
41 void applyGivensRotations(dim_t N, double* v, const double* c, const double* s);
42 
44 index_t arg_max(dim_t N, dim_t* lambda);
45 
47 int comparIndex(const void* index1, const void* index2);
48 
50 index_t cumsum(dim_t N, index_t* array);
51 
52 index_t cumsum_maskedTrue(dim_t N, index_t* array, int* mask);
53 
54 index_t cumsum_maskedFalse(dim_t N, index_t* array, int* mask);
55 
57 index_t iMax(dim_t N, const index_t* array);
58 
60 double innerProduct(dim_t N, const double* x, const double* y,
61  escript::JMPI mpiInfo);
62 
64 bool isAny(dim_t N, const index_t* array, index_t value);
65 
67 double l2(dim_t N, const double* x, escript::JMPI mpiInfo);
68 
71 void linearCombination(dim_t N, double* z, double a, const double* x, double b,
72  const double* y);
73 
75 double lsup(dim_t N, const double* x, escript::JMPI mpiInfo);
76 
78 dim_t numPositives(dim_t N, const double* x, escript::JMPI mpiInfo);
79 
82 void update(dim_t N, double a, double* x, double b, const double* y);
83 
85 void zeroes(dim_t N, double* x);
86 
88 inline void copy(dim_t N, double* out, const double* in)
89 {
90  linearCombination(N, out, 1., in, 0., in);
91 }
92 
94 inline void scale(dim_t N, double* x, double a)
95 {
96  update(N, a, x, 0, x);
97 }
98 
100 inline void AXPY(dim_t N, double* x, double a, const double* y)
101 {
102  update(N, 1., x, a, y);
103 }
104 
106 inline bool samesign(double a, double b)
107 {
108  return (a>=0 && b>=0) || (a<=0 && b<=0);
109 }
110 
111 } // namespace util
112 } // namespace paso
113 
114 #endif // __PASO_UTIL_H__
115 
paso::util::iMax
index_t iMax(dim_t N, const index_t *array)
returns the maximum value in integer array
Definition: PasoUtil.cpp:91
paso::util::arg_max
index_t arg_max(dim_t n, dim_t *lambda)
returns the index to the largest entry in lambda
Definition: PasoUtil.cpp:295
paso::N
static dim_t N
Definition: SparseMatrix_saveHB.cpp:50
paso::util::lsup
double lsup(dim_t n, const double *x, escript::JMPI mpiinfo)
returns the global Lsup of x
Definition: PasoUtil.cpp:492
escript::DataTypes::index_t_min
index_t index_t_min()
Returns the minimum finite value for the index_t type.
Definition: DataTypes.h:96
paso::util::cumsum
index_t cumsum(dim_t N, index_t *array)
calculates the cumulative sum in array and returns the total sum
Definition: PasoUtil.cpp:112
MPI_SUM
#define MPI_SUM
Definition: EsysMPI.h:51
paso::util::samesign
bool samesign(double a, double b)
returns true if both arguments have the same sign, false otherwise
Definition: PasoUtil.h:131
paso::util::AXPY
void AXPY(dim_t N, double *x, double a, const double *y)
x = x+a*y
Definition: PasoUtil.h:125
paso::util::numPositives
dim_t numPositives(dim_t N, const double *x, escript::JMPI mpiInfo)
returns the number of positive values in x
Definition: PasoUtil.cpp:65
MPI_MAX
#define MPI_MAX
Definition: EsysMPI.h:53
paso::util::applyGivensRotations
void applyGivensRotations(dim_t n, double *v, const double *c, const double *s)
Definition: PasoUtil.cpp:562
paso::util::cumsum_maskedTrue
index_t cumsum_maskedTrue(dim_t N, index_t *array, int *mask)
Definition: PasoUtil.cpp:165
paso::util::copy
void copy(dim_t N, double *out, const double *in)
out = in
Definition: PasoUtil.h:113
Paso.h
paso::util::update
void update(dim_t n, double a, double *x, double b, const double *y)
Definition: PasoUtil.cpp:365
paso::util::l2
double l2(dim_t n, const double *x, escript::JMPI mpiinfo)
returns the global L2 norm of x
Definition: PasoUtil.cpp:527
paso::util::comparIndex
int comparIndex(const void *index1, const void *index2)
this int-comparison function is used by qsort/bsearch in various places
Definition: PasoUtil.cpp:51
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:90
escript::JMPI
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:71
paso::util::cumsum_maskedFalse
index_t cumsum_maskedFalse(dim_t N, index_t *array, int *mask)
Definition: PasoUtil.cpp:230
paso::util::linearCombination
void linearCombination(dim_t n, double *z, double a, const double *x, double b, const double *y)
Definition: PasoUtil.cpp:414
MPI_DOUBLE
#define MPI_DOUBLE
Definition: EsysMPI.h:46
paso::util::scale
void scale(dim_t N, double *x, double a)
x = a*x
Definition: PasoUtil.h:119
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:85
PasoUtil.h
paso::util::zeroes
void zeroes(dim_t n, double *x)
fills array x with zeroes
Definition: PasoUtil.cpp:345
paso::util::isAny
bool isAny(dim_t N, const index_t *array, index_t value)
returns true if array contains value
Definition: PasoUtil.cpp:56
paso
Definition: BiCGStab.cpp:26
paso::util::innerProduct
double innerProduct(dim_t n, const double *x, const double *y, escript::JMPI mpiinfo)
returns the inner product of global arrays x and y
Definition: PasoUtil.cpp:454