00001
00002
00003
00004 #ifndef CPU_H_
00005 #define CPU_H_
00006
00009
00010 #ifdef _MSC_VER
00011 #pragma warning( disable : 4127 )
00012 #endif
00013
00015 #ifndef INT16_MAX
00016 #define INT16_MAX 32767
00017 #endif
00018 #ifndef INT16_MIN
00019 #define INT16_MIN (-INT16_MAX - 1)
00020 #endif
00021
00022 #if SHRT_MAX == INT16_MAX
00023 typedef short int int16;
00024 #elif INT_MAX == INT16_MAX
00025 typedef int int16;
00026 #else
00027 #error failed to define int16, please report this to gary@pa.uky.edu
00028 #endif
00029
00030 #ifndef UINT16_MAX
00031 #define UINT16_MAX 65535
00032 #endif
00033
00034 #if USHRT_MAX == UINT16_MAX
00035 typedef unsigned short int uint16;
00036 #elif UINT_MAX == UINT16_MAX
00037 typedef unsigned int uint16;
00038 #else
00039 #error failed to define uint16, please report this to gary@pa.uky.edu
00040 #endif
00041
00042 #ifndef INT32_MAX
00043 #define INT32_MAX 2147483647L
00044 #endif
00045 #ifndef INT32_MIN
00046 #define INT32_MIN (-INT32_MAX - 1)
00047 #endif
00048
00049 #if INT_MAX == INT32_MAX
00050 typedef int int32;
00051 #elif LONG_MAX == INT32_MAX
00052 typedef long int int32;
00053 #else
00054 #error failed to define int32, please report this to gary@pa.uky.edu
00055 #endif
00056
00057 #ifndef UINT32_MAX
00058 #define UINT32_MAX 4294967295UL
00059 #endif
00060
00061 #if UINT_MAX == UINT32_MAX
00062 typedef unsigned int uint32;
00063 #elif ULONG_MAX == UINT32_MAX
00064 typedef unsigned long int uint32;
00065 #else
00066 #error failed to define uint32, please report this to gary@pa.uky.edu
00067 #endif
00068
00069 #if LONG_MAX > INT32_MAX
00070
00071
00072
00073
00074
00075
00076
00077 #undef INT64_MAX
00078 #define INT64_MAX 9223372036854775807L
00079
00080 #undef INT64_MIN
00081 #define INT64_MIN (-INT64_MAX - 1L)
00082
00083 #if LONG_MAX == INT64_MAX
00084 #define HAVE_INT64 1
00085 typedef long int int64;
00086 #endif
00087
00088 #endif
00089
00090 #if ULONG_MAX > UINT32_MAX
00091
00092 #undef UINT64_MAX
00093 #define UINT64_MAX 18446744073709551615UL
00094
00095 #if ULONG_MAX == UINT64_MAX
00096 #define HAVE_UINT64 1
00097 typedef unsigned long int uint64;
00098 #endif
00099
00100 #endif
00101
00123 #ifdef cray
00124 #ifndef __cray
00125 #define __cray 1
00126 #endif
00127 #endif
00128
00130 #ifdef __x86_64
00131 #ifndef __amd64
00132 #define __amd64 1
00133 #endif
00134 #endif
00135
00136 #if defined(_ARCH_PPC) || defined(__POWERPC__) || defined(__powerpc__) || defined(PPC)
00137 #ifndef __ppc__
00138 #define __ppc__ 1
00139 #endif
00140 #endif
00141
00147 #if defined(unix) || defined(__unix__)
00148 #ifndef __unix
00149 #define __unix 1
00150 #endif
00151 #endif
00152
00154 #ifdef __ECC
00155 #ifndef __ICC
00156 #define __ICC __ECC
00157 #endif
00158 #endif
00159
00161 #undef __GNUC_EXCL__
00162 #if defined(__GNUC__) && ! ( defined(__ICC) || defined(__PATHSCALE__) || defined(__OPENCC__) || defined(__clang__) )
00163 #define __GNUC_EXCL__ 1
00164 #endif
00165
00166
00167 #ifndef HAVE_FUNC
00168 #undef __func__
00169 #define __func__ DEBUG_ENTRY.name()
00170 #endif
00171
00172
00175
00176 const realnum BIGFLOAT = numeric_limits<realnum>::max()/realnum(100.f);
00178 const realnum SMALLFLOAT = numeric_limits<realnum>::min()*realnum(100.f);
00179
00181 const double BIGDOUBLE = DBL_MAX/100.;
00182 const double SMALLDOUBLE = DBL_MIN*100.;
00183
00184 const int STDLEN = 32;
00185
00193 typedef enum { AS_DATA_ONLY_TRY, AS_DATA_LOCAL_TRY, AS_LOCAL_DATA_TRY, AS_LOCAL_ONLY_TRY,
00194 AS_DATA_ONLY, AS_DATA_OPTIONAL, AS_DATA_LOCAL, AS_LOCAL_DATA, AS_LOCAL_ONLY } access_scheme;
00195
00196
00197
00198 const ios_base::openmode mode_r = ios_base::in;
00199 const ios_base::openmode mode_w = ios_base::out | ios_base::trunc;
00200 const ios_base::openmode mode_a = ios_base::out | ios_base::app;
00201 const ios_base::openmode mode_rp = ios_base::in | ios_base::out;
00202 const ios_base::openmode mode_wp = ios_base::in | ios_base::out | ios_base::trunc;
00203 const ios_base::openmode mode_ap = ios_base::in | ios_base::out | ios_base::app;
00204
00205 const ios_base::openmode mode_rb = mode_r | ios_base::binary;
00206 const ios_base::openmode mode_wb = mode_w | ios_base::binary;
00207 const ios_base::openmode mode_ab = mode_a | ios_base::binary;
00208 const ios_base::openmode mode_rpb = mode_rp | ios_base::binary;
00209 const ios_base::openmode mode_wpb = mode_wp | ios_base::binary;
00210 const ios_base::openmode mode_apb = mode_ap | ios_base::binary;
00211
00212 FILE* open_data( const char* fname, const char* mode, access_scheme scheme=AS_DATA_ONLY );
00213 void open_data( fstream& stream, const char* fname, ios_base::openmode mode, access_scheme scheme=AS_DATA_ONLY );
00214
00215
00216
00217 EXTERN class t_cpu
00218 {
00221 union
00222 {
00223 char c[4];
00224 int32 i;
00225 } endian;
00226
00227 sys_float test_float;
00228 double test_double;
00229
00230 int32 Float_SNaN_Value;
00231 # ifdef HAVE_INT64
00232 int64 Double_SNaN_Value;
00233 # else
00234 int32 Double_SNaN_Value[2];
00235 # endif
00236
00237 # ifdef __unix
00238 struct sigaction p_action;
00239 struct sigaction p_default;
00240 # endif
00241
00243 bool p_lgAssertAbort;
00244
00246 long n_avail_CPU;
00248 bool p_lgMPI;
00253 bool p_lgMPISingleRankMode;
00255 long n_rank;
00257 char HostName[STDLEN];
00259 vector<string> chSearchPath;
00260 int nFileDone;
00261
00262 void enable_traps() const;
00263 static void signal_handler(int sig);
00264
00265 void getPathList( const char* fname, vector<string>& PathList, access_scheme scheme ) const;
00266 public:
00267 t_cpu();
00268
00269 bool big_endian() const { return ( endian.i == 0x12345678 ); }
00270 bool little_endian() const { return ( endian.i == 0x78563412 ); }
00271
00272 sys_float min_float() const { return test_float; }
00273 double min_double() const { return test_double; }
00274
00275 # ifdef __unix
00276 const struct sigaction* action() const { return &p_action; }
00277 const struct sigaction* deflt() const { return &p_default; }
00278 # endif
00279
00280 void setAssertAbort(bool val)
00281 {
00282 p_lgAssertAbort = val;
00283 #ifdef CATCH_SIGNAL
00284 # ifdef __unix
00285 if( val )
00286 sigaction( SIGABRT, deflt(), NULL );
00287 else
00288 sigaction( SIGABRT, action(), NULL );
00289 # endif
00290 # ifdef _MSC_VER
00291 if( val )
00292 signal( SIGABRT, SIG_DFL );
00293 else
00294 signal( SIGABRT, &signal_handler );
00295 # endif
00296 #endif
00297 }
00298 bool lgAssertAbort() const { return p_lgAssertAbort; }
00299
00300 void set_nCPU(long n) { n_avail_CPU = n; }
00301 long nCPU() const { return n_avail_CPU; }
00302 void set_MPI() { p_lgMPI = true; }
00303 bool lgMPI() const { return p_lgMPI; }
00304 void set_MPISingleRankMode( bool mode ) { p_lgMPISingleRankMode = mode; }
00305 bool lgMPISingleRankMode() const { return p_lgMPISingleRankMode; }
00306 void set_nRANK(long n) { n_rank = n; }
00307 long nRANK() const { return n_rank; }
00308 bool lgMaster() const { return ( n_rank == 0 ); }
00309 bool lgMPI_talk() const { return lgMaster() || lgMPISingleRankMode(); }
00310 const char *host_name() const { return HostName; }
00311 void printDataPath() const;
00312 bool firstOpen() const { return ( nFileDone == 0 ); }
00313
00314 friend FILE* open_data( const char* fname, const char* mode, access_scheme scheme );
00315 friend void open_data( fstream& stream, const char* fname, ios_base::openmode mode, access_scheme scheme );
00316
00317 friend void set_NaN(sys_float &x);
00318 friend void set_NaN(sys_float x[], long n);
00319 friend void set_NaN(double &x);
00320 friend void set_NaN(double x[], long n);
00321 } cpu;
00322
00324 void set_NaN(sys_float &x);
00325 void set_NaN(sys_float x[],
00326 long n);
00327 void set_NaN(double &x);
00328 void set_NaN(double x[],
00329 long n);
00330
00332 bool MyIsnan(const sys_float &x);
00333 bool MyIsnan(const double &x);
00334
00335
00336
00337 #ifdef _MSC_VER
00338 #define NORETURN __declspec(noreturn)
00339 #elif defined(__GNUC__) || ( defined(__INTEL_COMPILER) && defined(__linux) )
00340 #define NORETURN __attribute__ ((noreturn))
00341 #else
00342 #define NORETURN
00343 #endif
00344
00345 #ifdef __GNUC__
00346 #define UNUSED __attribute__ ((unused))
00347 #else
00348 #define UNUSED
00349 #endif
00350
00351
00352
00353
00354
00355 #define DO_EXPAND(VAL) VAL ## 1
00356 #define EXPAND(VAL) DO_EXPAND(VAL)
00357
00358
00359
00360
00361 #if defined __INTEL_COMPILER
00362 # define __COMP "icc"
00363 # define __COMP_VER __INTEL_COMPILER
00364
00365
00366
00367 #elif defined __PATHSCALE__
00368 # define __COMP "pathCC"
00369 # define __COMP_VER __PATHCC__ * 100 + __PATHCC_MINOR__ * 10 + __PATHCC_PATCHLEVEL__
00370
00371
00372
00373 #elif defined __OPENCC__
00374 # define __COMP "Open64"
00375 # if EXPAND(__OPENCC_PATCHLEVEL__) == 1
00376 # define __COMP_VER __OPENCC__ * 100 + __OPENCC_MINOR__ * 10
00377 # else
00378 # define __COMP_VER __OPENCC__ * 100 + __OPENCC_MINOR__ * 10 + __OPENCC_PATCHLEVEL__
00379 # endif
00380
00381
00382
00383 #elif defined __clang__
00384 # define __COMP "clang++"
00385 # define __COMP_VER __clang_major__ * 100 + __clang_minor__ * 10 + __clang_patchlevel__
00386
00387
00388 #elif defined __GNUC__
00389 # define __COMP "g++"
00390 # if defined(__GNUC_PATCHLEVEL__)
00391 # define __COMP_VER (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
00392 # else
00393 # define __COMP_VER (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
00394 # endif
00395
00396 #elif defined __PGI
00397 # define __COMP "Portland Group"
00398 # if defined(__PGIC__)
00399 # define __COMP_VER (__PGIC__ * 100 + __PGIC_MINOR__ * 10 + __PGIC_PATCHLEVEL__)
00400 # else
00401 # define __COMP_VER 0
00402 # endif
00403
00404
00405
00406 #elif defined(__sgi) && defined(_COMPILER_VERSION)
00407 # define __COMP "MIPSpro"
00408 # define __COMP_VER _COMPILER_VERSION
00409
00410
00411 #elif defined __HP_aCC
00412 # define __COMP "HP aCC"
00413 # define __COMP_VER __HP_aCC
00414
00415
00416 #elif defined __DECC
00417 # define __COMP "DEC CC"
00418 # define __COMP_VER __DECC_VER
00419
00420
00421 #elif defined _MSC_VER
00422 # define __COMP "vs"
00423 # define __COMP_VER _MSC_VER
00424
00425
00426 #elif defined __SUNPRO_CC
00427 # define __COMP "Solaris Studio"
00428 # define __COMP_VER __SUNPRO_CC
00429
00430
00431 #else
00432 # define __COMP "unknown"
00433 # define __COMP_VER 0
00434 #endif
00435
00436
00437
00438 #if defined __linux
00439 # if defined __i386
00440 # define __OS "Linux (IA32)"
00441 # elif defined __amd64
00442 # define __OS "Linux (AMD64)"
00443 # elif defined __ia64
00444 # define __OS "Linux (IA64)"
00445 # elif defined __ppc__
00446 # define __OS "Linux (PowerPC)"
00447 # else
00448 # define __OS "Linux (other)"
00449 # endif
00450
00451
00452 #elif defined macintosh
00453 # define __OS "Mac OS 9"
00454
00455
00456 #elif defined __MACOSX__
00457 # define __OS "Mac OS X"
00458
00459
00460 #elif defined __APPLE__
00461 # define __OS "Apple MacOS"
00462
00463
00464 #elif defined hpux
00465 # define __OS "HP-UX"
00466
00467
00468 #elif defined __sun
00469 # define __OS "Solaris"
00470
00471
00472 #elif defined _AIX
00473 # define __OS "AIX"
00474
00475
00476 #elif defined ultrix
00477 # define __OS "Ultrix"
00478
00479
00480 #elif defined __FreeBSD__
00481 # define __OS "FreeBSD"
00482
00483 #elif defined __NetBSD__
00484 # define __OS "NetBSD"
00485
00486 #elif defined __OpenBSD__
00487 # define __OS "OpenBSD"
00488
00489
00490
00491 #elif defined _WIN64
00492 # define __OS "Win64"
00493
00494
00495 #elif defined _WIN32
00496 # define __OS "Win32"
00497
00498
00499 #elif defined __CYGWIN__
00500 # define __OS "Cygwin"
00501
00502
00503 #elif defined __sgi
00504 # define __OS "IRIX"
00505
00506
00507 #else
00508 # define __OS "unknown"
00509 #endif
00510
00511
00512 #ifndef MM
00513
00514 #if defined(__GNUC_EXCL__) && ((__GNUC__ == 2 && __GNUC_MINOR__ == 96) || (__GNUC__ == 3 && __GNUC_MINOR__ == 4))
00515 #error "This g++ version cannot compile Cloudy and must not be used! Please update g++ to a functional version. See http://wiki.nublado.org/wiki/CompilingCloudy for more details."
00516 #endif
00517
00518 #if __INTEL_COMPILER >= 1200 && __INTEL_COMPILER < 1300
00519 #error "This icc version cannot compile Cloudy and must not be used! Please use a functional version of icc, or g++. See http://wiki.nublado.org/wiki/CompilingCloudy for more details."
00520 #endif
00521 #endif
00522
00523 #ifdef _MSC_VER
00524 #pragma warning( default : 4127 )
00525 #endif
00526
00527 #endif