H2Lib  3.0
Macros | Typedefs | Functions | Variables
basic

Miscellaneous auxiliary functions and macros. More...

Macros

#define M_PI   3.141592653589793238462643383
 Mathematical constant $\pi$.
 
#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 $a$ of a field element $x=a+ib$.
 
#define IMAG(x)   cimag(x)
 Get the imaginary part $b$ of a field element $x=a+ib$.
 
#define CONJ(x)   conj(x)
 Compute the complex conjugate $\bar x$ of a field element $x$.
 
#define ABSSQR(x)   _h2_abssqr(x)
 Compute the square of the absolute value $|x|^2$ of a field element $x$.
 
#define ABS(x)   REAL_SQRT(ABSSQR(x))
 Compute the absolute value $|x|$ of a field element $x$.
 
#define SIGN1(x)   _h2_sgn1(x)
 Compute the sign $\mathop{\rm sgn}(x)$ of a field element $x$ with the convention $\mathop{\rm sgn}(0)=1$.
 
#define FIELD_RAND()   _h2_fieldrand()
 Compute a (pseudo-)random field element.
 
#define REAL_ABS(x)   fabs(x)
 Compute the absolute value $|x|$ of a real number $x$.
 
#define REAL_SQR(x)   _h2_real_sqr(x)
 Compute the square $x^2$ of a real number $x$.
 
#define REAL_SIN(x)   sin(x)
 Compute the sine $\sin(x)$ of a real number $x$.
 
#define REAL_COS(x)   cos(x)
 Compute the cosine $\cos(x)$ of a real number $x$.
 
#define REAL_ASIN(x)   asin(x)
 Compute the arcsine $\asin(x)$ of a real number $x$.
 
#define REAL_ACOS(x)   acos(x)
 Compute the arccosine $\acos(x)$ of a real number $x$.
 
#define REAL_TAN(x)   tan(x)
 Compute the tangent $\tan(x)$ of a real number $x$.
 
#define REAL_SQRT(x)   sqrt(x)
 Compute the square root $\sqrt{x}$ of a non-negative real nunber $x$.
 
#define REAL_RSQRT(x)   _h2_rsqrt(x)
 Compute the reciprocal square root $1.0/\sqrt{x}$ of a non-negative real nunber $x$.
 
#define REAL_POW(x, y)   pow(x, y)
 Compute the $y$-th power $x^y$ of a real number $x$.
 
#define REAL_LOG(x)   log(x)
 Compute the natural logarithm $\ln(x)$ of a positive real number $x$.
 
#define REAL_EXP(x)   exp(x)
 Compute the exponetial function $\exp(x)$ of a real number $x$.
 
#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. $ \bar x_1 y_1 + \bar x_2 y_2 $.
 
#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. $ \bar x_1 y_1 + \bar x_2 y_2 + \bar x_3 y_3 $.
 
#define NORMSQR2(x, y)   (ABSSQR(x) + ABSSQR(y))
 Compute squared 2-norm of a vector of dimension 2, i.e. $ \lvert x \rvert^2 + \lvert y \rvert^2 $.
 
#define NORMSQR3(x, y, z)   (ABSSQR(x) + ABSSQR(y) + ABSSQR(z))
 Compute squared 2-norm of a vector of dimension 3, i.e. $ \lvert x \rvert^2 + \lvert y \rvert^2 + \lvert z \rvert^2 $.
 
#define NORM2(x, y)   REAL_SQRT(ABSSQR(x) + ABSSQR(y))
 Compute 2-norm of a vector of dimension 2, i.e. $ \sqrt{\lvert x \rvert^2 + \lvert y \rvert^2} $.
 
#define NORM3(x, y, z)   REAL_SQRT(ABSSQR(x) + ABSSQR(y) + ABSSQR(z))
 Compute 2-norm of a vector of dimension 3, i.e. $ \sqrt{\lvert x \rvert^2 + \lvert y \rvert^2 + \lvert z \rvert^2} $.
 
#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. $ x_1 y_1 + x_2 y_2 $.
 
#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. $ x_1 y_1 + x_2 y_2 + x_3 y_3 $.
 
#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. $ x^2 + y^2 $.
 
#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. $ x^2 + y^2 +z^2 $.
 
#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. $ \sqrt{x^2 + y^2} $.
 
#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. $ \sqrt{x^2 + y^2 + z^2} $.
 
#define REAL_MAX(x, y)   _h2_realmax(x, y)
 Compute the maximum $\max\{x,y\}$ of two real numbers $x$ and $y$.
 
#define REAL_MAX3(x, y, z)   _h2_realmax3(x, y, z)
 Compute the maximum $\max\{x,y,z\}$ of three real numbers $x,y$ and $z$.
 
