00001
00014
00015
00016 #ifndef __UTILS_H_
00017 #define __UTILS_H_
00018
00019
00020 #include "cstd.h"
00021 #include "usempi.h"
00022
00023
00024
00025 #ifndef __cplusplus
00026 #if __STDC_VERSION__ >= 199901L
00027 #else
00028 #define inline
00029 #endif
00030 #endif
00031
00032 #if __STDC_VERSION__ >= 199901L
00033 #else
00034 #define restrict
00035 #endif
00036
00037
00038
00039
00040 #define DT_CSTRING 1
00041 #define DT_CHAR 2
00042 #define DT_SHORT 3
00043 #define DT_INT 4
00044 #define DT_LONG 5
00045 #define DT_FLOAT 6
00046 #define DT_DOUBLE 7
00047 #define DT_USHORT 9
00048 #define DT_UINT 10
00049 #define DT_ULONG 11
00050
00054
00055 #define DT_REAL DT_FLOAT
00056
00057
00058 #if DT_REAL == DT_DOUBLE
00059
00060 #define ireal double
00061 #define REAL_NAN 0.0
00062 #define REAL_ZERO 0.0
00063 #define REAL_ONE 1.0
00064 #define REAL_EPS DBL_EPSILON
00065 #define REAL_MIN DBL_MIN
00066 #define REAL_MAX DBL_MAX
00067 #define IWAVE_MPI_REAL MPI_DOUBLE
00068 #elif DT_REAL == DT_FLOAT
00069 #define ireal float
00070
00071 #define REAL_NAN 0.0f
00072 #define REAL_ZERO 0.0f
00073 #define REAL_ONE 1.0f
00074 #define REAL_EPS FLT_EPSILON
00075 #define REAL_MIN FLT_MIN
00076 #define REAL_MAX FLT_MAX
00077 #define IWAVE_MPI_REAL MPI_FLOAT
00078 #else
00079 #error REAL TYPE UNDEFINED.
00080 #endif
00081
00082
00086 #define RDOM_MAX_NARR 30
00087
00092 #define RARR_MAX_NDIM 3
00093
00094
00095
00096
00097
00098
00099
00100 #define IWAVE_NDIM 3
00101
00102 #if IWAVE_NDIM > RARR_MAX_NDIM
00103 #error NOT ENOUGH DIMENSIONS IN THE RARRAY: WAVE_NDIM > RARR_MAX_NDIM.
00104 #endif
00105
00106
00107
00108
00109
00110
00111 #if IWAVE_NDIM == 1
00112 #define IWAVE_3NDIM 3
00113 #elif IWAVE_NDIM == 2
00114 #define IWAVE_3NDIM 9
00115 #elif IWAVE_NDIM == 3
00116 #define IWAVE_3NDIM 27
00117 #else
00118 #error IWAVE_3NDIM UNDEFINED.
00119 #endif
00120
00121 #define IWAVE_NNEI (IWAVE_3NDIM - 1)
00122
00123
00124
00125
00126
00127
00128
00129
00130 #define IX 0
00131 #define IY 1
00132 #define IZ 2
00133
00134
00135
00136
00137
00138 #define RARR_DUMP_POINTERS 0
00139
00144 typedef int IPNT[RARR_MAX_NDIM];
00149 typedef ireal RPNT[RARR_MAX_NDIM];
00150
00151 #if RARR_MAX_NDIM == 1
00152 static const IPNT IPNT_0 = {0};
00153 static const IPNT IPNT_1 = {1};
00154 static const RPNT RPNT_0 = {REAL_ZERO};
00155 static const RPNT RPNT_1 = {REAL_ONE};
00156 #define RARR_MAX_3NDIM 3
00157 #elif RARR_MAX_NDIM == 2
00158 static const IPNT IPNT_0 = {0, 0};
00159 static const IPNT IPNT_1 = {1, 1};
00160 static const RPNT RPNT_0 = {REAL_ZERO, REAL_ZERO};
00161 static const RPNT RPNT_1 = {REAL_ONE, REAL_ONE};
00162 #define RARR_MAX_3NDIM 9
00163 #elif RARR_MAX_NDIM == 3
00164 static const IPNT IPNT_0 = {0, 0, 0};
00165 static const IPNT IPNT_1 = {1, 1, 1};
00166 static const RPNT RPNT_0 = {REAL_ZERO, REAL_ZERO, REAL_ZERO};
00167 static const RPNT RPNT_1 = {REAL_ONE, REAL_ONE, REAL_ONE};
00168 #define RARR_MAX_3NDIM 27
00169 #else
00170 #error IPNT/RPNT CONSTANTS UNDEFINED.
00171 #endif
00172
00173
00174
00176 int* IASN(IPNT l, const IPNT r);
00178 ireal* RASN(RPNT l, const RPNT r);
00179
00180
00181 #define _IPNT IPNT
00182 #define _RPNT RPNT
00183
00184
00185
00186
00187
00188 #define CHECK_BOUNDS
00189
00190
00198 typedef struct s_SIZEDSTRING
00199 {
00200 long n;
00201 char *s;
00202 } SIZEDSTRING;
00203
00204
00205
00206
00207
00208 #define PS_SEP '='
00209 #define PS_QUO '"'
00210
00211 void* usermalloc_(size_t size);
00220 void userfree_(void *ptr);
00221
00222
00223
00224
00225
00226 #define iwave_min(a, b) ((a) < (b) ? (a) : (b))
00227 #define iwave_max(a, b) ((a) > (b) ? (a) : (b))
00228 #define iwave_abs(a) ((a) < REAL_ZERO ? (-a) : (a))
00229
00230
00235 #define E_SUCCESS 0
00237 #define E_INTERNAL 1000
00238 #define E_OTHER 2000
00239 #define E_ALLOC 1
00240 #define E_BADINPUT 2
00241 #define E_OUTOFBOUNDS 3
00242 #define E_BADINDEX 4
00243 #define E_BADARRINDEX 5
00244 #define E_BADDIMINDEX 6
00245 #define E_FILE 7
00246 #define E_FILEOPEN 8
00247 #define E_MPI 9
00248 #define E_DOMAINDECOMP 10
00249 #define E_PARSE 11
00250 #define E_PARSENONAME 12
00251 #define E_PARSENOVALUE 13
00252 #define E_PARSECONVERT 14
00253 #define E_ALREADYALLOC 15
00254 #define E_RANGE -2
00255 #define E_OVERFLOW -3
00256 #define E_UNDERFLOW -4
00257 #define E_NOTIMESTEP -100
00258 #define E_NOTINGRID -200
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 int gen_3n1(int ndim, int *n);
00277 int gen_i2pnt(int ndim, int i, IPNT p);
00278 int gen_pnt2i(int ndim, const IPNT p, int *i);
00279
00280
00281 void storeRank(int rk);
00282 int retrieveRank();
00283
00284 void storeSize(int sz);
00285 int retrieveSize();
00286
00287 void storeComm(MPI_Comm cm);
00288 MPI_Comm retrieveComm();
00289
00290 void storeOutstream(FILE *stream);
00291 FILE* retrieveOutstream();
00292
00293
00294
00295
00296 void storeGlobalRank(int rk);
00297 int retrieveGlobalRank();
00298
00299 void storeGlobalSize(int sz);
00300 int retrieveGlobalSize();
00301
00302 void storeGlobalComm(MPI_Comm cm);
00303 MPI_Comm retrieveGlobalComm();
00304
00305 void storeThreadSupp(int ts);
00306 int retrieveThreadSupp();
00307
00308
00309
00310
00311 void storeGroupID(int);
00312 int retrieveGroupID();
00313
00314 void storeNumGroups(int);
00315 int retrieveNumGroups();
00316
00317
00318
00319
00320 void storeRemComm(MPI_Comm cm);
00321 MPI_Comm retrieveRemComm();
00322
00323
00324
00325
00326
00327 #define SEAMX_BIG_ENDIAN 0
00328 #define SEAMX_LITTLE_ENDIAN 1
00329
00330 int getMachineEndianness();
00331
00332
00333
00334
00335
00336 void swapBytes(unsigned char *arr, int arrsize, int atomsize);
00337
00338
00339 #endif