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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (hide annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 8413 byte(s)
Don't panic.
Updating copyright stamps

1 ksteube 1312
2     /*******************************************************
3 ksteube 1811 *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1811 * 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 dhawcroft 631
14 ksteube 1811
15 jgs 150 #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 phornby 1628 /* 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 phornby 2019 #if defined(_WIN32) && defined(__INTEL_COMPILER)
35 woo409 757 #include <mathimf.h>
36     #else
37     #include <math.h>
38     #endif
39 jgs 150
40 gross 1565 #if (defined __OPENMP)
41     #include <omp.h>
42     #endif
43    
44 jgs 150 #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 gross 1716 #define INDEX_T_MIN -INT_MAX
64 jgs 150 #define EPSILON DBL_EPSILON
65 gross 1370 #define LARGE_POSITIVE_FLOAT DBL_MAX
66 gross 1804 #define SMALL_NEGATIVE_FLOAT -DBL_MAX
67 jfenwick 2879 /*#ifndef NAN
68 gross 2748 #define NAN (0.0/0.0)
69     #endif
70 jfenwick 2879 */
71     /*#define IS_NAN(__VAL__) ( (__VAL__) == NAN )*/ /* this does not work */
72 gross 2748 /* #define IS_NAN(__VAL__) ( ! ( ( (__VAL__) >= 0. ) || ( (__VAL__) <= 0. ) ) ) this does not work */
73 jgs 150
74 jfenwick 2879 #ifdef isnan
75     #define IS_NAN(__VAL__) (isnan(__VAL__))
76     #else
77     /* If we do not have isnan then we can't reliably check for NaN - return false */
78     #define IS_NAN(__VAL__) (0)
79     #endif
80    
81 jgs 150 /**************************************************************/
82    
83     /* some useful functions: */
84    
85     #define FALSE 0
86     #define TRUE 1
87     #define UNKNOWN -1
88     #define DBLE(_x_) (double)(_x_)
89     #define INDEX1(_X1_) (_X1_)
90     #define INDEX2(_X1_,_X2_,_N1_) ((_X1_)+(_N1_)*(_X2_))
91     #define INDEX3(_X1_,_X2_,_X3_,_N1_,_N2_) ((_X1_)+(_N1_)*INDEX2(_X2_,_X3_,_N2_))
92     #define INDEX4(_X1_,_X2_,_X3_,_X4_,_N1_,_N2_,_N3_) ((_X1_)+(_N1_)*INDEX3(_X2_,_X3_,_X4_,_N2_,_N3_))
93     #define INDEX5(_X1_,_X2_,_X3_,_X4_,_X5_,_N1_,_N2_,_N3_,_N4_) ((_X1_)+(_N1_)*INDEX4(_X2_,_X3_,_X4_,_X5_,_N2_,_N3_,_N4_))
94     #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_))
95    
96     #define MAX(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg1_) : (_arg2_))
97 ksteube 1312 #define MAX3(_arg1_,_arg2_,_arg3_) MAX(_arg1_,MAX(_arg2_,_arg3_))
98 jgs 150 #define MIN(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg2_) : (_arg1_))
99 ksteube 1312 #define MIN3(_arg1_,_arg2_,_arg3_) MIN(_arg1_,MIN(_arg2_,_arg3_))
100 jgs 150 #define ABS(_arg_) MAX((_arg_),-(_arg_))
101 gross 1361 #define SIGN(_arg_) ((_arg_)>0 ? 1 : ((_arg_)<0 ? -1 : 0 ))
102 gross 1562 #define SWAP(_a0_,_a1_,_type_) { \
103     _type_ s; \
104     s=(_a0_); \
105     _a0_= (_a1_); \
106     _a1_=s; \
107     }
108 gross 2554 #define XNOR(_a0_,_a1_) ( ( (_a0_) && (_a1_) ) || ( !(_a0_) && !(_a1_) ) )
109 jgs 150 /**************************************************************/
110     /* memory allocation: */
111 phornby 1628 /* Wise to not use PASO_MALLOC/FREE/REALLOC and */
112     /* PASO_THREAD... directly. These are only for tailoring */
113     /* the main macros that follow */
114     /**************************************************************/
115 jgs 150
116 phornby 1628 #if defined(_WIN32) /* Use python for memory management on windows. */
117 ksteube 1312
118 phornby 1628 #include <python.h>
119 ksteube 1312
120 phornby 1628 #define PASO_MALLOC PyMem_Malloc
121     #define PASO_FREE PyMem_Free
122     #define PASO_REALLOC PyMem_Realloc
123 bcumming 730
124 jgs 150 #else
125 phornby 1628
126 ksteube 1662 #include <stdlib.h>
127 phornby 1628
128     #define PASO_MALLOC malloc
129     #define PASO_FREE free
130     #define PASO_REALLOC realloc
131    
132 jgs 150 #endif
133    
134 phornby 2028 #ifndef __const
135     # if (defined __STDC__ && __STDC__)
136     # define __const const
137     # else
138     # define __const
139     # endif
140     #endif
141 gross 1407
142 phornby 2028
143 phornby 1628 /* FIXME: This is not satisfactory. */
144     /* _ECC, __INTEL_COMPILER, and other */
145     /* intel compiler pre-defines need to be handled */
146     /* (__ICL, __ICC come to mind) */
147     /* Also, _WIN32 may take this branch one day... */
148     /* SO KEEP ALL THREAD_MEMALLOC/FREEs CONFINED TO THE PASO LIBRARY. */
149    
150     #if defined(__ECC) && defined(_OPENMP) /* ECC version of intel compiler with openmp. */
151     #include <omp.h>
152     #define PASO_THREAD_MALLOC kmp_malloc
153     #define PASO_THREAD_FREE kmp_free
154     #else
155     #define PASO_THREAD_MALLOC PASO_MALLOC
156     #define PASO_THREAD_FREE PASO_FREE
157     #endif
158    
159 phornby 2056
160     /* Prepare for the day that this becomes sharable. */
161     /* and we wish to do multi-file optimisations on windows */
162    
163     #define PASO_DLL_API
164    
165     #ifdef _WIN32
166     # ifndef PASO_STATIC_LIB
167     # undef PASO_DLL_API
168     # ifdef PASO_EXPORTS
169     # define PASO_DLL_API __declspec(dllexport)
170     # else
171     # define PASO_DLL_API __declspec(dllimport)
172     # endif
173     # endif
174     #endif
175    
176    
177 phornby 1628 /******************The main macros ************************************/
178    
179     #define MEMALLOC(_LENGTH_,_TYPE_) \
180     (_TYPE_*) PASO_MALLOC(((size_t)(_LENGTH_))*sizeof(_TYPE_))
181    
182     /* do {} while(0) - an old trick for bracketing a macro that */
183     /* makes sure a semi-colon does no harm. */
184    
185     #define MEMFREE(_PTR_) \
186     do \
187     { \
188     if ((void *)(_PTR_) != NULL ) { PASO_FREE(_PTR_); (_PTR_) = NULL; } \
189     } while(0)
190    
191 phornby 1875 #define MEMREALLOC(_RETP_,_POINTER_,_LENGTH_,_TYPE_) \
192 phornby 1628 do \
193     { \
194     if( (_POINTER_)!=NULL ) \
195     { \
196 phornby 1875 _RETP_ = (_TYPE_*)PASO_REALLOC((void*)(_POINTER_), \
197 phornby 1628 ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
198     } \
199     else \
200     { \
201 phornby 1875 _RETP_ = (_TYPE_*)PASO_MALLOC( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
202 phornby 1628 } \
203     } while(0)
204    
205     #define TMPMEMALLOC MEMALLOC
206     #define TMPMEMFREE MEMFREE
207 phornby 1875 #define TMPMEMREALLOC MEMREALLOC
208 phornby 1628
209     #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) \
210     (_TYPE_*) PASO_THREAD_MALLOC/**/(((size_t)(_LENGTH_))*sizeof(_TYPE_))
211    
212     #define THREAD_MEMFREE(_PTR_) \
213     do \
214     { \
215     if ((void *)(_PTR_) != NULL ) { PASO_THREAD_FREE(_PTR_); (_PTR_) = NULL; } \
216     } while(0)
217    
218    
219     /*
220     This was useful for seeing what memory is being allocated if you get an "Out of memory" error
221     if used again, bracket with do {} while(0)
222     #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_)))
223    
224     This was useful for seeing where memory is being freed if you get an "glibc detected...free" error
225     if used again, bracket with do {} while(0)
226     #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__); }
227     */
228    
229 jgs 150 #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