#define REAL_MIN(x, y)   _h2_realmin(x, y)
 Compute the minimum $\min\{x,y\}$ of two real numbers $x$ and $y$.
 
#define REAL_MIN3(x, y, z)   _h2_realmin3(x, y, z)
 Compute the minimum $\min\{x,y,z\}$ of three real numbers $x,y$ and $z$.
 
#define UINT_MAX(x, y)   _h2_uintmax(x, y)
 Compute the maximum $\max\{x,y\}$ of two unsigned integers $x$ and $y$.
 
#define UINT_MAX3(x, y, z)   _h2_uintmax3(x, y, z)
 Compute the maximum $\max\{x,y,z\}$ of three unsigned integers $x,y$ and $z$.
 
#define UINT_MIN(x, y)   _h2_uintmin(x, y)
 Compute the minimum $\min\{x,y,z\}$ of two unsigned integers $x,y$ and $z$.
 
#define UINT_MIN3(x, y, z)   _h2_uintmin3(x, y, z)
 Compute the minimum $\min\{x,y,z\}$ of three unsigned integers $x,y$ and $z$.
 
#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 stopwatchpstopwatch
 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.
 

Detailed Description

Miscellaneous auxiliary functions and macros.

Macro Definition Documentation

#define allocfield (   sz)    _h2_allocfield(sz,__FILE__,__LINE__)

Allocate heap storage of type field.

Parameters
szNumber of field variables.
Returns
Pointer to sz variables of type field.
#define allocmatrix (   rows,
  cols 
)    _h2_allocmatrix(rows,cols,__FILE__,__LINE__)

Allocate heap storage for a matrix.

Remark: For algebraic operations, consider new_amatrix.

Parameters
rowsNumber of rows.
colsNumber of columns.
Returns
Pointer to rows*cols variables of type field.
#define allocmem (   sz)    _h2_allocmem(sz,__FILE__,__LINE__)

Allocate heap storage.

Parameters
szNumber of bytes.
Returns
Pointer to sz bytes.
#define allocreal (   sz)    _h2_allocreal(sz,__FILE__,__LINE__)

Allocate heap storage of type real.

Parameters
szNumber of real variables
Returns
Pointer to sz variables of type real.
#define allocuint (   sz)    _h2_allocuint(sz,__FILE__,__LINE__)

Allocate heap storage of type uint.

Parameters
szNumber of uint variables.
Returns
Pointer to sz variables of type uint.
#define h2_free (   p)    free(p)

Wrapper for either aligned or not align memory free function.

Parameters
pPointer to an object that should be freed.
#define h2_malloc (   sz)    malloc(sz)

Wrapper for either aligned or not align memory allocation function.

Parameters
szNumber 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.

Parameters
nNumber of array elements.
leqReturn true if the array element corresponding to the first index is less than or equal to the one corresponding to the second index.
swapSwap the array elements corresponding to the first and second index.
dataArray to be sorted.
#define NC_DEFLATE_LEVEL   9

Deflation level for NetCDF compression.

The value 9 corresponds to maximal compression.

#define ROUNDUP (   x,
 
)    ((((x) + (N) - 1) / (N)) * (N))

Round up some value x to the nearest multiple of N.

Parameters
xValue that should be round up to nearest multiple of N.
NMuliples of N are used for rounding up x.
Returns
((x + N - 1) / N) * N

Function Documentation

void del_stopwatch ( pstopwatch  sw)

Delete a stopwatch object.

Parameters
swStopwatch object to be deleted.
void freemem ( void *  ptr)

Release allocated storage.

Parameters
ptrPointer to allocated storage.
size_t get_current_memory ( )

Current amount of allocated memory (bytes)

Returns
Current amount of currently allocated memory is returned.
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.

Parameters
argcNumber of command line parameters.
argvValues of command line parameters.
cairo_t* new_cairopdf ( const char *  filename,
double  width,
double  height 
)

Create a PDF canvas for Cairo drawing.

Remarks
The resulting 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.
Parameters
filenameName of the PDF file.
widthWidth of the canvas in pixels.
heightHeight of the canvas in pixels.
Returns
cairo_t object that can be used in drawing operations.
cairo_t* new_cairopng ( uint  width,
uint  height 
)

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.

Remarks
The cairo_t object should be destroyed using cairo_destroy once it is no longer needed.
Parameters
widthWidth of the canvas in pixels.
heightHeight of the canvas in pixels.
Returns
cairo_t object that can be used in drawing operations.
pstopwatch new_stopwatch ( )

Create a stopwatch object.

Returns
New stopwatch object.
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.

Parameters
swStopwatch 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.

Parameters
swStopwatch (start_stopwatch has to have been called for this object at least once).
Returns
Elapsed time in seconds since stopwatch was started.
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.

Parameters
crCairo context created by new_cairopng.
filenameName of the PNG file.
Returns
True if successful.