8 #if defined(__ia64) && defined(__INTEL_COMPILER)
9 extern "C" unsigned long fpgetmask();
10 extern "C" void fpsetmask(
unsigned long);
13 #if defined(__sun) || defined(__sgi)
15 #if defined(HAVE_SUNMATH) || defined(FLUSH_DENORM_TO_ZERO)
20 #if defined(__alpha) && defined(__linux__) && defined(__GNUC__)
25 #if defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140
29 #if defined(__unix) || defined(__APPLE__)
33 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
34 #include <sys/types.h>
35 #include <sys/sysctl.h>
131 if(
sizeof(
double) == 8 )
149 if(
sizeof(
double) == 8 )
202 # if defined(_SC_NPROCESSORS_ONLN)
203 #if defined(__APPLE__)
204 size_t sizeOfInt =
sizeof(int);
206 sysctlbyname(
"hw.physicalcpu", &physicalCores, &sizeOfInt, NULL, 0);
211 # elif defined(_SC_NPROC_ONLN)
213 # elif defined(_SC_CRAY_NCPU)
215 # elif defined(_WIN32)
216 str = getenv(
"NUMBER_OF_PROCESSORS" );
227 # elif defined(HW_AVAILCPU)
228 #if defined(__APPLE__)
229 size_t sizeOfInt =
sizeof(int);
231 sysctlbyname(
"hw.physicalcpu", &physicalCores, &sizeOfInt, NULL, 0);
237 mib[1] = HW_AVAILCPU;
262 str = getenv(
"COMPUTERNAME" );
264 str = getenv(
"HOSTNAME" );
274 const char *path = getenv(
"CLOUDY_DATA_PATH" );
277 string separator(
";" );
280 string separator(
":" );
286 string chSearchPathRaw = ( path != NULL ) ?
string( path ) : string( CLOUDY_DATA_PATH );
288 chSearchPathRaw =
"." + separator + chSearchPathRaw + separator;
292 string chCloudyRoot = string( CLOUDY_ROOT );
295 while(
FindAndReplace( chSearchPathRaw, separator +
"+" + separator,
305 char* ptr = realpath( p->c_str(), NULL );
314 char chEnd = *p->rbegin();
335 setlocale(LC_ALL,
"POSIX");
349 # if defined(_MSC_VER)
350 volatile unsigned int NewMask;
355 NewMask = _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_INVALID;
358 _controlfp( NewMask , _MCW_EM );
364 # elif defined(__GNUC__) && ( defined(__i386) || defined(__amd64) ) && !defined(__clang__)
365 volatile unsigned int Old_Mask, New_Mask;
366 # if defined(__SSE__) || defined(__SSE2__)
367 volatile unsigned int SSE_Mask;
370 # define _FPU_MASK_IM 0x01
371 # define _FPU_MASK_DM 0x02
372 # define _FPU_MASK_ZM 0x04
373 # define _FPU_MASK_OM 0x08
374 # define _FPU_MASK_UM 0x10
375 # define _FPU_MASK_PM 0x20
385 volatile unsigned int UnMask = ~((
unsigned int)( _FPU_MASK_ZM | _FPU_MASK_IM | _FPU_MASK_OM ));
387 __asm__
volatile(
"fnstcw %0" :
"=m" (*&Old_Mask));
389 New_Mask = Old_Mask & UnMask;
391 __asm__
volatile(
"fldcw %0" : :
"m" (*&New_Mask));
393 # if defined(__SSE__) || defined(__SSE2__)
406 __asm__
volatile(
"ldmxcsr %0" : :
"m" (*&SSE_Mask) );
411 # elif defined(__ia64)
413 # define FPSR_TRAP_VD (1 << 0)
414 # define FPSR_TRAP_DD (1 << 1)
415 # define FPSR_TRAP_ZD (1 << 2)
416 # define FPSR_TRAP_OD (1 << 3)
417 # define FPSR_TRAP_UD (1 << 4)
418 # define FPSR_TRAP_ID (1 << 5)
420 # define FPSR_SF0_FTZ (1 << 6)
422 # if defined(__GNUC_EXCL__)
424 # define _IA64_REG_AR_FPSR 40
426 # define ia64_getreg( regnum ) __asm__ volatile( "mov %0=ar%1" : "=r" (fpsr) : "i"(regnum) )
427 # define ia64_setreg( regnum, val ) __asm__ volatile( "mov ar%0=%1" :: "i" (regnum), "r"(val): "memory" )
428 # define ia64_serialize __asm__ volatile( "srlz.i" );
430 volatile unsigned long fpsr, flags = FPSR_TRAP_VD | FPSR_TRAP_ZD | FPSR_TRAP_OD;
432 ia64_getreg( _IA64_REG_AR_FPSR );
434 # if defined(FLUSH_DENORM_TO_ZERO)
435 fpsr |= FPSR_SF0_FTZ;
437 ia64_setreg( _IA64_REG_AR_FPSR, fpsr );
441 # elif defined(__INTEL_COMPILER)
443 unsigned long fpsr = fpgetmask();
444 fpsr |= FPSR_TRAP_VD | FPSR_TRAP_ZD | FPSR_TRAP_OD;
449 # elif defined(__sun) || defined(__sgi)
454 # if defined(HAVE_SUNMATH) || defined(FLUSH_DENORM_TO_ZERO)
491 nonstandard_arithmetic();
496 mask = mask | FP_X_INV | FP_X_OFL | FP_X_DZ;
499 # elif defined(__alpha) && defined(__linux__) && defined(__GNUC__)
504 # ifdef FE_NONIEEE_ENV
508 fesetenv(FE_NONIEEE_ENV);
511 # elif defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140
514 feenableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
526 sigemptyset( &p_action.sa_mask );
527 p_action.sa_flags = SA_NODEFER;
529 p_default.sa_handler = SIG_DFL;
530 sigemptyset( &p_default.sa_mask );
531 p_default.sa_flags = SA_NODEFER;
533 for(
int sig=1; sig <= 31; sig++ )
536 if( sigaction( sig, NULL, NULL ) == 0 )
538 if( sig != SIGSTOP && sig != SIGCONT )
539 sigaction( sig, action(), NULL );
578 vector<string>::size_type begin, end;
611 string FileName( fname );
614 for( vector<string>::size_type
i=begin;
i < end; ++
i )
619 PathList.push_back( FileName );
635 vector<string> PathList;
638 vector<string>::const_iterator ptr;
639 for( ptr=PathList.begin(); ptr != PathList.end() && !io.is_open(); ++ptr )
640 io.open( ptr->c_str(),
mode_r );
648 while( getline( io, line ) )
653 if( line.find(
'/' ) != string::npos )
655 if( line.find(
'\\' ) != string::npos )
662 istringstream iss( line );
663 iss >> md5sum >> path;
674 fprintf(
ioQQQ,
"\nI could not open the data file %s\n\n", fname );
676 fprintf(
ioQQQ,
"\nPROBLEM DISASTER I could not open the data file %s\n\n", fname );
681 fprintf(
ioQQQ,
"Although there may be other reasons you have received this error,\n");
682 fprintf(
ioQQQ,
"the most likely are that the path has not been properly set or\n");
683 fprintf(
ioQQQ,
"that the path points to an old version of the data. It should\n");
684 fprintf(
ioQQQ,
"point to the data directory you downloaded from the web site.\n\n");
685 fprintf(
ioQQQ,
"Please use \"make\" to compile the code. This will automatically\n");
686 fprintf(
ioQQQ,
"set the path correctly. Alternatively you can set the environment\n");
687 fprintf(
ioQQQ,
"variable CLOUDY_DATA_PATH to point to the data directory using\n");
688 fprintf(
ioQQQ,
"the shell command \nexport CLOUDY_DATA_PATH=\"/path/to/data\"\n");
698 for( vector<string>::const_iterator ptr=PathList.begin(); ptr != PathList.end(); ++ptr )
703 fprintf(
ioQQQ,
"\nAlthough there may be other reasons you have received this error,\n");
704 fprintf(
ioQQQ,
"the most likely are that you mistyped the file name, or that you\n");
705 fprintf(
ioQQQ,
"are running Cloudy in the wrong directory. If you are running a\n");
706 fprintf(
ioQQQ,
"COMPILE command, this needs to be done in the data directory.\n\n");
707 fprintf(
ioQQQ,
"It is is also possible that the path has not been properly set. It\n");
708 fprintf(
ioQQQ,
"should point to the data directory you downloaded from the web site.\n");
709 fprintf(
ioQQQ,
"Please use \"make\" to compile the code. This will automatically\n");
710 fprintf(
ioQQQ,
"set the path correctly. Alternatively you can set the environment\n");
711 fprintf(
ioQQQ,
"variable CLOUDY_DATA_PATH to point to the data directory using\n");
712 fprintf(
ioQQQ,
"the shell command \nexport CLOUDY_DATA_PATH=\"/path/to/data\"\n");
726 ASSERT( PathList.size() == 1 );
728 fprintf(
ioQQQ,
" open_data writing %s\n", PathList[0].c_str() );
732 vector<string>::const_iterator ptr;
733 vector<string> PathSuccess;
734 for( ptr=PathList.begin(); ptr != PathList.end(); ++ptr )
736 FILE* handle =
sys_fopen( ptr->c_str(),
"r" );
739 fprintf(
ioQQQ,
" open_data trying to read %s found %c", ptr->c_str(),
TorF(handle != NULL) );
747 if( find( PathSuccess.begin(), PathSuccess.end(), *ptr ) == PathSuccess.end() )
748 PathSuccess.push_back( *ptr );
755 fprintf(
ioQQQ,
"CAUTION: multiple matches for file %s found:\n", fname );
756 for(
size_t i=0; i < PathSuccess.size(); ++i )
762 return ( PathSuccess.size() > 0 ) ? PathSuccess[0] :
"";
772 bool lgRead = ( m ==
"r" || m ==
"rb" );
780 vector<string> PathList;
789 handle =
sys_fopen( path.c_str(), mode );
809 bool lgRead = ( (mode&ios_base::out) == 0 );
817 vector<string> PathList;
820 ASSERT( !stream.is_open() );
826 stream.open( path.c_str(), mode );
829 if( !stream.is_open() )
852 vector<string> PathList;
862 err =
MPI_File_open( MPI_COMM_WORLD, const_cast<char*>(path.c_str()), mode, MPI_INFO_NULL, &fh );
885 map<string,string>::const_iterator ptr =
cpu.
i().
md5sum_expct.find( fname );
888 fstream ioFile( fpath,
mode_r );
889 if( ioFile.is_open() )
892 if( md5sum != ptr->second )
894 fprintf(
ioQQQ,
"NOTE: using modified data in %s.\n", fname );
921 int32 *y =
reinterpret_cast<int32*
>(x);
922 for( i=0; i < n; i++ )
927 for( i=0; i < n; i++ )
934 if(
sizeof(
double) == 8 )
939 int32 *y =
reinterpret_cast<int32*
>(&x);
954 if(
sizeof(
double) == 8 )
957 int64 *y =
reinterpret_cast<int64*
>(x);
958 for( i=0; i < n; i++ )
961 int32 *y =
reinterpret_cast<int32*
>(x);
962 for( i=0; i < n; i++ )
971 for( i=0; i < n; i++ )
979 if(
sizeof(
sys_float) == 4 && FLT_MAX_EXP-FLT_MIN_EXP+3 == 256 )
981 const int32 *p =
reinterpret_cast<const int32*
>(&x);
982 int32 r = *p & 0x7f800000; r ^= 0x7f800000;
983 int32 s = *p & 0x007fffff;
984 return ( r == 0 && s != 0 );
994 if(
sizeof(
double) == 8 && DBL_MAX_EXP-DBL_MIN_EXP+3 == 2048 )
997 const int64 *p =
reinterpret_cast<const int64*
>(&x);
998 int64 r = *p & INT64_LIT(0x7ff0000000000000); r ^= INT64_LIT(0x7ff0000000000000);
999 int64 s = *p & INT64_LIT(0x000fffffffffffff);
1000 return ( r == 0 && s != 0 );
1002 const int32 *p =
reinterpret_cast<const int32*
>(&x);
1005 int32 r = p[1] & 0x7ff00000; r ^= 0x7ff00000;
1006 int32 s = p[1] & 0x000fffff; s |= p[0];
1007 return ( r == 0 && s != 0 );
1011 int32 r = p[0] & 0x7ff00000; r ^= 0x7ff00000;
1012 int32 s = p[0] & 0x000fffff; s |= p[1];
1013 return ( r == 0 && s != 0 );
map< string, string > md5sum_expct
string MD5datastream(fstream &ioFile)
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)
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)
void check_data(const char *fpath, const char *fname)
#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)