124 #include <fpu_control.h> 133 return fegetenv (&fenv) ? -1 : (fenv.__control & FE_ALL_EXCEPT);
137 feenableexcept (
unsigned int excepts) {
139 unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
142 if(fegetenv (&fenv))
return -1;
143 old_excepts = fenv.__control & FE_ALL_EXCEPT;
146 fenv.__control &= ~new_excepts;
147 fenv.__mxcsr &= ~(new_excepts << 7);
149 return (fesetenv (&fenv) ? -1 : old_excepts);
153 fedisableexcept (
unsigned int excepts) {
155 unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
158 if(fegetenv (&fenv))
return -1;
159 old_excepts = fenv.__control & FE_ALL_EXCEPT;
162 fenv.__control |= new_excepts;
163 fenv.__mxcsr |= new_excepts << 7;
165 return (fesetenv (&fenv) ? -1 : old_excepts);
229 char const* debugInfo);
232 char const* debugInfo);
235 char const* debugInfo);
238 char const* debugInfo);
268 LogVerbatim(
"FPE_Enable") <<
"\nSettings in EnableFloatingPointExceptions constructor";
329 typedef std::vector<std::string> VString;
333 VString
const empty_VString;
336 for(VString::const_iterator it(moduleNames.begin()), itEnd = moduleNames.end(); it != itEnd; ++it) {
344 if(enableDivByZeroEx) flags |= FE_DIVBYZERO;
345 if(enableInvalidEx) flags |= FE_INVALID;
346 if(enableOverFlowEx) flags |= FE_OVERFLOW;
347 if(enableUnderFlowEx) flags |= FE_UNDERFLOW;
351 assert(flags == fpuState);
354 LogVerbatim(
"FPE_Enable") <<
"\nSettings for module " << *it;
370 LogVerbatim(
"FPE_Enable") <<
"\nSettings after endJob ";
548 desc.
addUntracked<
bool>(
"reportSettings",
false)->setComment(
549 "Log FPE settings at different phases of the job.");
550 desc.
addUntracked<
bool>(
"setPrecisionDouble",
true)->setComment(
551 "Set the FPU to use double precision");
554 validator.
setComment(
"FPU exceptions to enable/disable for the requested module");
555 validator.
addUntracked<
bool>(
"enableDivByZeroEx",
false)->setComment(
556 "Enable/disable exception for 'divide by zero'");
557 validator.
addUntracked<
bool>(
"enableInvalidEx",
false)->setComment(
558 "Enable/disable exception for 'invalid' math operations (e.g. sqrt(-1))");
559 validator.
addUntracked<
bool>(
"enableOverFlowEx",
false)->setComment(
560 "Enable/disable exception for numeric 'overflow' (value to big for type)");
561 validator.
addUntracked<
bool>(
"enableUnderFlowEx",
false)->setComment(
562 "Enable/disable exception for numeric 'underflow' (value to small to be represented accurately)");
565 node.
setComment(
"Contains the names for PSets where the PSet name matches the label of a module for which you want to modify the FPE");
568 descriptions.
add(
"EnableFloatingPointExceptions", desc);
569 descriptions.
setComment(
"This service allows you to control the FPU and its exceptions on a per module basis.");
576 char const* debugInfo) {
579 std::map<std::string, fpu_flags_type>::const_iterator iModule =
stateMap_.find(moduleLabel);
584 fpuState = iModule->second;
590 <<
"\nSettings for module label \"" 606 <<
"\nSettings for module label \"" 617 char const* debugInfo) {
620 std::map<std::string, fpu_flags_type>::const_iterator iModule =
stateMap_.find(moduleLabel);
625 fpuState = iModule->second;
631 <<
"\nSettings for module label \"" 649 fpuState = iModule->second;
656 <<
"\nSettings for module label \"" 691 if(precisionDouble) {
695 cw = (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;
712 feclearexcept(FE_ALL_EXCEPT);
718 if(exceptionsToModify & FE_DIVBYZERO) {
719 if(target & FE_DIVBYZERO) {
720 exceptionsToEnable |= FE_DIVBYZERO;
723 exceptionsToDisable |= FE_DIVBYZERO;
726 if(exceptionsToModify & FE_INVALID) {
727 if(target & FE_INVALID) {
728 exceptionsToEnable |= FE_INVALID;
731 exceptionsToDisable |= FE_INVALID;
734 if(exceptionsToModify & FE_OVERFLOW) {
735 if(target & FE_OVERFLOW) {
736 exceptionsToEnable |= FE_OVERFLOW;
739 exceptionsToDisable |= FE_OVERFLOW;
742 if(exceptionsToModify & FE_UNDERFLOW) {
743 if(target & FE_UNDERFLOW) {
744 exceptionsToEnable |= FE_UNDERFLOW;
747 exceptionsToDisable |= FE_UNDERFLOW;
750 if(exceptionsToEnable != 0) {
751 feenableexcept(exceptionsToEnable);
753 if(exceptionsToDisable != 0) {
754 fedisableexcept(exceptionsToDisable);
760 feclearexcept(FE_ALL_EXCEPT);
762 LogVerbatim(
"FPE_Enable") <<
"Floating point exception mask is " 763 << std::showbase << std::hex << femask;
765 if(femask & FE_DIVBYZERO)
766 LogVerbatim(
"FPE_Enable") <<
"\tDivByZero exception is on";
768 LogVerbatim(
"FPE_Enable") <<
"\tDivByZero exception is off";
770 if(femask & FE_INVALID)
771 LogVerbatim(
"FPE_Enable") <<
"\tInvalid exception is on";
773 LogVerbatim(
"FPE_Enable") <<
"\tInvalid exception is off";
775 if(femask & FE_OVERFLOW)
776 LogVerbatim(
"FPE_Enable") <<
"\tOverFlow exception is on";
778 LogVerbatim(
"FPE_Enable") <<
"\tOverflow exception is off";
780 if(femask & FE_UNDERFLOW)
781 LogVerbatim(
"FPE_Enable") <<
"\tUnderFlow exception is on";
783 LogVerbatim(
"FPE_Enable") <<
"\tUnderFlow exception is off";
789 #if defined(__linux__) void preModuleGlobalEndLumi(GlobalContext const &, ModuleCallingContext const &)
void watchPostModuleGlobalEndLumi(PostModuleGlobalEndLumi::slot_type const &iSlot)
void watchPostModuleConstruction(PostModuleConstruction::slot_type const &iSlot)
void preModuleGlobalBeginLumi(GlobalContext const &, ModuleCallingContext const &)
void watchPreModuleGlobalBeginRun(PreModuleGlobalBeginRun::slot_type const &iSlot)
void setComment(std::string const &value)
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_SERVICE_MAKER(concrete, maker)
void preModuleConstruction(ModuleDescription const &)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void postModuleGlobalBeginLumi(GlobalContext const &, ModuleCallingContext const &)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void preModuleEvent(StreamContext const &, ModuleCallingContext const &)
void preActions(ModuleDescription const &, char const *debugInfo)
void watchPostModuleEndStream(PostModuleEndStream::slot_type const &iSlot)
void preModuleBeginJob(ModuleDescription const &)
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void watchPreModuleConstruction(PreModuleConstruction::slot_type const &iSlot)
EnableFloatingPointExceptions
void preModuleStreamEndRun(StreamContext const &, ModuleCallingContext const &)
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
void establishModuleEnvironments(ParameterSet const &)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
void watchPostModuleGlobalBeginLumi(PostModuleGlobalBeginLumi::slot_type const &iSlot)
void watchPostModuleStreamEndLumi(PostModuleStreamEndLumi::slot_type const &iSlot)
std::vector< Variable::Flags > flags
void watchPostModuleStreamBeginRun(PostModuleStreamBeginRun::slot_type const &iSlot)
void preModuleStreamEndLumi(StreamContext const &, ModuleCallingContext const &)
void enableAndDisableExcept(fpu_flags_type target)
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
void postModuleBeginStream(StreamContext const &, ModuleCallingContext const &)
void watchPreModuleBeginStream(PreModuleBeginStream::slot_type const &iSlot)
std::string const & moduleLabel() const
void watchPreModuleGlobalEndRun(PreModuleGlobalEndRun::slot_type const &iSlot)
void preModuleStreamBeginLumi(StreamContext const &, ModuleCallingContext const &)
void postModuleStreamBeginLumi(StreamContext const &, ModuleCallingContext const &)
void setComment(std::string const &value)
fpu_flags_type defaultState_
std::map< std::string, fpu_flags_type > stateMap_
ModuleDescription const * moduleDescription() const
void watchPreModuleEndJob(PreModuleEndJob::slot_type const &iSlot)
void postModuleGlobalEndLumi(GlobalContext const &, ModuleCallingContext const &)
void postModuleStreamEndLumi(StreamContext const &, ModuleCallingContext const &)
void postModuleStreamBeginRun(StreamContext const &, ModuleCallingContext const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void postModuleEndJob(ModuleDescription const &md)
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
void postModuleGlobalEndRun(GlobalContext const &, ModuleCallingContext const &)
void watchPreModuleGlobalBeginLumi(PreModuleGlobalBeginLumi::slot_type const &iSlot)
void watchPostModuleStreamEndRun(PostModuleStreamEndRun::slot_type const &iSlot)
void watchPreModuleStreamBeginLumi(PreModuleStreamBeginLumi::slot_type const &iSlot)
void preModuleBeginStream(StreamContext const &, ModuleCallingContext const &)
void setComment(std::string const &value)
void watchPostModuleBeginStream(PostModuleBeginStream::slot_type const &iSlot)
void postModuleConstruction(ModuleDescription const &)
void postModuleBeginJob(ModuleDescription const &)
void watchPostModuleGlobalEndRun(PostModuleGlobalEndRun::slot_type const &iSlot)
void watchPostModuleStreamBeginLumi(PostModuleStreamBeginLumi::slot_type const &iSlot)
void watchPreModuleStreamEndLumi(PreModuleStreamEndLumi::slot_type const &iSlot)
void watchPreModuleStreamBeginRun(PreModuleStreamBeginRun::slot_type const &iSlot)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void watchPreModuleEndStream(PreModuleEndStream::slot_type const &iSlot)
void preModuleEndStream(StreamContext const &, ModuleCallingContext const &)
void postModuleGlobalBeginRun(GlobalContext const &, ModuleCallingContext const &)
void preModuleStreamBeginRun(StreamContext const &, ModuleCallingContext const &)
ModuleCallingContext const * previousModuleOnThread() const
void postModuleEndStream(StreamContext const &, ModuleCallingContext const &)
void postModuleEvent(StreamContext const &, ModuleCallingContext const &)
void watchPreModuleStreamEndRun(PreModuleStreamEndRun::slot_type const &iSlot)
void watchPostModuleBeginJob(PostModuleBeginJob::slot_type const &iSlot)
void watchPostModuleGlobalBeginRun(PostModuleGlobalBeginRun::slot_type const &iSlot)
void preModuleGlobalBeginRun(GlobalContext const &, ModuleCallingContext const &)
void postActions(ModuleDescription const &, char const *debugInfo)
void preModuleGlobalEndRun(GlobalContext const &, ModuleCallingContext const &)
void watchPostModuleEndJob(PostModuleEndJob::slot_type const &iSlot)
void postModuleStreamEndRun(StreamContext const &, ModuleCallingContext const &)
void watchPreModuleGlobalEndLumi(PreModuleGlobalEndLumi::slot_type const &iSlot)
void setPrecision(bool precisionDouble)
void preModuleEndJob(ModuleDescription const &md)
EnableFloatingPointExceptions(ParameterSet const &pset, ActivityRegistry ®istry)