7 #if defined(__ia64) && defined(__INTEL_COMPILER)
8 extern "C" unsigned long fpgetmask();
9 extern "C" void fpsetmask(
unsigned long);
12 #if defined(__sun) || defined(__sgi)
14 #if defined(HAVE_SUNMATH) || defined(FLUSH_DENORM_TO_ZERO)
19 #if defined(__alpha) && defined(__linux__) && defined(__GNUC__)
24 #if defined(__unix) || defined(__APPLE__)
28 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
29 #include <sys/types.h>
30 #include <sys/sysctl.h>
125 if(
sizeof(
double) == 8 )
143 if(
sizeof(
double) == 8 )
196 # if defined(_SC_NPROCESSORS_ONLN)
197 #if defined(__APPLE__)
198 size_t sizeOfInt =
sizeof(int);
200 sysctlbyname(
"hw.physicalcpu", &physicalCores, &sizeOfInt, NULL, 0);
205 # elif defined(_SC_NPROC_ONLN)
207 # elif defined(_SC_CRAY_NCPU)
209 # elif defined(_WIN32)
210 str = getenv(
"NUMBER_OF_PROCESSORS" );
221 # elif defined(HW_AVAILCPU)
222 #if defined(__APPLE__)
223 size_t sizeOfInt =
sizeof(int);
225 sysctlbyname(
"hw.physicalcpu", &physicalCores, &sizeOfInt, NULL, 0);
231 mib[1] = HW_AVAILCPU;
256 str = getenv(
"COMPUTERNAME" );
258 str = getenv(
"HOSTNAME" );
268 const char *path = getenv(
"CLOUDY_DATA_PATH" );
271 string separator(
";" );
274 string separator(
":" );
280 string chSearchPathRaw = ( path != NULL ) ?
string( path ) : string( CLOUDY_DATA_PATH );
282 chSearchPathRaw =
"." + separator + chSearchPathRaw + separator;
286 string chCloudyRoot = string( CLOUDY_ROOT );
289 while(
FindAndReplace( chSearchPathRaw, separator +
"+" + separator,
299 char* ptr = realpath( p->c_str(), NULL );
308 char chEnd = *p->rbegin();
339 # if defined(_MSC_VER)
340 volatile unsigned int NewMask;
345 NewMask = _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_INVALID;
348 _controlfp( NewMask , _MCW_EM );
354 # elif defined(__GNUC__) && ( defined(__i386) || defined(__amd64) ) && !defined(__clang__)
355 volatile unsigned int Old_Mask, New_Mask;
356 # if defined(__SSE__) || defined(__SSE2__)
357 volatile unsigned int SSE_Mask;
360 # define _FPU_MASK_IM 0x01
361 # define _FPU_MASK_DM 0x02
362 # define _FPU_MASK_ZM 0x04
363 # define _FPU_MASK_OM 0x08
364 # define _FPU_MASK_UM 0x10
365 # define _FPU_MASK_PM 0x20
375 volatile unsigned int UnMask = ~((
unsigned int)( _FPU_MASK_ZM | _FPU_MASK_IM | _FPU_MASK_OM ));
377 __asm__
volatile(
"fnstcw %0" :
"=m" (*&Old_Mask));
379 New_Mask = Old_Mask & UnMask;
381 __asm__
volatile(
"fldcw %0" : :
"m" (*&New_Mask));
383 # if defined(__SSE__) || defined(__SSE2__)
396 __asm__
volatile(
"ldmxcsr %0" : :
"m" (*&SSE_Mask) );
401 # elif defined(__ia64)
403 # define FPSR_TRAP_VD (1 << 0)
404 # define FPSR_TRAP_DD (1 << 1)
405 # define FPSR_TRAP_ZD (1 << 2)
406 # define FPSR_TRAP_OD (1 << 3)
407 # define FPSR_TRAP_UD (1 << 4)
408 # define FPSR_TRAP_ID (1 << 5)
410 # define FPSR_SF0_FTZ (1 << 6)
412 # if defined(__GNUC_EXCL__)
414 # define _IA64_REG_AR_FPSR 40
416 # define ia64_getreg( regnum ) __asm__ volatile( "mov %0=ar%1" : "=r" (fpsr) : "i"(regnum) )
417 # define ia64_setreg( regnum, val ) __asm__ volatile( "mov ar%0=%1" :: "i" (regnum), "r"(val): "memory" )
418 # define ia64_serialize __asm__ volatile( "srlz.i" );
420 volatile unsigned long fpsr, flags = FPSR_TRAP_VD | FPSR_TRAP_ZD | FPSR_TRAP_OD;
422 ia64_getreg( _IA64_REG_AR_FPSR );
424 # if defined(FLUSH_DENORM_TO_ZERO)
425 fpsr |= FPSR_SF0_FTZ;
427 ia64_setreg( _IA64_REG_AR_FPSR, fpsr );
431 # elif defined(__INTEL_COMPILER)
433 unsigned long fpsr = fpgetmask();
434 fpsr |= FPSR_TRAP_VD | FPSR_TRAP_ZD | FPSR_TRAP_OD;
439 # elif defined(__sun) || defined(__sgi)
444 # if defined(HAVE_SUNMATH) || defined(FLUSH_DENORM_TO_ZERO)
481 nonstandard_arithmetic();
486 mask = mask | FP_X_INV | FP_X_OFL | FP_X_DZ;
489 # elif defined(__alpha) && defined(__linux__) && defined(__GNUC__)
494 # ifdef FE_NONIEEE_ENV
498 fesetenv(FE_NONIEEE_ENV);
512 sigemptyset( &p_action.sa_mask );
513 p_action.sa_flags = SA_NODEFER;
515 p_default.sa_handler = SIG_DFL;
516 sigemptyset( &p_default.sa_mask );
517 p_default.sa_flags = SA_NODEFER;
519 for(
int sig=1; sig <= 31; sig++ )
522 if( sigaction( sig, NULL, NULL ) == 0 )
524 if( sig != SIGSTOP && sig != SIGCONT )
525 sigaction( sig, action(), NULL );
564 vector<string>::size_type begin, end;
597 string FileName( fname );
600 for( vector<string>::size_type
i=begin;
i < end; ++
i )
605 PathList.push_back( FileName );
621 vector<string> PathList;
624 vector<string>::const_iterator ptr;
625 for( ptr=PathList.begin(); ptr != PathList.end() && !io.is_open(); ++ptr )
626 io.open( ptr->c_str(),
mode_r );
634 while( getline( io, line ) )
639 if( line.find(
'/' ) != string::npos )
641 if( line.find(
'\\' ) != string::npos )
648 istringstream iss( line );
649 iss >> md5sum >> path;
660 fprintf(
ioQQQ,
"\nI could not open the data file %s\n\n", fname );
662 fprintf(
ioQQQ,
"\nPROBLEM DISASTER I could not open the data file %s\n\n", fname );
667 fprintf(
ioQQQ,
"Although there may be other reasons you have received this error,\n");
668 fprintf(
ioQQQ,
"the most likely are that the path has not been properly set or\n");
669 fprintf(
ioQQQ,
"that the path points to an old version of the data. It should\n");
670 fprintf(
ioQQQ,
"point to the data directory you downloaded from the web site.\n\n");
671 fprintf(
ioQQQ,
"Please use \"make\" to compile the code. This will automatically\n");
672 fprintf(
ioQQQ,
"set the path correctly. Alternatively you can set the environment\n");
673 fprintf(
ioQQQ,
"variable CLOUDY_DATA_PATH to point to the data directory using\n");
674 fprintf(
ioQQQ,
"the shell command \nexport CLOUDY_DATA_PATH=\"/path/to/data\"\n");
684 for( vector<string>::const_iterator ptr=PathList.begin(); ptr != PathList.end(); ++ptr )
689 fprintf(
ioQQQ,
"\nAlthough there may be other reasons you have received this error,\n");
690 fprintf(
ioQQQ,
"the most likely are that you mistyped the file name, or that you\n");
691 fprintf(
ioQQQ,
"are running Cloudy in the wrong directory. If you are running a\n");
692 fprintf(
ioQQQ,
"COMPILE command, this needs to be done in the data directory.\n\n");
693 fprintf(
ioQQQ,
"It is is also possible that the path has not been properly set. It\n");
694 fprintf(
ioQQQ,
"should point to the data directory you downloaded from the web site.\n");
695 fprintf(
ioQQQ,
"Please use \"make\" to compile the code. This will automatically\n");
696 fprintf(
ioQQQ,
"set the path correctly. Alternatively you can set the environment\n");
697 fprintf(
ioQQQ,
"variable CLOUDY_DATA_PATH to point to the data directory using\n");
698 fprintf(
ioQQQ,
"the shell command \nexport CLOUDY_DATA_PATH=\"/path/to/data\"\n");
712 ASSERT( PathList.size() == 1 );
714 fprintf(
ioQQQ,
" open_data writing %s\n", PathList[0].c_str() );
718 vector<string>::const_iterator ptr;
719 vector<string> PathSuccess;
720 for( ptr=PathList.begin(); ptr != PathList.end(); ++ptr )
722 FILE* handle =
sys_fopen( ptr->c_str(),
"r" );
725 fprintf(
ioQQQ,
" open_data trying to read %s found %c", ptr->c_str(),
TorF(handle != NULL) );
733 if( find( PathSuccess.begin(), PathSuccess.end(), *ptr ) == PathSuccess.end() )
734 PathSuccess.push_back( *ptr );
741 fprintf(
ioQQQ,
"CAUTION: multiple matches for file %s found:\n", fname );
742 for(
size_t i=0; i < PathSuccess.size(); ++i )
748 return ( PathSuccess.size() > 0 ) ? PathSuccess[0] :
"";
758 bool lgRead = ( m ==
"r" || m ==
"rb" );
765 vector<string> PathList;
771 handle =
sys_fopen( path.c_str(), mode );
773 if( handle == NULL && lgAbort )
787 bool lgRead = ( (mode&ios_base::out) == 0 );
794 vector<string> PathList;
797 ASSERT( !stream.is_open() );
800 stream.open( path.c_str(), mode );
802 if( !stream.is_open() &&
lgAbort )
821 vector<string> PathList;
828 err =
MPI_File_open( MPI_COMM_WORLD, const_cast<char*>(path.c_str()), mode, MPI_INFO_NULL, &fh );
845 map<string,string>::const_iterator ptr =
cpu.
i().
md5sum_expct.find( fname );
849 if( md5sum != ptr->second )
851 fprintf(
ioQQQ,
"Warning: using non-standard data in %s: ", fname );
852 fprintf(
ioQQQ,
"checksum %s != %s (expected)\n", md5sum.c_str(), ptr->second.c_str() );
877 int32 *y =
reinterpret_cast<int32*
>(x);
878 for( i=0; i < n; i++ )
883 for( i=0; i < n; i++ )
890 if(
sizeof(
double) == 8 )
895 int32 *y =
reinterpret_cast<int32*
>(&x);
910 if(
sizeof(
double) == 8 )
913 int64 *y =
reinterpret_cast<int64*
>(x);
914 for( i=0; i < n; i++ )
917 int32 *y =
reinterpret_cast<int32*
>(x);
918 for( i=0; i < n; i++ )
927 for( i=0; i < n; i++ )
935 if(
sizeof(
sys_float) == 4 && FLT_MAX_EXP-FLT_MIN_EXP+3 == 256 )
937 const int32 *p =
reinterpret_cast<const int32*
>(&x);
938 int32 r = *p & 0x7f800000; r ^= 0x7f800000;
939 int32 s = *p & 0x007fffff;
940 return ( r == 0 && s != 0 );
950 if(
sizeof(
double) == 8 && DBL_MAX_EXP-DBL_MIN_EXP+3 == 2048 )
953 const int64 *p =
reinterpret_cast<const int64*
>(&x);
954 int64 r = *p & INT64_LIT(0x7ff0000000000000); r ^= INT64_LIT(0x7ff0000000000000);
955 int64 s = *p & INT64_LIT(0x000fffffffffffff);
956 return ( r == 0 && s != 0 );
958 const int32 *p =
reinterpret_cast<const int32*
>(&x);
961 int32 r = p[1] & 0x7ff00000; r ^= 0x7ff00000;
962 int32 s = p[1] & 0x000fffff; s |= p[0];
963 return ( r == 0 && s != 0 );
967 int32 r = p[0] & 0x7ff00000; r ^= 0x7ff00000;
968 int32 s = p[0] & 0x000fffff; s |= p[1];
969 return ( r == 0 && s != 0 );
map< string, string > md5sum_expct
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
static void signal_handler(int sig)
bool p_lgMPISingleRankMode
NORETURN void TotalInsanity(void)
void set_NaN(sys_float &x)
FILE * sys_fopen(const char *path, const char *mode)
int32 Double_SNaN_Value[2]
void getPathList(const char *fname, vector< string > &PathList, access_scheme scheme, bool lgRead) const
bool MyIsnan(const sys_float &x)
string MD5datafile(const char *fnam, access_scheme scheme)
void getMD5sums(const char *fname)
bool little_endian() const
static t_version & Inst()
#define MPI_File_open(V, W, X, Y, Z)
const ios_base::openmode mode_r
void printDataPath() const
vector< string > p_exit_status
STATIC string check_mult_path(const char *fname, const vector< string > &PathList, access_scheme scheme, bool lgRead)
#define DEBUG_ENTRY(funcname)
void set_signal_handlers()
int fprintf(const Output &stream, const char *format,...)
void Split(const string &str, const string &sep, vector< string > &lst, split_mode mode)
void enable_traps() const
bool FindAndReplace(string &str, const string &substr, const string &newstr)
vector< string > chSearchPath
STATIC NORETURN void AbortErrorMessage(const char *fname, const vector< string > &PathList, access_scheme scheme)
void check_data(const char *fname, access_scheme scheme)