/[escript]/trunk/paso/src/Common.h
ViewVC logotype

Contents of /trunk/paso/src/Common.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (show annotations)
Tue Nov 17 07:32:59 2009 UTC (10 years ago) by gross
File MIME type: text/plain
File size: 8222 byte(s)
Macro elements are implemented now. VTK writer for macro elements still needs testing.
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #ifndef INC_PASO_COMMON
16 #define INC_PASO_COMMON
17
18 /**************************************************************/
19
20 /* Finley finite element solver: common include file */
21
22 /**************************************************************/
23
24 /* Copyrights by ACcESS Australia, 2003 */
25 /* Version: $Id$ */
26
27 /**************************************************************/
28
29 /* some system values */
30 /* FIXME: This is not satisfactory. */
31 /* _ECC, __INTEL_COMPILER, and other */
32 /* intel compiler pre-defines need to be handled */
33 /* (__ICL, __ICC come to mind) */
34 #if defined(_WIN32) && defined(__INTEL_COMPILER)
35 #include <mathimf.h>
36 #else
37 #include <math.h>
38 #endif
39
40 #if (defined __OPENMP)
41 #include <omp.h>
42 #endif
43
44 #include <float.h>
45 #include <stdio.h>
46 #include <limits.h>
47 #include <stdlib.h>
48 #include <string.h>
49
50 #define LenString_MAX FILENAME_MAX*2
51 #define LenErrorMsg_MAX LenString_MAX
52
53 /* on some arcitectures it could be a good idea to use long rather than int */
54 /* this has not really been tested */
55
56 typedef int dim_t;
57 typedef int index_t;
58 typedef int bool_t;
59 typedef int type_t;
60 typedef int err_t;
61
62 #define INDEX_T_MAX INT_MAX
63 #define INDEX_T_MIN -INT_MAX
64 #define EPSILON DBL_EPSILON
65 #define LARGE_POSITIVE_FLOAT DBL_MAX
66 #define SMALL_NEGATIVE_FLOAT -DBL_MAX
67 #ifndef NAN
68 #define NAN (0.0/0.0)
69 #endif
70 #define IS_NAN(__VAL__) ( (__VAL__) == NAN ) /* this does not work */
71 /* #define IS_NAN(__VAL__) ( ! ( ( (__VAL__) >= 0. ) || ( (__VAL__) <= 0. ) ) ) this does not work */
72
73 /**************************************************************/
74
75 /* some useful functions: */
76
77 #define FALSE 0
78 #define TRUE 1
79 #define UNKNOWN -1
80 #define DBLE(_x_) (double)(_x_)
81 #define INDEX1(_X1_) (_X1_)
82 #define INDEX2(_X1_,_X2_,_N1_) ((_X1_)+(_N1_)*(_X2_))
83 #define INDEX3(_X1_,_X2_,_X3_,_N1_,_N2_) ((_X1_)+(_N1_)*INDEX2(_X2_,_X3_,_N2_))
84 #define INDEX4(_X1_,_X2_,_X3_,_X4_,_N1_,_N2_,_N3_) ((_X1_)+(_N1_)*INDEX3(_X2_,_X3_,_X4_,_N2_,_N3_))
85 #define INDEX5(_X1_,_X2_,_X3_,_X4_,_X5_,_N1_,_N2_,_N3_,_N4_) ((_X1_)+(_N1_)*INDEX4(_X2_,_X3_,_X4_,_X5_,_N2_,_N3_,_N4_))
86 #define INDEX6(_X1_,_X2_,_X3_,_X4_,_X5_,_X6_,_N1_,_N2_,_N3_,_N4_,_N5_) ((_X1_)+(_N1_)*INDEX5(_X2_,_X3_,_X4_,_X5_,_X6_,_N2_,_N3_,_N4_,_N5_))
87
88 #define MAX(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg1_) : (_arg2_))
89 #define MAX3(_arg1_,_arg2_,_arg3_) MAX(_arg1_,MAX(_arg2_,_arg3_))
90 #define MIN(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg2_) : (_arg1_))
91 #define MIN3(_arg1_,_arg2_,_arg3_) MIN(_arg1_,MIN(_arg2_,_arg3_))
92 #define ABS(_arg_) MAX((_arg_),-(_arg_))
93 #define SIGN(_arg_) ((_arg_)>0 ? 1 : ((_arg_)<0 ? -1 : 0 ))
94 #define SWAP(_a0_,_a1_,_type_) { \
95 _type_ s; \
96 s=(_a0_); \
97 _a0_= (_a1_); \
98 _a1_=s; \
99 }
100 #define XNOR(_a0_,_a1_) ( ( (_a0_) && (_a1_) ) || ( !(_a0_) && !(_a1_) ) )
101 /**************************************************************/
102 /* memory allocation: */
103 /* Wise to not use PASO_MALLOC/FREE/REALLOC and */
104 /* PASO_THREAD... directly. These are only for tailoring */
105 /* the main macros that follow */
106 /**************************************************************/
107
108 #if defined(_WIN32) /* Use python for memory management on windows. */
109
110 #include <python.h>
111
112 #define PASO_MALLOC PyMem_Malloc
113 #define PASO_FREE PyMem_Free
114 #define PASO_REALLOC PyMem_Realloc
115
116 #else
117
118 #include <stdlib.h>
119
120 #define PASO_MALLOC malloc
121 #define PASO_FREE free
122 #define PASO_REALLOC realloc
123
124 #endif
125
126 #ifndef __const
127 # if (defined __STDC__ && __STDC__)
128 # define __const const
129 # else
130 # define __const
131 # endif
132 #endif
133
134
135 /* FIXME: This is not satisfactory. */
136 /* _ECC, __INTEL_COMPILER, and other */
137 /* intel compiler pre-defines need to be handled */
138 /* (__ICL, __ICC come to mind) */
139 /* Also, _WIN32 may take this branch one day... */
140 /* SO KEEP ALL THREAD_MEMALLOC/FREEs CONFINED TO THE PASO LIBRARY. */
141
142 #if defined(__ECC) && defined(_OPENMP) /* ECC version of intel compiler with openmp. */
143 #include <omp.h>
144 #define PASO_THREAD_MALLOC kmp_malloc
145 #define PASO_THREAD_FREE kmp_free
146 #else
147 #define PASO_THREAD_MALLOC PASO_MALLOC
148 #define PASO_THREAD_FREE PASO_FREE
149 #endif
150
151
152 /* Prepare for the day that this becomes sharable. */
153 /* and we wish to do multi-file optimisations on windows */
154
155 #define PASO_DLL_API
156
157 #ifdef _WIN32
158 # ifndef PASO_STATIC_LIB
159 # undef PASO_DLL_API
160 # ifdef PASO_EXPORTS
161 # define PASO_DLL_API __declspec(dllexport)
162 # else
163 # define PASO_DLL_API __declspec(dllimport)
164 # endif
165 # endif
166 #endif
167
168
169 /******************The main macros ************************************/
170
171 #define MEMALLOC(_LENGTH_,_TYPE_) \
172 (_TYPE_*) PASO_MALLOC(((size_t)(_LENGTH_))*sizeof(_TYPE_))
173
174 /* do {} while(0) - an old trick for bracketing a macro that */
175 /* makes sure a semi-colon does no harm. */
176
177 #define MEMFREE(_PTR_) \
178 do \
179 { \
180 if ((void *)(_PTR_) != NULL ) { PASO_FREE(_PTR_); (_PTR_) = NULL; } \
181 } while(0)
182
183 #define MEMREALLOC(_RETP_,_POINTER_,_LENGTH_,_TYPE_) \
184 do \
185 { \
186 if( (_POINTER_)!=NULL ) \
187 { \
188 _RETP_ = (_TYPE_*)PASO_REALLOC((void*)(_POINTER_), \
189 ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
190 } \
191 else \
192 { \
193 _RETP_ = (_TYPE_*)PASO_MALLOC( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
194 } \
195 } while(0)
196
197 #define TMPMEMALLOC MEMALLOC
198 #define TMPMEMFREE MEMFREE
199 #define TMPMEMREALLOC MEMREALLOC
200
201 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) \
202 (_TYPE_*) PASO_THREAD_MALLOC/**/(((size_t)(_LENGTH_))*sizeof(_TYPE_))
203
204 #define THREAD_MEMFREE(_PTR_) \
205 do \
206 { \
207 if ((void *)(_PTR_) != NULL ) { PASO_THREAD_FREE(_PTR_); (_PTR_) = NULL; } \
208 } while(0)
209
210
211 /*
212 This was useful for seeing what memory is being allocated if you get an "Out of memory" error
213 if used again, bracket with do {} while(0)
214 #define TMPMEMALLOC(_LENGTH_,_TYPE_) (printf("TMPMEMALLOC at %s %d #bytes=%d*%d=%d\n", __FILE__, __LINE__, _LENGTH_, sizeof(_TYPE_), ((size_t)(_LENGTH_) * sizeof(_TYPE_))) , (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_)))
215
216 This was useful for seeing where memory is being freed if you get an "glibc detected...free" error
217 if used again, bracket with do {} while(0)
218 #define TMPMEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { printf("TMPMEMFREE AAA %s %d\n", __FILE__, __LINE__); free(_PTR_); (_PTR_) = NULL; printf("TMPMEMFREE BBB %s %d\n", __FILE__, __LINE__); }
219 */
220
221 #endif /* #ifndef INC_PASO_COMMON */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26