Newer
Older
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* adiosMath.h math functions used in the ADIOS framework
*
* Created on: May 17, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#ifndef ADIOS2_HELPER_ADIOSMATH_H_
#define ADIOS2_HELPER_ADIOSMATH_H_
/// \cond EXCLUDE_FROM_DOXYGEN
#include <vector>
/// \endcond
#include "adios2/ADIOSTypes.h"
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{
/**
* Loops through a vector containing dimensions and returns the product of all
* elements
* @param dimensions input containing size on each dimension {Nx, Ny, Nz}
* @return product of all dimensions Nx * Ny * Nz
*/
size_t GetTotalSize(const Dims &dimensions) noexcept;
/**
* Gets the min and max from a values array of primitive types (not including
* complex)
* @param values input array
* @param size of values array
* @param min of values
* @param max of values
*/
template <class T>
void GetMinMax(const T *values, const size_t size, T &min, T &max) noexcept;
/**
* Version for complex types of GetMinMax, gets the "doughnut" range between min
* and max modulus. Needed a different function as thread can't resolve the
* overload of a GetMinMax with complex types
* @param values array of complex numbers
* @param size of the values array
* @param min modulus from values
* @param max modulus from values
*/
template <class T>
void GetMinMaxComplex(const std::complex<T> *values, const size_t size, T &min,
T &max) noexcept;
/**
* Threaded version of GetMinMax.
* Gets the min and max from a values array of primitive types (not including
* complex) using threads
* @param values input array of complex
* @param size of values array
* @param min of values
* @param max of values
* @param threads used for parallel computation
*/
template <class T>
void GetMinMaxThreads(const T *values, const size_t size, T &min, T &max,
const unsigned int threads = 1) noexcept;
/**
* Overloaded version of GetMinMaxThreads for complex types
* @param values input array of complex
* @param size of values array
* @param min of values
* @param max of values
* @param threads used for parallel computation
*/
template <class T>
void GetMinMaxThreads(const std::complex<T> *values, const size_t size, T &min,
T &max, const unsigned int threads = 1) noexcept;
/**
* Check if index is within (inclusive) limits
* lowerLimit <= index <= upperLimit
* @param index input to be checked
* @param upperLimit
* @param lowerLimit
* @return true index is within limits
*/
bool CheckIndexRange(const int index, const int upperLimit,
const int lowerLimit = 0) noexcept;
/**
* Returns the appropriate size larger than requiredSize
* @param requiredSize
* @param currentSize
* @param growthFactor larger than 1. (typically 1.5 or 2. )
* @return next currentSize * growthFactor^n (n is a signed integer) larger than
* requiredSize
*/
size_t NextExponentialSize(const size_t requiredSize, const size_t currentSize,
const float growthFactor) noexcept;
/**
* Returns the intersection box { start, end } from box1 and box2
* @param box1
* @param box2
* @return empty if not interception, otherwise intersection box
*/
Box<Dims> IntersectionBox(const Box<Dims> &box1,
const Box<Dims> &box2) noexcept;
/**
* Get a linear index for a point inside a localBox
* @param localBox start and count
* @param point inside box
* @param isRowMajor
* @param isZeroIndex
* @return linear index for contiguous memory
*/
size_t LinearIndex(const Box<Dims> &localBox, const Dims &point,
const bool isRowMajor, const bool isZeroIndex);
#include "adiosMath.inl"
#endif /* ADIOS2_HELPER_ADIOSMATH_H_ */