Bachelor's degree final project  v1.0
Faculty of Mathematics, University of Barcelona
src/include/utils.h
Go to the documentation of this file.
00001 
00009 #ifndef UTILS_H
00010 #define UTILS_H
00011 
00016 // #define NDEBUG       /* Assert case */
00017 
00021 //#define DEBUG_PRINT     /* Prints case */
00022 
00026 //#define DEBUG_QR_PRINT     /* Prints case */
00027 
00028 // #include <errno.h>
00029 #include <stdlib.h>
00030 // #include <stdio.h>
00031 // #include <string.h>
00032 // #include <math.h>
00033 #include <ctype.h>
00034 #include <assert.h>
00035 
00036 #include "load.h"
00037 #include "save.h"
00038 
00039 #ifdef _OPENMP
00040   #include <omp.h>
00041 #endif
00042 
00043 #if __STDC_VERSION__ >= 199901L
00044 /* "inline" is a keyword */
00045 #else
00046 #define inline static
00047 #endif
00048 
00049 /* Actually M_PI seems to be more widely used so we deprecate PI */
00050 #ifndef PI
00051 #define PI    3.1415926535897932384
00052 #endif
00053 
00054 #ifndef M_PI
00055 #define M_PI    3.1415926535897932384
00056 #endif
00057 
00063 #ifdef _OPENMP
00064 #define _OPENMP_DIMENSION 1e2
00065 #endif
00066 
00067 /* Various utility macros */
00073 #ifndef MAX
00074 #define MAX(a, b) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
00075 #endif
00076 
00082 #ifndef MIN
00083 #define MIN(a, b) ( ( ( a ) > ( b ) ) ? ( b ) : ( a ) )
00084 #endif
00085 
00091 #ifndef ROUND
00092 #define ROUND( a ) ( ( a ) < 0. ? ( ( a ) - .5 ) : ( ( a ) + .5 ) )
00093 #endif
00094 
00100 #ifndef ABS
00101 #define ABS( a ) ( ( a ) < 0. ? -( a ) : ( a ) )
00102 #endif
00103 
00109 #ifndef SIGN
00110 #define SIGN( a ) ( ( a ) < 0. ? -1 : 1 )
00111 #endif
00112 
00118 #define SWAP( a, b ) typeof(a) _SWAPPING_VAR; _SWAPPING_VAR = a; a = b; b = _SWAPPING_VAR
00119 
00125 #define free_mem( a ) \
00126 if ( a != NULL ) { free( (void *) a ); a = NULL; }
00127 
00128 #ifndef NULL
00129 #define NULL (void *) 0
00130 #endif
00131 
00132 /* Function prototypes */
00133 double euclidian_norm(size_t n, double * const x);
00134 double inner_product(size_t n, double * const x);
00135 
00136 void copy_vector(size_t n, double * const x, double * const y);
00137 void copy_matrix(size_t m, size_t n, double ** const A, double ** const B);
00138 
00139 void print_matrix(size_t m, size_t n, double ** const A, char * const name);
00140 void print_vector(size_t idx, size_t n, double * const v, char * const name);
00141 
00142 double * malloc_vector(size_t n);
00143 void free_vector(double *p);
00144 double ** malloc_matrix(size_t m, size_t n);
00145 void free_matrix(size_t m, double **p);
00146 
00147 int qrsis(int n, int m, double ** a, double * b, double tol); //TODO
00148 
00149 #ifdef MEMORY_INFO
00150 void add_bytes(size_t b);
00151 void print(void);
00152 void free_bytes(size_t b);
00153 #endif
00154 
00155 #ifdef MEMORY_INFO
00156 
00160 struct memory {
00161   size_t used; 
00162   size_t free; 
00163 };
00164 
00165 struct memory m;
00166 #endif
00167 #endif