Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEGFAULT or SIGFPE at src/tools/SwitchingFunction.cpp:188. #210

Closed
tripiana opened this issue Dec 20, 2016 · 6 comments
Closed

SEGFAULT or SIGFPE at src/tools/SwitchingFunction.cpp:188. #210

tripiana opened this issue Dec 20, 2016 · 6 comments

Comments

@tripiana
Copy link

When running a gromacs 5.1.4, with plumed 2.3.0 and hrex, and matheval 1.1.11.

In the case this line: dmax_2=dmax*dmax; is executed with dmax=std::numeric_limits<double>::max(); then dmax_2 has a value similar to std::numeric_limits<double>::infinity(); but in some processors like Intel(R) Xeon(R) CPU E5-2670 when the code is compiled with Intel Compilers (in my case 2017.0.098) this multiplication (that is beyond the representable double values) throws a SEGFAULT (when compiled with -O3, release compilation) of a SIGFPE (when compiled with -O0 -g, debug compilation).

Applying this patch:

*** src/tools/SwitchingFunction.cpp 2016-12-12 15:25:12.000000000 +0100
--- src/tools/SwitchingFunction.cpp 2016-12-15 11:12:19.191539000 +0100
***************
*** 184,191 ****
    if(present && !Tools::parse(data,"D_0",d0)) errormsg="could not parse D_0";

    present=Tools::findKeyword(data,"D_MAX");
!   if(present && !Tools::parse(data,"D_MAX",dmax)) errormsg="could not parse D_MAX";
!   dmax_2=dmax*dmax;
    bool dostretch=false;
    Tools::parseFlag(data,"STRETCH",dostretch); // this is ignored now
    dostretch=true;
--- 184,193 ----
    if(present && !Tools::parse(data,"D_0",d0)) errormsg="could not parse D_0";

    present=Tools::findKeyword(data,"D_MAX");
!   if(present){
!     if(!Tools::parse(data,"D_MAX",dmax)) errormsg="could not parse D_MAX";
!     else dmax_2=dmax*dmax;
!   }
    bool dostretch=false;
    Tools::parseFlag(data,"STRETCH",dostretch); // this is ignored now
    dostretch=true;

with patch -p0 < plumed.patch solves the gromacs signal failure. I have tested this patch with gromacs and input files that caused a failure, and it worked OK. The results were OK.

Please, confirm the patch is correct, so I can apply it in a production environment. Merge the patch into your code if you think it is OK. If not OK, please, give me details on how to fix this error.

Thanks in advance,
Carlos.

@tripiana
Copy link
Author

@GiovanniBussi could you, please, take a look on this? Thanks!

@GiovanniBussi
Copy link
Member

Hi,

thanks for reporting this issue and finding a solution as well.

Could you please try if the following fix works as well?

--- a/src/tools/SwitchingFunction.cpp
+++ b/src/tools/SwitchingFunction.cpp
@@ -185,7 +185,7 @@ void SwitchingFunction::set(const std::string & definition,std::string& errormsg
 
   present=Tools::findKeyword(data,"D_MAX");
   if(present && !Tools::parse(data,"D_MAX",dmax)) errormsg="could not parse D_MAX";
-  dmax_2=dmax*dmax;
+  if(dmax<std::sqrt(std::numeric_limits<double>::max())) dmax_2=dmax*dmax;
   bool dostretch=false;
   Tools::parseFlag(data,"STRETCH",dostretch); // this is ignored now
   dostretch=true;

I would prefer this change since it can be backported to v2.2 which is still maintained.

Thanks again!

Giovanni

@tripiana
Copy link
Author

Yes of course. Give me a while and I'll test it.

@tripiana
Copy link
Author

@GiovanniBussi, patch applied, and compiled OK. I've sent a job. When it starts to run I'll see how it goes.

Best regards,

@tripiana
Copy link
Author

Job running, and working. Could you please apply this patch into the master (and any other branch needed)? Thanks!

@GiovanniBussi
Copy link
Member

Merged now. Thanks to you

Giovanni

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants