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 7
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 #define IARR_MAX_NDIM 7
00145
00146 #if RARR_MAX_NDIM > IARR_MAX_NDIM
00147 #error NOT ENOUGH DIMENSIONS IN THE IPNT: RARR_MAX_NDIM > IARR_MAX_NDIM.
00148 #endif
00149 typedef int IPNT[IARR_MAX_NDIM];
00154 typedef ireal RPNT[RARR_MAX_NDIM];
00155
00156 #if RARR_MAX_NDIM == 1
00157 static const IPNT IPNT_0 = {0};
00158 static const IPNT IPNT_1 = {1};
00159 static const RPNT RPNT_0 = {REAL_ZERO};
00160 static const RPNT RPNT_1 = {REAL_ONE};
00161 #define RARR_MAX_3NDIM 3
00162 #elif RARR_MAX_NDIM == 2
00163 static const IPNT IPNT_0 = {0, 0};
00164 static const IPNT IPNT_1 = {1, 1};
00165 static const RPNT RPNT_0 = {REAL_ZERO, REAL_ZERO};
00166 static const RPNT RPNT_1 = {REAL_ONE, REAL_ONE};
00167 #define RARR_MAX_3NDIM 9
00168 #elif RARR_MAX_NDIM == 3
00169 static const IPNT IPNT_0 = {0, 0, 0};
00170 static const IPNT IPNT_1 = {1, 1, 1};
00171 static const RPNT RPNT_0 = {REAL_ZERO, REAL_ZERO, REAL_ZERO};
00172 static const RPNT RPNT_1 = {REAL_ONE, REAL_ONE, REAL_ONE};
00173 #define RARR_MAX_3NDIM 27
00174 #elif RARR_MAX_NDIM == 4
00175 static const IPNT IPNT_0 = {0, 0, 0, 0};
00176 static const IPNT IPNT_1 = {1, 1, 1, 1};
00177 static const RPNT RPNT_0 = {REAL_ZERO, REAL_ZERO, REAL_ZERO, REAL_ZERO};
00178 static const RPNT RPNT_1 = {REAL_ONE, REAL_ONE, REAL_ONE, REAL_ONE};
00179 #define RARR_MAX_3NDIM 81
00180 #elif RARR_MAX_NDIM == 5
00181 static const IPNT IPNT_0 = {0, 0, 0, 0, 0};
00182 static const IPNT IPNT_1 = {1, 1, 1, 1, 1};
00183 static const RPNT RPNT_0 = {REAL_ZERO, REAL_ZERO, REAL_ZERO, REAL_ZERO, REAL_ZERO};
00184 static const RPNT RPNT_1 = {REAL_ONE, REAL_ONE, REAL_ONE, REAL_ONE, REAL_ONE};
00185 #define RARR_MAX_3NDIM 243
00186 #elif RARR_MAX_NDIM == 6
00187 static const IPNT IPNT_0 = {0, 0, 0, 0, 0, 0};
00188 static const IPNT IPNT_1 = {1, 1, 1, 1, 1, 1};
00189 static const RPNT RPNT_0 = {REAL_ZERO, REAL_ZERO, REAL_ZERO, REAL_ZERO, REAL_ZERO, REAL_ZERO};
00190 static const RPNT RPNT_1 = {REAL_ONE, REAL_ONE, REAL_ONE, REAL_ONE, REAL_ONE, REAL_ONE};
00191 #define RARR_MAX_3NDIM 729
00192 #elif RARR_MAX_NDIM == 7
00193 static const IPNT IPNT_0 = {0, 0, 0, 0, 0, 0, 0};
00194 static const IPNT IPNT_1 = {1, 1, 1, 1, 1, 1, 1};
00195 static const RPNT RPNT_0 = {REAL_ZERO, REAL_ZERO, REAL_ZERO, REAL_ZERO, REAL_ZERO, REAL_ZERO, REAL_ZERO};
00196 static const RPNT RPNT_1 = {REAL_ONE, REAL_ONE, REAL_ONE, REAL_ONE, REAL_ONE, REAL_ONE, REAL_ONE};
00197 #define RARR_MAX_3NDIM 2187
00198 #else
00199 #error IPNT/RPNT CONSTANTS UNDEFINED.
00200 #endif
00201
00202
00203
00205 int* IASN(IPNT l, const IPNT r);
00207 ireal* RASN(RPNT l, const RPNT r);
00208
00209
00210 #define _IPNT IPNT
00211 #define _RPNT RPNT
00212
00213
00214
00215
00216
00217 #define CHECK_BOUNDS
00218
00219
00227 typedef struct s_SIZEDSTRING
00228 {
00229 long n;
00230 char *s;
00231 } SIZEDSTRING;
00232
00233
00234
00235
00236
00237 #define PS_SEP '='
00238 #define PS_QUO '"'
00239
00240 void* usermalloc_(size_t size);
00249 void userfree_(void *ptr);
00250
00251
00252
00253
00254
00255 #define iwave_min(a, b) ((a) < (b) ? (a) : (b))
00256 #define iwave_max(a, b) ((a) > (b) ? (a) : (b))
00257 #define iwave_abs(a) ((a) < REAL_ZERO ? (-a) : (a))
00258
00259
00264 #define E_SUCCESS 0
00266 #define E_INTERNAL 1000
00267 #define E_OTHER 2000
00268 #define E_ALLOC 1
00269 #define E_BADINPUT 2
00270 #define E_OUTOFBOUNDS 3
00271 #define E_BADINDEX 4
00272 #define E_BADARRINDEX 5
00273 #define E_BADDIMINDEX 6
00274 #define E_FILE 7
00275 #define E_FILEOPEN 8
00276 #define E_MPI 9
00277 #define E_DOMAINDECOMP 10
00278 #define E_PARSE 11
00279 #define E_PARSENONAME 12
00280 #define E_PARSENOVALUE 13
00281 #define E_PARSECONVERT 14
00282 #define E_ALREADYALLOC 15
00283 #define E_RANGE -2
00284 #define E_OVERFLOW -3
00285 #define E_UNDERFLOW -4
00286 #define E_NOTIMESTEP -100
00287 #define E_NOTINGRID -200
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 int gen_3n1(int ndim, int *n);
00306 int gen_i2pnt(int ndim, int i, IPNT p);
00307 int gen_pnt2i(int ndim, const IPNT p, int *i);
00308
00309
00310 void storeRank(int rk);
00311 int retrieveRank();
00312
00313 void storeSize(int sz);
00314 int retrieveSize();
00315
00316 void storeComm(MPI_Comm cm);
00317 MPI_Comm retrieveComm();
00318
00319 void storeOutstream(FILE *stream);
00320 FILE* retrieveOutstream();
00321
00322
00323
00324
00325 void storeGlobalRank(int rk);
00326 int retrieveGlobalRank();
00327
00328 void storeGlobalSize(int sz);
00329 int retrieveGlobalSize();
00330
00331 void storeGlobalComm(MPI_Comm cm);
00332 MPI_Comm retrieveGlobalComm();
00333
00334 void storeThreadSupp(int ts);
00335 int retrieveThreadSupp();
00336
00337
00338
00339
00340 void storeGroupID(int);
00341 int retrieveGroupID();
00342
00343 void storeNumGroups(int);
00344 int retrieveNumGroups();
00345
00346
00347
00348
00349 void storeRemComm(MPI_Comm cm);
00350 MPI_Comm retrieveRemComm();
00351
00352
00353
00354
00355
00356 #define SEAMX_BIG_ENDIAN 0
00357 #define SEAMX_LITTLE_ENDIAN 1
00358
00359 int getMachineEndianness();
00360
00361
00362
00363
00364
00365 void swapBytes(unsigned char *arr, int arrsize, int atomsize);
00366
00367
00368
00369
00370
00371
00372
00373 int getBoundaryFlags(IPNT lbc, IPNT rbc, int dim);
00374
00375 #endif