rambrain
common.h
Go to the documentation of this file.
1 /* rambrain - a dynamical physical memory extender
2  * Copyright (C) 2015 M. Imgrund, A. Arth
3  * mimgrund (at) mpifr-bonn.mpg.de
4  * arth (at) usm.uni-muenchen.de
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef COMMON_H
21 #define COMMON_H
22 
23 #include <malloc.h>
24 #include <inttypes.h>
25 
26 namespace rambrain
27 {
28 
29 typedef double myScalar;
30 
31 inline static double sqr ( double x )
32 {
33  return x * x;
34 }
35 #define NANCHECK(x) if(x!=x) errmsg("NaN! occured")
36 #define NANBOOL(x) x!=x?true:false
37 
38 #define errmsg(message) {fprintf(stderr,"\033[31mERROR:\033[0m\t%s\n\t\033[90m(from %s, %s(...) , line %d)\033[0m\n", message, __FILE__,__FUNCTION__,__LINE__);}
39 #define infomsg(message) {fprintf(stderr,"\033[32mINFO:\033[0m\t%s\n\t\033[90m(from %s, %s(...) , line %d)\033[0m\n", message, __FILE__,__FUNCTION__,__LINE__);}
40 #define warnmsg(message) {fprintf(stderr,"\033[33mWARN:\033[0m\t%s\n\t\033[90m(from %s, %s(...) , line %d)\033[0m\n", message, __FILE__,__FUNCTION__,__LINE__);}
41 
42 #define errmsgf(format,...) {char tmp[1024];snprintf(tmp,1024,format,__VA_ARGS__);errmsg(tmp);}
43 #define infomsgf(format,...) {char tmp[1024];snprintf(tmp,1024,format,__VA_ARGS__);infomsg(tmp);}
44 #define warnmsgf(format,...) {char tmp[1024];snprintf(tmp,1024,format,__VA_ARGS__);warnmsg(tmp);}
45 
46 //#define DBG_MUTICES
47 #ifdef DBG_MUTICES
48 #define rambrain_pthread_mutex_lock(x) infomsg("Lock of " #x " ") pthread_mutex_lock(x);
49 #define rambrain_pthread_mutex_unlock(x) infomsg("Unlock of " #x " ") pthread_mutex_unlock(x);
50 #else
51 #define rambrain_pthread_mutex_lock(x) pthread_mutex_lock(x)
52 #define rambrain_pthread_mutex_unlock(x) pthread_mutex_unlock(x)
53 #endif
54 #define VECTOR_FOREACH(vec,iter) for(int iter = 0; iter < vec.size(); ++iter)
55 
56 #ifdef __GNUC__
57 #define DEPRECATED __attribute__((deprecated))
58 #elif defined(_MSC_VER)
59 #define DEPRECATED __declspec(deprecated)
60 #else
61 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
62 #define DEPRECATED
63 #endif
64 
65 typedef uint64_t global_bytesize;
66 
67 const global_bytesize kib = 1024;
68 const global_bytesize mib = kib * kib;
69 const global_bytesize gig = mib * kib;
70 
71 }
72 
73 #endif
74 
uint64_t global_bytesize
Definition: common.h:65
const global_bytesize gig
Definition: common.h:69
const global_bytesize kib
Definition: common.h:67
double myScalar
Definition: common.h:29
const global_bytesize mib
Definition: common.h:68