/[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

branches/domexper/paso/src/Common.h revision 3079 by jfenwick, Tue Aug 3 04:04:51 2010 UTC branches/domexper/esysUtils/src/maths.h revision 3227 by jfenwick, Thu Sep 30 06:07:08 2010 UTC
# Line 12  Line 12 
12  *******************************************************/  *******************************************************/
13    
14    
15  #ifndef INC_PASO_COMMON  #ifndef INC_ESYS_MATHS
16  #define INC_PASO_COMMON  #define INC_ESYS_MATHS
17    
18  /**************************************************************/  /**************************************************************/
19    
20  /*    Finley finite element solver: common include file       */  /*    Pull in a maths library and define ISNAN      */
21    
 /**************************************************************/  
   
 /*   Copyrights by ACcESS Australia, 2003 */  
 /*   Version: $Id$ */  
   
 /**************************************************************/  
22    
23  /* some system values */  /* some system values */
24  /* FIXME: This is not satisfactory.                                */  /* FIXME: This is not satisfactory.                                */
# Line 37  Line 31 
31  #include <math.h>  #include <math.h>
32  #endif  #endif
33    
 #if (defined __OPENMP)  
 #include <omp.h>  
 #endif  
   
 #include <float.h>  
 #include <stdio.h>  
 #include <limits.h>  
 #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 INDEX_T_MIN -INT_MAX  
 #define EPSILON DBL_EPSILON  
 #define LARGE_POSITIVE_FLOAT DBL_MAX  
 #define SMALL_NEGATIVE_FLOAT -DBL_MAX  
34  /*#ifndef NAN  /*#ifndef NAN
35     #define NAN (0.0/0.0)     #define NAN (0.0/0.0)
36  #endif  #endif
# Line 80  typedef int err_t; Line 47  typedef int err_t;
47    #define IS_NAN(__VAL__) (0)    #define IS_NAN(__VAL__) (0)
48  #endif  #endif
49    
50  /**************************************************************/  #define INDEX_T_MAX INT_MAX
51    #define INDEX_T_MIN -INT_MAX
52  /*   some useful functions: */  #define EPSILON DBL_EPSILON
53    #define LARGE_POSITIVE_FLOAT DBL_MAX
54  #define FALSE 0  #define SMALL_NEGATIVE_FLOAT -DBL_MAX
 #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 ))  
 #define SWAP(_a0_,_a1_,_type_) { \  
                                 _type_ s; \  
                                 s=(_a0_); \  
                                 _a0_= (_a1_); \  
                                 _a1_=s; \  
                                }  
 #define XNOR(_a0_,_a1_) ( ( (_a0_) && (_a1_) ) || ( !(_a0_) && !(_a1_) ) )  
 /**************************************************************/  
 /*    memory allocation:                                      */  
 /*    Wise to not use PASO_MALLOC/FREE/REALLOC and            */  
 /*    PASO_THREAD... directly. These are only for tailoring   */  
 /*    the main macros that follow                             */  
 /**************************************************************/  
   
 #if defined(_WIN32) /* Use python for memory management on windows. */  
   
   #include <python.h>  
   
   #define PASO_MALLOC PyMem_Malloc  
   #define PASO_FREE PyMem_Free  
   #define PASO_REALLOC PyMem_Realloc  
   
 #else  
   
   #include <stdlib.h>  
   
   #define PASO_MALLOC malloc  
   #define PASO_FREE free  
   #define PASO_REALLOC realloc  
   
 #endif  
   
 #ifndef __const  
 # if (defined __STDC__ && __STDC__)  
 #  define __const   const  
 # else  
 #  define __const  
 # endif  
 #endif  
   
   
 /* FIXME: This is not satisfactory.                                */  
 /* _ECC, __INTEL_COMPILER, and other                               */  
 /* intel compiler pre-defines need to be handled                   */  
 /* (__ICL, __ICC come to mind)                                     */  
 /* Also, _WIN32 may take this branch one day...                    */  
 /* SO KEEP ALL THREAD_MEMALLOC/FREEs CONFINED TO THE PASO LIBRARY. */  
   
 #if defined(__ECC) && defined(_OPENMP) /* ECC version of intel compiler with openmp. */  
   #include <omp.h>  
   #define PASO_THREAD_MALLOC kmp_malloc  
   #define PASO_THREAD_FREE kmp_free  
 #else  
   #define PASO_THREAD_MALLOC PASO_MALLOC  
   #define PASO_THREAD_FREE PASO_FREE  
 #endif  
   
   
 /* Prepare for the day that this becomes sharable. */  
 /* and we wish to do multi-file optimisations on windows */  
   
 #define PASO_DLL_API  
   
 #ifdef _WIN32  
 #   ifndef PASO_STATIC_LIB  
 #      undef PASO_DLL_API  
 #      ifdef PASO_EXPORTS  
 #         define PASO_DLL_API __declspec(dllexport)  
 #      else  
 #         define PASO_DLL_API __declspec(dllimport)  
 #      endif  
 #   endif  
 #endif  
   
   
 /******************The main macros ************************************/  
   
 #define MEMALLOC(_LENGTH_,_TYPE_)                                     \  
   (_TYPE_*) PASO_MALLOC(((size_t)(_LENGTH_))*sizeof(_TYPE_))  
   
 /* do {} while(0) -  an old trick for bracketing a macro that */  
 /* makes sure a semi-colon does no harm.                      */  
   
 #define MEMFREE(_PTR_)                                                  \  
 do                                                                      \  
 {                                                                       \  
   if ((void *)(_PTR_) != NULL ) { PASO_FREE(_PTR_); (_PTR_) = NULL; }   \  
 } while(0)  
   
 #define MEMREALLOC(_RETP_,_POINTER_,_LENGTH_,_TYPE_)                    \  
 do                                                                        \  
 {                                                                         \  
    if( (_POINTER_)!=NULL )                                                \  
    {                                                                      \  
       _RETP_ = (_TYPE_*)PASO_REALLOC((void*)(_POINTER_),               \  
                                    ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \  
    }                                                                      \  
    else                                                                   \  
    {                                                                      \  
       _RETP_ = (_TYPE_*)PASO_MALLOC( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \  
    }                                                                      \  
 } while(0)  
   
 #define TMPMEMALLOC MEMALLOC  
 #define TMPMEMFREE MEMFREE  
 #define TMPMEMREALLOC MEMREALLOC  
   
 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_)                          \  
    (_TYPE_*) PASO_THREAD_MALLOC/**/(((size_t)(_LENGTH_))*sizeof(_TYPE_))  
   
 #define THREAD_MEMFREE(_PTR_)                                                \  
 do                                                                           \  
 {                                                                            \  
   if ((void *)(_PTR_) != NULL ) { PASO_THREAD_FREE(_PTR_); (_PTR_) = NULL; } \  
 } while(0)  
   
   
 /*  
     This was useful for seeing what memory is being allocated if you get an "Out of memory" error  
         if used again, bracket with do {} while(0)  
 #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 was useful for seeing where memory is being freed if you get an "glibc detected...free" error  
         if used again, bracket with do {} while(0)  
 #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__); }  
 */  
55    
56  #endif /* #ifndef INC_PASO_COMMON */  #endif

Legend:
Removed from v.3079  
changed lines
  Added in v.3227

  ViewVC Help
Powered by ViewVC 1.1.26