00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef INC_PASO_COMMON
00016 #define INC_PASO_COMMON
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #if defined(_WIN32) && defined(__INTEL_COMPILER)
00035 #include <mathimf.h>
00036 #else
00037 #include <math.h>
00038 #endif
00039
00040 #if (defined __OPENMP)
00041 #include <omp.h>
00042 #endif
00043
00044 #include <float.h>
00045 #include <stdio.h>
00046 #include <limits.h>
00047 #include <stdlib.h>
00048 #include <string.h>
00049
00050 #define LenString_MAX FILENAME_MAX*2
00051 #define LenErrorMsg_MAX LenString_MAX
00052
00053
00054
00055
00056 typedef int dim_t;
00057 typedef int index_t;
00058 typedef int bool_t;
00059 typedef int type_t;
00060 typedef int err_t;
00061
00062 #define INDEX_T_MAX INT_MAX
00063 #define INDEX_T_MIN -INT_MAX
00064 #define EPSILON DBL_EPSILON
00065 #define LARGE_POSITIVE_FLOAT DBL_MAX
00066 #define SMALL_NEGATIVE_FLOAT -DBL_MAX
00067
00068
00069
00070
00071
00072 #define FALSE 0
00073 #define TRUE 1
00074 #define UNKNOWN -1
00075 #define DBLE(_x_) (double)(_x_)
00076 #define INDEX1(_X1_) (_X1_)
00077 #define INDEX2(_X1_,_X2_,_N1_) ((_X1_)+(_N1_)*(_X2_))
00078 #define INDEX3(_X1_,_X2_,_X3_,_N1_,_N2_) ((_X1_)+(_N1_)*INDEX2(_X2_,_X3_,_N2_))
00079 #define INDEX4(_X1_,_X2_,_X3_,_X4_,_N1_,_N2_,_N3_) ((_X1_)+(_N1_)*INDEX3(_X2_,_X3_,_X4_,_N2_,_N3_))
00080 #define INDEX5(_X1_,_X2_,_X3_,_X4_,_X5_,_N1_,_N2_,_N3_,_N4_) ((_X1_)+(_N1_)*INDEX4(_X2_,_X3_,_X4_,_X5_,_N2_,_N3_,_N4_))
00081 #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_))
00082
00083 #define MAX(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg1_) : (_arg2_))
00084 #define MAX3(_arg1_,_arg2_,_arg3_) MAX(_arg1_,MAX(_arg2_,_arg3_))
00085 #define MIN(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg2_) : (_arg1_))
00086 #define MIN3(_arg1_,_arg2_,_arg3_) MIN(_arg1_,MIN(_arg2_,_arg3_))
00087 #define ABS(_arg_) MAX((_arg_),-(_arg_))
00088 #define SIGN(_arg_) ((_arg_)>0 ? 1 : ((_arg_)<0 ? -1 : 0 ))
00089 #define SWAP(_a0_,_a1_,_type_) { \
00090 _type_ s; \
00091 s=(_a0_); \
00092 _a0_= (_a1_); \
00093 _a1_=s; \
00094 }
00095 #define XNOR(_a0_,_a1_) ( ( (_a0_) && (_a1_) ) || ( !(_a0_) && !(_a1_) ) )
00096
00097
00098
00099
00100
00101
00102
00103 #if defined(_WIN32)
00104
00105 #include <python.h>
00106
00107 #define PASO_MALLOC PyMem_Malloc
00108 #define PASO_FREE PyMem_Free
00109 #define PASO_REALLOC PyMem_Realloc
00110
00111 #else
00112
00113 #include <stdlib.h>
00114
00115 #define PASO_MALLOC malloc
00116 #define PASO_FREE free
00117 #define PASO_REALLOC realloc
00118
00119 #endif
00120
00121 #ifndef __const
00122 # if (defined __STDC__ && __STDC__)
00123 # define __const const
00124 # else
00125 # define __const
00126 # endif
00127 #endif
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 #if defined(__ECC) && defined(_OPENMP)
00138 #include <omp.h>
00139 #define PASO_THREAD_MALLOC kmp_malloc
00140 #define PASO_THREAD_FREE kmp_free
00141 #else
00142 #define PASO_THREAD_MALLOC PASO_MALLOC
00143 #define PASO_THREAD_FREE PASO_FREE
00144 #endif
00145
00146
00147
00148
00149
00150 #define PASO_DLL_API
00151
00152 #ifdef _WIN32
00153 # ifndef PASO_STATIC_LIB
00154 # undef PASO_DLL_API
00155 # ifdef PASO_EXPORTS
00156 # define PASO_DLL_API __declspec(dllexport)
00157 # else
00158 # define PASO_DLL_API __declspec(dllimport)
00159 # endif
00160 # endif
00161 #endif
00162
00163
00164
00165
00166 #define MEMALLOC(_LENGTH_,_TYPE_) \
00167 (_TYPE_*) PASO_MALLOC(((size_t)(_LENGTH_))*sizeof(_TYPE_))
00168
00169
00170
00171
00172 #define MEMFREE(_PTR_) \
00173 do \
00174 { \
00175 if ((void *)(_PTR_) != NULL ) { PASO_FREE(_PTR_); (_PTR_) = NULL; } \
00176 } while(0)
00177
00178 #define MEMREALLOC(_RETP_,_POINTER_,_LENGTH_,_TYPE_) \
00179 do \
00180 { \
00181 if( (_POINTER_)!=NULL ) \
00182 { \
00183 _RETP_ = (_TYPE_*)PASO_REALLOC((void*)(_POINTER_), \
00184 ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
00185 } \
00186 else \
00187 { \
00188 _RETP_ = (_TYPE_*)PASO_MALLOC( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
00189 } \
00190 } while(0)
00191
00192 #define TMPMEMALLOC MEMALLOC
00193 #define TMPMEMFREE MEMFREE
00194 #define TMPMEMREALLOC MEMREALLOC
00195
00196 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) \
00197 (_TYPE_*) PASO_THREAD_MALLOC(((size_t)(_LENGTH_))*sizeof(_TYPE_))
00198
00199 #define THREAD_MEMFREE(_PTR_) \
00200 do \
00201 { \
00202 if ((void *)(_PTR_) != NULL ) { PASO_THREAD_FREE(_PTR_); (_PTR_) = NULL; } \
00203 } while(0)
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 #endif