9extern "C" unsigned long fegettrapenable();
10extern "C" void fesettrapenable(
unsigned long);
13#if defined(__ia64) && defined(__INTEL_COMPILER)
14extern "C" unsigned long fpgetmask();
15extern "C" void fpsetmask(
unsigned long);
18#if defined(__sun) || defined(__sgi)
20#if defined(HAVE_SUNMATH) || defined(FLUSH_DENORM_TO_ZERO)
25#if defined(__alpha) && defined(__linux__) && defined(__GNUC__)
30#if defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140
34#if defined(__unix) || defined(__APPLE__)
38#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
40#include <sys/sysctl.h>
131 if(
sizeof(
double) == 8 )
149 if(
sizeof(
double) == 8 )
202# if defined(_SC_NPROCESSORS_ONLN)
204# elif defined(_SC_NPROC_ONLN)
206# elif defined(_SC_CRAY_NCPU)
208# elif defined(_WIN32)
209 str = getenv(
"NUMBER_OF_PROCESSORS" );
220# elif defined(HW_AVAILCPU)
224 mib[1] = HW_AVAILCPU;
248 str = getenv(
"COMPUTERNAME" );
250 str = getenv(
"HOSTNAME" );
260 const char *path = getenv(
"CLOUDY_DATA_PATH" );
263 string chSearchPathRaw = ( path != NULL ) ?
string( path ) : string( CLOUDY_DATA_PATH );
266 string separator(
";" );
269 string separator(
":" );
302# if defined(_MSC_VER)
303 volatile unsigned int NewMask;
308 NewMask = _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_INVALID;
311 _controlfp( NewMask , _MCW_EM );
317# elif defined(__GNUC__) && ( defined(__i386) || defined(__amd64) ) && !defined(__clang__)
318 volatile unsigned int Old_Mask, New_Mask;
319# if defined(__SSE__) || defined(__SSE2__)
320 volatile unsigned int SSE_Mask;
323# define _FPU_MASK_IM 0x01
324# define _FPU_MASK_DM 0x02
325# define _FPU_MASK_ZM 0x04
326# define _FPU_MASK_OM 0x08
327# define _FPU_MASK_UM 0x10
328# define _FPU_MASK_PM 0x20
338 volatile unsigned int UnMask = ~((
unsigned int)( _FPU_MASK_ZM | _FPU_MASK_IM | _FPU_MASK_OM ));
340 __asm__
volatile(
"fnstcw %0" :
"=m" (*&Old_Mask));
342 New_Mask = Old_Mask & UnMask;
344 __asm__
volatile(
"fldcw %0" : :
"m" (*&New_Mask));
346# if defined(__SSE__) || defined(__SSE2__)
348# if defined(FLUSH_DENORM_TO_ZERO)
359 __asm__
volatile(
"ldmxcsr %0" : :
"m" (*&SSE_Mask) );
364# elif defined(__ia64)
366# define FPSR_TRAP_VD (1 << 0)
367# define FPSR_TRAP_DD (1 << 1)
368# define FPSR_TRAP_ZD (1 << 2)
369# define FPSR_TRAP_OD (1 << 3)
370# define FPSR_TRAP_UD (1 << 4)
371# define FPSR_TRAP_ID (1 << 5)
373# define FPSR_SF0_FTZ (1 << 6)
375# if defined(__GNUC_EXCL__)
377# define _IA64_REG_AR_FPSR 40
379# define ia64_getreg( regnum ) __asm__ volatile( "mov %0=ar%1" : "=r" (fpsr) : "i"(regnum) )
380# define ia64_setreg( regnum, val ) __asm__ volatile( "mov ar%0=%1" :: "i" (regnum), "r"(val): "memory" )
381# define ia64_serialize __asm__ volatile( "srlz.i" );
383 volatile unsigned long fpsr, flags = FPSR_TRAP_VD | FPSR_TRAP_ZD | FPSR_TRAP_OD;
385 ia64_getreg( _IA64_REG_AR_FPSR );
387# if defined(FLUSH_DENORM_TO_ZERO)
388 fpsr |= FPSR_SF0_FTZ;
390 ia64_setreg( _IA64_REG_AR_FPSR, fpsr );
394# elif defined(__INTEL_COMPILER)
396 unsigned long fpsr = fpgetmask();
397 fpsr |= FPSR_TRAP_VD | FPSR_TRAP_ZD | FPSR_TRAP_OD;
399# elif defined(__HP_aCC)
401 unsigned long fpsr = fegettrapenable();
402 fpsr |= FPSR_TRAP_VD | FPSR_TRAP_ZD | FPSR_TRAP_OD;
403 fesettrapenable( fpsr );
407# elif defined(__sun) || defined(__sgi)
412# if defined(HAVE_SUNMATH) || defined(FLUSH_DENORM_TO_ZERO)
449 nonstandard_arithmetic();
454 mask = mask | FP_X_INV | FP_X_OFL | FP_X_DZ;
457# elif defined(__alpha) && defined(__linux__) && defined(__GNUC__)
462# ifdef FE_NONIEEE_ENV
466 fesetenv(FE_NONIEEE_ENV);
469# elif defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140
472 feenableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
484 sigemptyset( &p_action.sa_mask );
485 p_action.sa_flags = SA_NODEFER;
487 p_default.sa_handler = SIG_DFL;
488 sigemptyset( &p_default.sa_mask );
489 p_default.sa_flags = SA_NODEFER;
491 for(
int sig=1; sig <= 31; sig++ )
494 if( sigaction( sig, NULL, NULL ) == 0 )
496 if( sig != SIGSTOP && sig != SIGCONT )
497 sigaction( sig, action(), NULL );
515 cpu.i().enable_traps();
526 fprintf(
ioQQQ,
"The path is:\n");
536 vector<string>::size_type begin, end;
544 end =
cpu.i().chSearchPath.size()-1;
549 end =
cpu.i().chSearchPath.size();
554 end =
cpu.i().chSearchPath.size()-1;
567 string FileName( fname );
568 for( vector<string>::size_type
i=begin;
i < end; ++
i )
569 PathList.push_back(
cpu.i().chSearchPath[
i] + FileName );
578 fprintf(
ioQQQ,
"\nI could not open the data file %s\n\n", fname );
580 fprintf(
ioQQQ,
"\nPROBLEM DISASTER I could not open the data file %s\n\n", fname );
585 fprintf(
ioQQQ,
"Although there may be other reasons you have received this error,\n");
586 fprintf(
ioQQQ,
"the most likely are that the path has not been properly set\n");
587 fprintf(
ioQQQ,
"or that the path points to an old version of the data.\n\n");
588 fprintf(
ioQQQ,
"Please have a look at the file path.h in the source directory\n");
589 fprintf(
ioQQQ,
"to check how the variable CLOUDY_DATA_PATH is set - \n");
590 fprintf(
ioQQQ,
"it should give the location of the data files I need.\n");
591 fprintf(
ioQQQ,
"These are the files in the data download from the web site.\n\n");
592 fprintf(
ioQQQ,
"Recompile the code with the correct data path set in path.h\n");
593 fprintf(
ioQQQ,
"or use the shell command \nexport CLOUDY_DATA_PATH=\"/path/to/data\"\n to set the\n");
594 fprintf(
ioQQQ,
"path from a bash command prompt.\n\n");
595 cpu.i().printDataPath();
602 fprintf(
ioQQQ,
"These are all the paths I tried:\n" );
603 for( vector<string>::const_iterator ptr=PathList.begin(); ptr != PathList.end(); ++ptr )
604 fprintf(
ioQQQ,
" ==%s==\n", ptr->c_str() );
608 fprintf(
ioQQQ,
"\nAlthough there may be other reasons you have received this error,\n");
609 fprintf(
ioQQQ,
"the most likely are that you mistyped the file name, or that you\n");
610 fprintf(
ioQQQ,
"are running Cloudy in the wrong directory. If you are running a\n");
611 fprintf(
ioQQQ,
"COMPILE command, this needs to be done in the data directory.\n\n");
612 fprintf(
ioQQQ,
"Otherwise, please have a look at the file path.h in the source\n");
613 fprintf(
ioQQQ,
"directory to check how the variable CLOUDY_DATA_PATH is set - \n");
614 fprintf(
ioQQQ,
"it should give the location of the data files I need.\n");
615 fprintf(
ioQQQ,
"These are the files in the data download from the web site.\n\n");
616 fprintf(
ioQQQ,
"Recompile the code with the correct data path set in path.h\n");
617 fprintf(
ioQQQ,
"or use the shell command \nexport CLOUDY_DATA_PATH=\"/path/to/data\"\n to set the\n");
618 fprintf(
ioQQQ,
"path from a bash command prompt.\n\n");
621 fprintf(
ioQQQ,
"Sorry.\n\n\n");
632 vector<string> PathList;
633 cpu.i().getPathList( fname, PathList, scheme );
636 vector<string>::const_iterator ptr;
637 for( ptr=PathList.begin(); ptr != PathList.end() && handle == NULL; ++ptr )
639 handle = fopen( ptr->c_str(), mode );
641 fprintf(
ioQQQ,
" open_data trying %s mode %s handle %p\n", ptr->c_str(), mode, handle );
644 if( handle == NULL &&
lgAbort )
659 vector<string> PathList;
660 cpu.i().getPathList( fname, PathList, scheme );
662 ASSERT( !stream.is_open() );
663 vector<string>::const_iterator ptr;
664 for( ptr=PathList.begin(); ptr != PathList.end() && !stream.is_open(); ++ptr )
666 stream.open( ptr->c_str(), mode );
668 fprintf(
ioQQQ,
" open_data trying %s succes? %c\n", ptr->c_str(),
TorF(stream.is_open()) );
671 if( !stream.is_open() &&
lgAbort )
685 *
reinterpret_cast<int32*
>(&x) =
cpu.i().Float_SNaN_Value;
697 int32 *y =
reinterpret_cast<int32*
>(x);
698 for(
i=0;
i < n;
i++ )
699 *y++ =
cpu.i().Float_SNaN_Value;
703 for(
i=0;
i < n;
i++ )
710 if(
sizeof(
double) == 8 )
713 *
reinterpret_cast<int64*
>(&x) =
cpu.i().Double_SNaN_Value;
715 int32 *y =
reinterpret_cast<int32*
>(&x);
716 *y++ =
cpu.i().Double_SNaN_Value[0];
717 *y =
cpu.i().Double_SNaN_Value[1];
730 if(
sizeof(
double) == 8 )
733 int64 *y =
reinterpret_cast<int64*
>(x);
734 for(
i=0;
i < n;
i++ )
735 *y++ =
cpu.i().Double_SNaN_Value;
737 int32 *y =
reinterpret_cast<int32*
>(x);
738 for(
i=0;
i < n;
i++ )
740 *y++ =
cpu.i().Double_SNaN_Value[0];
741 *y++ =
cpu.i().Double_SNaN_Value[1];
747 for(
i=0;
i < n;
i++ )
755 if(
sizeof(
sys_float) == 4 && FLT_MAX_EXP-FLT_MIN_EXP+3 == 256 )
757 const int32 *p =
reinterpret_cast<const int32*
>(&x);
758 int32 r = *p & 0x7f800000; r ^= 0x7f800000;
759 int32 s = *p & 0x007fffff;
760 return ( r == 0 && s != 0 );
770 if(
sizeof(
double) == 8 && DBL_MAX_EXP-DBL_MIN_EXP+3 == 2048 )
773 const int64 *p =
reinterpret_cast<const int64*
>(&x);
774 int64 r = *p & 0x7ff0000000000000; r ^= 0x7ff0000000000000;
775 int64 s = *p & 0x000fffffffffffff;
776 return ( r == 0 && s != 0 );
778 const int32 *p =
reinterpret_cast<const int32*
>(&x);
779 if(
cpu.i().little_endian() )
781 int32 r = p[1] & 0x7ff00000; r ^= 0x7ff00000;
782 int32 s = p[1] & 0x000fffff; s |= p[0];
783 return ( r == 0 && s != 0 );
785 else if(
cpu.i().big_endian() )
787 int32 r = p[0] & 0x7ff00000; r ^= 0x7ff00000;
788 int32 s = p[0] & 0x000fffff; s |= p[1];
789 return ( r == 0 && s != 0 );
void Split(const string &str, const string &sep, vector< string > &lst, split_mode mode)
NORETURN void TotalInsanity(void)
#define DEBUG_ENTRY(funcname)
int32 Double_SNaN_Value[2]
void set_signal_handlers()
union t_cpu_i::@054004306043002077260303305210015065171251205067 endian
static void signal_handler(int sig)
bool little_endian() const
void getPathList(const char *fname, vector< string > &PathList, access_scheme scheme) const
void enable_traps() const
bool p_lgMPISingleRankMode
vector< string > p_exit_status
void printDataPath() const
vector< string > chSearchPath
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
STATIC NORETURN void AbortErrorMessage(const char *fname, vector< string > &PathList, access_scheme scheme)
bool MyIsnan(const sys_float &x)
void set_NaN(sys_float &x)