/[escript]/trunk/esysUtils/src/maths.h
ViewVC logotype

Contents of /trunk/esysUtils/src/maths.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1361 - (show annotations)
Fri Dec 14 09:26:51 2007 UTC (11 years, 9 months ago) by gross
Original Path: trunk/paso/src/Common.h
File MIME type: text/plain
File size: 5036 byte(s)
first steps towards a flux controlled transport solver.
1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #ifndef INC_PASO_COMMON
17 #define INC_PASO_COMMON
18
19 /**************************************************************/
20
21 /* Finley finite element solver: common include file */
22
23 /**************************************************************/
24
25 /* Copyrights by ACcESS Australia, 2003 */
26 /* Version: $Id$ */
27
28 /**************************************************************/
29
30 /* some system values */
31 #if ( defined __INTEL_COMPILER )
32 #include <mathimf.h>
33 #else
34 #include <math.h>
35 #endif
36
37 #include <float.h>
38 #include <stdio.h>
39 #include <limits.h>
40 #include <stdlib.h>
41 #include <string.h>
42
43 #define LenString_MAX FILENAME_MAX*2
44 #define LenErrorMsg_MAX LenString_MAX
45
46 /* on some arcitectures it could be a good idea to use long rather than int */
47 /* this has not really been tested */
48
49 typedef int dim_t;
50 typedef int index_t;
51 typedef int bool_t;
52 typedef int type_t;
53 typedef int err_t;
54
55 #define INDEX_T_MAX INT_MAX
56 #define EPSILON DBL_EPSILON
57
58 /**************************************************************/
59
60 /* some useful functions: */
61
62 #define FALSE 0
63 #define TRUE 1
64 #define UNKNOWN -1
65 #define DBLE(_x_) (double)(_x_)
66 #define INDEX1(_X1_) (_X1_)
67 #define INDEX2(_X1_,_X2_,_N1_) ((_X1_)+(_N1_)*(_X2_))
68 #define INDEX3(_X1_,_X2_,_X3_,_N1_,_N2_) ((_X1_)+(_N1_)*INDEX2(_X2_,_X3_,_N2_))
69 #define INDEX4(_X1_,_X2_,_X3_,_X4_,_N1_,_N2_,_N3_) ((_X1_)+(_N1_)*INDEX3(_X2_,_X3_,_X4_,_N2_,_N3_))
70 #define INDEX5(_X1_,_X2_,_X3_,_X4_,_X5_,_N1_,_N2_,_N3_,_N4_) ((_X1_)+(_N1_)*INDEX4(_X2_,_X3_,_X4_,_X5_,_N2_,_N3_,_N4_))
71 #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_))
72
73 #define MAX(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg1_) : (_arg2_))
74 #define MAX3(_arg1_,_arg2_,_arg3_) MAX(_arg1_,MAX(_arg2_,_arg3_))
75 #define MIN(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg2_) : (_arg1_))
76 #define MIN3(_arg1_,_arg2_,_arg3_) MIN(_arg1_,MIN(_arg2_,_arg3_))
77 #define ABS(_arg_) MAX((_arg_),-(_arg_))
78 #define SIGN(_arg_) ((_arg_)>0 ? 1 : ((_arg_)<0 ? -1 : 0 ))
79 /**************************************************************/
80
81 /* memory allocation: */
82
83 /*
84 This is useful for seeing what memory is being allocated if you get an "Out of memory" error
85 #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_)))
86
87 This is useful for seeing where memory is being freed if you get an "glibc detected...free" error
88 #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__); }
89 */
90
91 #define TMPMEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
92 #define TMPMEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
93 #ifdef __ECC
94 /*#define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_)); if( !(_LENGTH_) ) printf( "Trying malloc(0) at %s %d\n", __FILE__, __LINE__ ); //else printf( "malloc(%d) at %s %d\n", _LENGTH_, __FILE__, __LINE__ );*/
95 #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
96 #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
97 #ifdef _OPENMP
98 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) kmp_malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
99 #define THREAD_MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { kmp_free(_PTR_); (_PTR_) = NULL; }
100 #else
101 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)
102 #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)
103 #endif
104 #define MEMREALLOC(_POINTER_,_LENGTH_,_TYPE_) if( (_POINTER_)!=NULL ){ _POINTER_ = (_TYPE_*)realloc((void*)(_POINTER_),((size_t)(_LENGTH_))*sizeof(_TYPE_) ); }else{ _POINTER_ = (_TYPE_*)malloc( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); }
105
106 #else
107 #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
108 #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
109 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)
110 #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)
111 #define MEMREALLOC(_POINTER_,_LENGTH_,_TYPE_) if( (_POINTER_)!=NULL ){ _POINTER_ = (_TYPE_*)realloc((void*)(_POINTER_),((size_t)(_LENGTH_))*sizeof(_TYPE_) ); }else{ _POINTER_ = (_TYPE_*)malloc( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); }
112 #endif
113
114 #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