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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/paso/src/Common.h revision 1361 by gross, Fri Dec 14 09:26:51 2007 UTC trunk/esysUtils/src/maths.h revision 3259 by jfenwick, Mon Oct 11 01:48:14 2010 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2010 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
   
 #ifndef INC_PASO_COMMON  
 #define INC_PASO_COMMON  
13    
 /**************************************************************/  
14    
15  /*    Finley finite element solver: common include file       */  #ifndef INC_ESYS_MATHS
16    #define INC_ESYS_MATHS
17    
18  /**************************************************************/  /**************************************************************/
19    
20  /*   Copyrights by ACcESS Australia, 2003 */  /*    Pull in a maths library and define ISNAN      */
 /*   Version: $Id$ */  
21    
 /**************************************************************/  
22    
23  /* some system values */  /* some system values */
24  #if ( defined __INTEL_COMPILER )  /* FIXME: This is not satisfactory.                                */
25    /* _ECC, __INTEL_COMPILER, and other                               */
26    /* intel compiler pre-defines need to be handled                   */
27    /* (__ICL, __ICC come to mind)                                     */
28    #if defined(_WIN32) && defined(__INTEL_COMPILER)
29  #include <mathimf.h>  #include <mathimf.h>
30  #else  #else
31  #include <math.h>  #include <math.h>
32  #endif  #endif
33    
34  #include <float.h>  /*#ifndef NAN
35  #include <stdio.h>     #define NAN (0.0/0.0)
36  #include <limits.h>  #endif
 #include <stdlib.h>  
 #include <string.h>  
   
 #define LenString_MAX FILENAME_MAX*2  
 #define LenErrorMsg_MAX LenString_MAX  
   
 /* on some arcitectures it could be a good idea to use long rather than int */  
 /* this has not really been tested */  
   
 typedef int dim_t;  
 typedef int index_t;  
 typedef int bool_t;  
 typedef int type_t;  
 typedef int err_t;  
   
 #define INDEX_T_MAX INT_MAX  
 #define EPSILON DBL_EPSILON  
   
 /**************************************************************/  
   
 /*   some useful functions: */  
   
 #define FALSE 0  
 #define TRUE 1  
 #define UNKNOWN -1  
 #define DBLE(_x_) (double)(_x_)  
 #define INDEX1(_X1_) (_X1_)  
 #define INDEX2(_X1_,_X2_,_N1_) ((_X1_)+(_N1_)*(_X2_))  
 #define INDEX3(_X1_,_X2_,_X3_,_N1_,_N2_) ((_X1_)+(_N1_)*INDEX2(_X2_,_X3_,_N2_))  
 #define INDEX4(_X1_,_X2_,_X3_,_X4_,_N1_,_N2_,_N3_) ((_X1_)+(_N1_)*INDEX3(_X2_,_X3_,_X4_,_N2_,_N3_))  
 #define INDEX5(_X1_,_X2_,_X3_,_X4_,_X5_,_N1_,_N2_,_N3_,_N4_) ((_X1_)+(_N1_)*INDEX4(_X2_,_X3_,_X4_,_X5_,_N2_,_N3_,_N4_))  
 #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_))  
   
 #define MAX(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ?  (_arg1_) : (_arg2_))  
 #define MAX3(_arg1_,_arg2_,_arg3_) MAX(_arg1_,MAX(_arg2_,_arg3_))  
 #define MIN(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ?  (_arg2_) : (_arg1_))  
 #define MIN3(_arg1_,_arg2_,_arg3_) MIN(_arg1_,MIN(_arg2_,_arg3_))  
 #define ABS(_arg_) MAX((_arg_),-(_arg_))  
 #define SIGN(_arg_) ((_arg_)>0 ?  1  : ((_arg_)<0 ? -1 : 0 ))  
 /**************************************************************/  
   
 /*    memory allocation:                                      */  
   
 /*  
     This is useful for seeing what memory is being allocated if you get an "Out of memory" error  
 #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_)))  
   
     This is useful for seeing where memory is being freed if you get an "glibc detected...free" error  
 #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__); }  
37  */  */
38    /*#define IS_NAN(__VAL__)  ( (__VAL__) == NAN )*/  /* this does not work */
39    /* #define IS_NAN(__VAL__)  ( ! ( ( (__VAL__) >= 0. ) ||  ( (__VAL__) <= 0. ) ) )  this does not work */
40    
41  #define TMPMEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))  #ifdef isnan
42  #define TMPMEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }    #define IS_NAN(__VAL__) (isnan(__VAL__))
43  #ifdef __ECC  #elif defined _isnan
44    /*#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__ );*/    #define IS_NAN(__VAL__) (_isnan(__VAL__))
   #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))  
   #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }  
   #ifdef _OPENMP  
       #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) kmp_malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))  
       #define THREAD_MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { kmp_free(_PTR_); (_PTR_) = NULL; }  
   #else  
      #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)  
      #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)  
   #endif  
   #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_) ); }  
   
45  #else  #else
46    #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))  /* If we do not have isnan then we can't reliably check for NaN - return false */
47    #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }    #define IS_NAN(__VAL__) (0)
   #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)  
   #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)  
   #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_) ); }  
48  #endif  #endif
49    
50  #endif /* #ifndef INC_PASO_COMMON */  
51    #define EPSILON DBL_EPSILON
52    #define LARGE_POSITIVE_FLOAT DBL_MAX
53    #define SMALL_NEGATIVE_FLOAT -DBL_MAX
54    
55    #endif

Legend:
Removed from v.1361  
changed lines
  Added in v.3259

  ViewVC Help
Powered by ViewVC 1.1.26