H2Lib
3.0
|
Miscellaneous auxiliary functions and macros. More...
Macros | |
#define | M_PI 3.141592653589793238462643383 |
Mathematical constant . | |
#define | NORM_STEPS 20 |
Number of power iteration steps used to approximate the spectral norm. | |
#define | NC_DEFLATE_LEVEL 9 |
Deflation level for NetCDF compression. More... | |
#define | H2_MACH_EPS 1e-13 |
"Machine accuracy" for some algorithms | |
#define | h2_malloc(sz) malloc(sz) |
Wrapper for either aligned or not align memory allocation function. More... | |
#define | h2_free(p) free(p) |
Wrapper for either aligned or not align memory free function. More... | |
#define | ROUNDUP(x, N) ((((x) + (N) - 1) / (N)) * (N)) |
Round up some value x to the nearest multiple of N. More... | |
#define | REAL(x) creal(x) |
Get the real part of a field element . | |
#define | IMAG(x) cimag(x) |
Get the imaginary part of a field element . | |
#define | CONJ(x) conj(x) |
Compute the complex conjugate of a field element . | |
#define | ABSSQR(x) _h2_abssqr(x) |
Compute the square of the absolute value of a field element . | |
#define | ABS(x) REAL_SQRT(ABSSQR(x)) |
Compute the absolute value of a field element . | |
#define | SIGN1(x) _h2_sgn1(x) |
Compute the sign of a field element with the convention . | |
#define | FIELD_RAND() _h2_fieldrand() |
Compute a (pseudo-)random field element. | |
#define | REAL_ABS(x) fabs(x) |
Compute the absolute value of a real number . | |
#define | REAL_SQR(x) _h2_real_sqr(x) |
Compute the square of a real number . | |
#define | REAL_SIN(x) sin(x) |
Compute the sine of a real number . | |
#define | REAL_COS(x) cos(x) |
Compute the cosine of a real number . | |
#define | REAL_ASIN(x) asin(x) |
Compute the arcsine of a real number . | |
#define | REAL_ACOS(x) acos(x) |
Compute the arccosine of a real number . | |
#define | REAL_TAN(x) tan(x) |
Compute the tangent of a real number . | |
#define | REAL_SQRT(x) sqrt(x) |
Compute the square root of a non-negative real nunber . | |
#define | REAL_RSQRT(x) _h2_rsqrt(x) |
Compute the reciprocal square root of a non-negative real nunber . | |
#define | REAL_POW(x, y) pow(x, y) |
Compute the -th power of a real number . | |
#define | REAL_LOG(x) log(x) |
Compute the natural logarithm of a positive real number . | |
#define | REAL_EXP(x) exp(x) |
Compute the exponetial function of a real number . | |
#define | REAL_RAND() _h2_realrand() |
Compute a (pseudo-)random real number. | |
#define | DOT2(x, y) (CONJ((x)[0]) * (y)[0] + CONJ((x)[1]) * (y)[1]) |
Compute dot product of vectors of dimension 2, i.e. . | |
#define | DOT3(x, y) (CONJ((x)[0]) * (y)[0] + CONJ((x)[1]) * (y)[1] + CONJ((x)[2]) * (y)[2]) |
Compute dot product of vectors of dimension 3, i.e. . | |
#define | NORMSQR2(x, y) (ABSSQR(x) + ABSSQR(y)) |
Compute squared 2-norm of a vector of dimension 2, i.e. . | |
#define | NORMSQR3(x, y, z) (ABSSQR(x) + ABSSQR(y) + ABSSQR(z)) |
Compute squared 2-norm of a vector of dimension 3, i.e. . | |
#define | NORM2(x, y) REAL_SQRT(ABSSQR(x) + ABSSQR(y)) |
Compute 2-norm of a vector of dimension 2, i.e. . | |
#define | NORM3(x, y, z) REAL_SQRT(ABSSQR(x) + ABSSQR(y) + ABSSQR(z)) |
Compute 2-norm of a vector of dimension 3, i.e. . | |
#define | REAL_DOT2(x, y) ((x)[0] * (y)[0] + (x)[1] * (y)[1]) |
Compute dot product of vectors of reals with dimension 2, i.e. . | |
#define | REAL_DOT3(x, y) ((x)[0] * (y)[0] + (x)[1] * (y)[1] + (x)[2] * (y)[2]) |
Compute dot product of vectors of reals with dimension 3, i.e. . | |
#define | REAL_NORMSQR2(x, y) (REAL_SQR(x) + REAL_SQR(y)) |
Compute squared 2-norm of a vector of reals with dimension 2, i.e. . | |
#define | REAL_NORMSQR3(x, y, z) (REAL_SQR(x) + REAL_SQR(y) + REAL_SQR(z)) |
Compute squared 2-norm of a vector of reals with dimension 3, i.e. . | |
#define | REAL_NORM2(x, y) REAL_SQRT(REAL_SQR(x) + REAL_SQR(y)) |
Compute 2-norm of a vector of reals with dimension 2, i.e. . | |
#define | REAL_NORM3(x, y, z) REAL_SQRT(REAL_SQR(x) + REAL_SQR(y) + REAL_SQR(z)) |
Compute 2-norm of a vector of reals with dimension 3, i.e. . | |
#define | REAL_MAX(x, y) _h2_realmax(x, y) |
Compute the maximum of two real numbers and . | |
#define | REAL_MAX3(x, y, z) _h2_realmax3(x, y, z) |
Compute the maximum of three real numbers and . | |
#define | REAL_MIN(x, y) _h2_realmin(x, y) |
Compute the minimum of two real numbers and . | |
#define | REAL_MIN3(x, y, z) _h2_realmin3(x, y, z) |
Compute the minimum of three real numbers and . | |
#define | UINT_MAX(x, y) _h2_uintmax(x, y) |
Compute the maximum of two unsigned integers and . | |
#define | UINT_MAX3(x, y, z) _h2_uintmax3(x, y, z) |
Compute the maximum of three unsigned integers and . | |
#define | UINT_MIN(x, y) _h2_uintmin(x, y) |
Compute the minimum of two unsigned integers and . | |
#define | UINT_MIN3(x, y, z) _h2_uintmin3(x, y, z) |
Compute the minimum of three unsigned integers and . | |
#define | allocmem(sz) _h2_allocmem(sz,__FILE__,__LINE__) |
Allocate heap storage. More... | |
#define | allocuint(sz) _h2_allocuint(sz,__FILE__,__LINE__) |
Allocate heap storage of type uint. More... | |
#define | allocreal(sz) _h2_allocreal(sz,__FILE__,__LINE__) |
Allocate heap storage of type real. More... | |
#define | allocfield(sz) _h2_allocfield(sz,__FILE__,__LINE__) |
Allocate heap storage of type field. More... | |
#define | allocmatrix(rows, cols) _h2_allocmatrix(rows,cols,__FILE__,__LINE__) |
Allocate heap storage for a matrix. More... | |
#define | heapsort(n, leq, swap, data) _h2_heapsort(n,leq,swap,data) |
Heapsort algorithm. More... | |
Typedefs | |
typedef struct _stopwatch | stopwatch |
Stop watch for run-time measurements. | |
typedef stopwatch * | pstopwatch |
Pointer to a stopwatch object. | |
Functions | |
void | init_h2lib (int *argc, char ***argv) |
Initialize the library. More... | |
void | uninit_h2lib () |
Uninitialize the library. More... | |
size_t | get_current_memory () |
Current amount of allocated memory (bytes) More... | |
void | freemem (void *ptr) |
Release allocated storage. More... | |
pstopwatch | new_stopwatch () |
Create a stopwatch object. More... | |
void | del_stopwatch (pstopwatch sw) |
Delete a stopwatch object. More... | |
void | start_stopwatch (pstopwatch sw) |
Start a stopwatch. More... | |
real | stop_stopwatch (pstopwatch sw) |
Stop a stopwatch. More... | |
cairo_t * | new_cairopdf (const char *filename, double width, double height) |
Create a PDF canvas for Cairo drawing. More... | |
cairo_t * | new_cairopng (uint width, uint height) |
Create a PNG canvas for Cairo drawing. More... | |
bool | write_cairopng (cairo_t *cr, const char *filename) |
Write Cairo image to PNG file. More... | |
Variables | |
int | max_pardepth |
Reasonable cut-off depth for parallelization. | |
Miscellaneous auxiliary functions and macros.
#define allocfield | ( | sz | ) | _h2_allocfield(sz,__FILE__,__LINE__) |
#define allocmatrix | ( | rows, | |
cols | |||
) | _h2_allocmatrix(rows,cols,__FILE__,__LINE__) |
Allocate heap storage for a matrix.
Remark: For algebraic operations, consider new_amatrix.
rows | Number of rows. |
cols | Number of columns. |
rows*cols
variables of type field. #define allocmem | ( | sz | ) | _h2_allocmem(sz,__FILE__,__LINE__) |
Allocate heap storage.
sz | Number of bytes. |
sz
bytes. #define allocreal | ( | sz | ) | _h2_allocreal(sz,__FILE__,__LINE__) |
#define allocuint | ( | sz | ) | _h2_allocuint(sz,__FILE__,__LINE__) |
#define h2_free | ( | p | ) | free(p) |
Wrapper for either aligned or not align memory free function.
p | Pointer to an object that should be freed. |
#define h2_malloc | ( | sz | ) | malloc(sz) |
Wrapper for either aligned or not align memory allocation function.
sz | Number of bytes that should be allocated. |
#define heapsort | ( | n, | |
leq, | |||
swap, | |||
data | |||
) | _h2_heapsort(n,leq,swap,data) |
Heapsort algorithm.
This function permutes the given array to put it into increasing order.
n | Number of array elements. |
leq | Return true if the array element corresponding to the first index is less than or equal to the one corresponding to the second index. |
swap | Swap the array elements corresponding to the first and second index. |
data | Array to be sorted. |
#define NC_DEFLATE_LEVEL 9 |
Deflation level for NetCDF compression.
The value 9 corresponds to maximal compression.
#define ROUNDUP | ( | x, | |
N | |||
) | ((((x) + (N) - 1) / (N)) * (N)) |
Round up some value x to the nearest multiple of N.
x | Value that should be round up to nearest multiple of N. |
N | Muliples of N are used for rounding up x. |
void del_stopwatch | ( | pstopwatch | sw | ) |
Delete a stopwatch object.
sw | Stopwatch object to be deleted. |
void freemem | ( | void * | ptr | ) |
Release allocated storage.
ptr | Pointer to allocated storage. |
size_t get_current_memory | ( | ) |
Current amount of allocated memory (bytes)
void init_h2lib | ( | int * | argc, |
char *** | argv | ||
) |
Initialize the library.
This function prepares the run-time environment for calls to library functions, e.g., by initializing external libraries like GTK+ or FreeGLUT that are required by some functions.
argc | Number of command line parameters. |
argv | Values of command line parameters. |
cairo_t* new_cairopdf | ( | const char * | filename, |
double | width, | ||
double | height | ||
) |
Create a PDF canvas for Cairo drawing.
cairo_t
object should be destroyed using cairo_destroy
in order to ensure that pending drawing operations are completed and the PDF file is closed.filename | Name of the PDF file. |
width | Width of the canvas in pixels. |
height | Height of the canvas in pixels. |
cairo_t
object that can be used in drawing operations. Create a PNG canvas for Cairo drawing.
The resulting cairo_t
object can be used in write_cairopng to write the image to a PNG file.
cairo_t
object should be destroyed using cairo_destroy
once it is no longer needed.width | Width of the canvas in pixels. |
height | Height of the canvas in pixels. |
cairo_t
object that can be used in drawing operations. pstopwatch new_stopwatch | ( | ) |
void start_stopwatch | ( | pstopwatch | sw | ) |
Start a stopwatch.
This function stores the current time in a private variable that can be used subsequently to measure elapsed time.
sw | Stopwatch to be started. |
real stop_stopwatch | ( | pstopwatch | sw | ) |
Stop a stopwatch.
This function stores the current time in a private variable that can be used subsequently to determine the time that has passed between calls to start_stopwatch and stop_stopwatch.
sw | Stopwatch (start_stopwatch has to have been called for this object at least once). |
void uninit_h2lib | ( | ) |
Uninitialize the library.
This function cleans up the run-time environment once the library is no longer neede.
bool write_cairopng | ( | cairo_t * | cr, |
const char * | filename | ||
) |
Write Cairo image to PNG file.
cr | Cairo context created by new_cairopng. |
filename | Name of the PNG file. |