escript  Revision_4925
PasoUtil.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
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 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 
18 #ifndef __PASO_UTIL_H__
19 #define __PASO_UTIL_H__
20 
21 /****************************************************************************/
22 
23 /* Some utility routines: */
24 
25 /****************************************************************************/
26 
27 /* Copyrights by ACcESS Australia, 2003,2004,2005 */
28 /* author: l.gross@uq.edu.au */
29 
30 /****************************************************************************/
31 
32 #include "Paso.h"
33 
34 namespace paso {
35 
36 namespace util {
37 
40 void applyGivensRotations(dim_t N, double* v, const double* c, const double* s);
41 
43 index_t arg_max(dim_t N, dim_t* lambda);
44 
46 int comparIndex(const void* index1, const void* index2);
47 
49 index_t cumsum(dim_t N, index_t* array);
50 
51 index_t cumsum_maskedTrue(dim_t N, index_t* array, int* mask);
52 
53 index_t cumsum_maskedFalse(dim_t N, index_t* array, int* mask);
54 
56 index_t iMax(dim_t N, const index_t* array);
57 
59 double innerProduct(dim_t N, const double* x, const double* y,
60  Esys_MPIInfo* mpiinfo);
61 
63 bool isAny(dim_t N, index_t* array, index_t value);
64 
66 double l2(dim_t N, const double* x, Esys_MPIInfo* mpiinfo);
67 
70 void linearCombination(dim_t N, double* z, double a, const double* x, double b,
71  const double* y);
72 
74 double lsup(dim_t N, const double* x, Esys_MPIInfo* mpiinfo);
75 
77 dim_t numPositives(dim_t N, const double* x);
78 
81 void update(dim_t N, double a, double* x, double b, const double* y);
82 
84 void zeroes(dim_t N, double* x);
85 
87 inline void copy(dim_t N, double* out, const double* in)
88 {
89  linearCombination(N, out, 1., in, 0., in);
90 }
91 
93 inline void scale(dim_t N, double* x, double a)
94 {
95  update(N, a, x, 0, x);
96 }
97 
99 inline void AXPY(dim_t N, double* x, double a, const double* y)
100 {
101  update(N, 1., x, a, y);
102 }
103 
105 inline bool samesign(double a, double b)
106 {
107  return (a>=0 && b>=0) || (a<=0 && b<=0);
108 }
109 
110 } // namespace util
111 } // namespace paso
112 
113 #endif // __PASO_UTIL_H__
114 
double l2(dim_t n, const double *x, Esys_MPIInfo *mpiinfo)
returns the global L2 norm of x
Definition: PasoUtil.cpp:484
index_t arg_max(dim_t n, dim_t *lambda)
returns the index to the largest entry in lambda
Definition: PasoUtil.cpp:275
bool samesign(double a, double b)
returns true if both arguments have the same sign, false otherwise
Definition: PasoUtil.h:105
bool isAny(dim_t N, index_t *array, index_t value)
returns true if array contains value
Definition: PasoUtil.cpp:39
index_t cumsum(dim_t N, index_t *array)
calculates the cumulative sum in array and returns the total sum
Definition: PasoUtil.cpp:105
Struct that holds MPI communicator, rank, size and a tag counter.
Definition: Esys_MPI.h:48
dim_t numPositives(dim_t N, const double *x)
returns the number of positive values in x
Definition: PasoUtil.cpp:63
int comparIndex(const void *index1, const void *index2)
this int-comparison function is used by qsort/bsearch in various places
Definition: PasoUtil.cpp:34
void AXPY(dim_t N, double *x, double a, const double *y)
x = x+a*y
Definition: PasoUtil.h:99
void copy(dim_t N, double *out, const double *in)
out = in
Definition: PasoUtil.h:87
void scale(dim_t N, double *x, double a)
x = a*x
Definition: PasoUtil.h:93
double lsup(dim_t n, const double *x, Esys_MPIInfo *mpiinfo)
returns the global Lsup of x
Definition: PasoUtil.cpp:452
double innerProduct(const dim_t n, const double *x, const double *y, Esys_MPIInfo *mpiinfo)
returns the inner product of global arrays x and y
Definition: PasoUtil.cpp:418
void update(dim_t n, double a, double *x, double b, const double *y)
Definition: PasoUtil.cpp:337
void zeroes(dim_t n, double *x)
fills array x with zeroes
Definition: PasoUtil.cpp:321
static dim_t N
Definition: SparseMatrix_saveHB.cpp:36
index_t cumsum_maskedFalse(dim_t N, index_t *array, int *mask)
Definition: PasoUtil.cpp:214
void linearCombination(dim_t n, double *z, double a, const double *x, double b, const double *y)
Definition: PasoUtil.cpp:382
int index_t
Definition: types.h:25
index_t cumsum_maskedTrue(dim_t N, index_t *array, int *mask)
Definition: PasoUtil.cpp:153
index_t iMax(dim_t N, const index_t *array)
returns the maximum value in integer array
Definition: PasoUtil.cpp:84
int dim_t
Definition: types.h:24
void applyGivensRotations(dim_t n, double *v, const double *c, const double *s)
Definition: PasoUtil.cpp:515