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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1565 - (hide annotations)
Thu May 22 10:19:47 2008 UTC (11 years, 3 months ago) by gross
Original Path: trunk/paso/src/Common.h
File MIME type: text/plain
File size: 5449 byte(s)
some small fixes for openmp
1 ksteube 1312
2 jgs 150 /* $Id$ */
3    
4 ksteube 1312 /*******************************************************
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 dhawcroft 631
16 jgs 150 #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 woo409 779 #if ( defined __INTEL_COMPILER )
32 woo409 757 #include <mathimf.h>
33     #else
34     #include <math.h>
35     #endif
36 jgs 150
37 gross 1565 #if (defined __OPENMP)
38     #include <omp.h>
39     #endif
40    
41 jgs 150 #include <float.h>
42     #include <stdio.h>
43     #include <limits.h>
44     #include <stdlib.h>
45     #include <string.h>
46    
47     #define LenString_MAX FILENAME_MAX*2
48     #define LenErrorMsg_MAX LenString_MAX
49    
50     /* on some arcitectures it could be a good idea to use long rather than int */
51     /* this has not really been tested */
52    
53     typedef int dim_t;
54     typedef int index_t;
55     typedef int bool_t;
56     typedef int type_t;
57     typedef int err_t;
58    
59     #define INDEX_T_MAX INT_MAX
60     #define EPSILON DBL_EPSILON
61 gross 1370 #define LARGE_POSITIVE_FLOAT DBL_MAX
62 jgs 150
63     /**************************************************************/
64    
65     /* some useful functions: */
66    
67     #define FALSE 0
68     #define TRUE 1
69     #define UNKNOWN -1
70     #define DBLE(_x_) (double)(_x_)
71     #define INDEX1(_X1_) (_X1_)
72     #define INDEX2(_X1_,_X2_,_N1_) ((_X1_)+(_N1_)*(_X2_))
73     #define INDEX3(_X1_,_X2_,_X3_,_N1_,_N2_) ((_X1_)+(_N1_)*INDEX2(_X2_,_X3_,_N2_))
74     #define INDEX4(_X1_,_X2_,_X3_,_X4_,_N1_,_N2_,_N3_) ((_X1_)+(_N1_)*INDEX3(_X2_,_X3_,_X4_,_N2_,_N3_))
75     #define INDEX5(_X1_,_X2_,_X3_,_X4_,_X5_,_N1_,_N2_,_N3_,_N4_) ((_X1_)+(_N1_)*INDEX4(_X2_,_X3_,_X4_,_X5_,_N2_,_N3_,_N4_))
76     #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_))
77    
78     #define MAX(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg1_) : (_arg2_))
79 ksteube 1312 #define MAX3(_arg1_,_arg2_,_arg3_) MAX(_arg1_,MAX(_arg2_,_arg3_))
80 jgs 150 #define MIN(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg2_) : (_arg1_))
81 ksteube 1312 #define MIN3(_arg1_,_arg2_,_arg3_) MIN(_arg1_,MIN(_arg2_,_arg3_))
82 jgs 150 #define ABS(_arg_) MAX((_arg_),-(_arg_))
83 gross 1361 #define SIGN(_arg_) ((_arg_)>0 ? 1 : ((_arg_)<0 ? -1 : 0 ))
84 gross 1562 #define SWAP(_a0_,_a1_,_type_) { \
85     _type_ s; \
86     s=(_a0_); \
87     _a0_= (_a1_); \
88     _a1_=s; \
89     }
90 jgs 150 /**************************************************************/
91    
92     /* memory allocation: */
93    
94 ksteube 1312 /*
95     This is useful for seeing what memory is being allocated if you get an "Out of memory" error
96     #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_)))
97    
98     This is useful for seeing where memory is being freed if you get an "glibc detected...free" error
99     #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__); }
100     */
101    
102 jgs 150 #define TMPMEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
103     #define TMPMEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
104     #ifdef __ECC
105 ksteube 1322 /*#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__ );*/
106 jgs 150 #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
107     #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
108     #ifdef _OPENMP
109     #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) kmp_malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
110     #define THREAD_MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { kmp_free(_PTR_); (_PTR_) = NULL; }
111     #else
112     #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)
113     #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)
114     #endif
115 bcumming 730 #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_) ); }
116    
117 jgs 150 #else
118     #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
119     #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
120     #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)
121     #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)
122 bcumming 730 #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_) ); }
123 jgs 150 #endif
124    
125 gross 1407 #define TMPMEMALLOC_AND_PASOCHECK(_LENGTH_,_TYPE_) ( MEMALLOC(_LENGTH_,_TYPE_);
126    
127 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