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

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

Parent Directory Parent Directory | Revision Log Revision Log


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