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

Floating point exception in w3fld1md.F90 #1169

Closed
MatthewMasarik-NOAA opened this issue Jan 12, 2024 · 2 comments · Fixed by #1184
Closed

Floating point exception in w3fld1md.F90 #1169

MatthewMasarik-NOAA opened this issue Jan 12, 2024 · 2 comments · Fixed by #1184
Labels
bug Something isn't working

Comments

@MatthewMasarik-NOAA
Copy link
Collaborator

Describe the bug
Running a Debug build with additional flags captures a divide-by-zero floating point exception in w3fld1md.F90.

To Reproduce

  • Run grid option b from regtest ww3_ufs1.1/unstr
  • Ensure that WW3 builds in Debug cmake type, and additionally, appends these compile flags:
-fno-omit-frame-pointer -fsanitize=address

Expected behavior
forrtl: error (75): floating point exception due to a divide-by-zero occurring in a test condition parameter,

CRIT2=(ABS(TAUDIR-TAUDIRB)*100.0/(TAUDIR+TAUDIRB)*0.5) .GT. 0.1

within subroutine W3FLD1 of w3fld1md.F90. Here TAUDIR = -TAUDIRB, where the values are floating point approximations near Pi. See sample truncated with added write statement output:

  WAVEWATCH III calculating for 2019/12/01 06:36:00 UTC at 22:25:48     
  WAVEWATCH III calculating for 2019/12/01 06:48:00 UTC at 22:25:56     
  WAVEWATCH III calculating for 2019/12/01 07:00:00 UTC at 22:26:04     
  WAVEWATCH III calculating for 2019/12/01 07:12:00 UTC at 22:26:12     
   ******* !!! WARNING - TAUDIR:   3.141582                             
   ******* !!! WARNING - TAUDIRB:  -3.141582                            
  WAVEWATCH III calculating for 2019/12/01 07:24:00 UTC at 22:26:20     
  .                                                                     
  .                                                                     
  WAVEWATCH III calculating for 2019/12/01 10:00:00 UTC at 22:27:54     
   ******* !!! WARNING - TAUDIR:   3.141584                             
   ******* !!! WARNING - TAUDIRB:  -3.141584                            
  WAVEWATCH III calculating for 2019/12/01 10:12:00 UTC at 22:28:01     
  .                                                                     
  .                                                                     
  WAVEWATCH III reached the end of a computation loop at 22:29:12       
                                                                        
  Updating input at 2019/12/01 12:00:00 UTC                             
     Updating currents                                                  
     Updating winds                                                     
                                                                        
  WAVEWATCH III calculating for 2019/12/01 12:12:00 UTC at 22:29:12     
  .                                                                     
  .                                                                     
  WAVEWATCH III calculating for 2019/12/01 15:36:00 UTC at 22:31:09     
  WAVEWATCH III calculating for 2019/12/01 15:48:00 UTC at 22:31:16     
   ******* !!! WARNING - TAUDIR:  -3.141553                             
   ******* !!! WARNING - TAUDIRB:   3.141553                            
                                                                        
   ******* !!! WARNING - TAUDIR:  -3.141553                             
   ******* !!! WARNING - TAUDIRB:   3.141553                            
  WAVEWATCH III calculating for 2019/12/01 16:00:00 UTC at 22:31:23     
  WAVEWATCH III calculating for 2019/12/01 16:12:00 UTC at 22:31:29     
  WAVEWATCH III calculating for 2019/12/01 16:24:00 UTC at 22:31:37     
  WAVEWATCH III calculating for 2019/12/01 16:36:00 UTC at 22:31:43     
  .                                                                     
  .                                                                     
  WAVEWATCH III calculating for 2019/12/01 19:00:00 UTC at 22:33:04     
  WAVEWATCH III calculating for 2019/12/01 19:12:00 UTC at 22:33:11     
  WAVEWATCH III calculating for 2019/12/01 19:24:00 UTC at 22:33:18     
   ******* !!! WARNING - TAUDIR:  -3.141573                             
   ******* !!! WARNING - TAUDIRB:   3.141573                            
                                                                        
   ******* !!! WARNING - TAUDIR:   3.141589                             
   ******* !!! WARNING - TAUDIRB:  -3.141589                            
                                                                        
   ******* !!! WARNING - TAUDIR:   3.141589                             
   ******* !!! WARNING - TAUDIRB:  -3.141589                            
  WAVEWATCH III calculating for 2019/12/01 19:36:00 UTC at 22:33:25     
  WAVEWATCH III calculating for 2019/12/01 19:48:00 UTC at 22:33:32

I hit this error looking for a different issue, so I bypassed it with IF logic. It's just a mathematical bypass though -- I don't know what the science considerations are currently. I rationalized that in these cases, you have a finite number over zero, and taking the liberty to view that as a limit, as the denominator approaching zero, then the term approaches a very large number, and it only needs to be greater than 0.1, so assign it .true..

          IF ((TAUDIR+TAUDIRB).NE.0.) THEN                                               
              CRIT2=(ABS(TAUDIR-TAUDIRB)*100.0/(TAUDIR+TAUDIRB)*0.5) .GT. 0.1            
          ELSE                                                                           
              CRIT2=.TRUE.                                                               
          ENDIF    

Screenshots

 5 0x000000000040fd52 main()  ???:0                                                                            
 6 0x0000000000022555 __libc_start_main()  ???:0                                                               
 7 0x000000000040fc69 _start()  ???:0                                                                          
=================================                                                                              
forrtl: error (75): floating point exception                                                                   
Image              PC                Routine            Line        Source                                     
ww3_shel           0000000001569AFB  Unknown               Unknown  Unknown                                    
libpthread-2.17.s  00002BA86A224630  Unknown               Unknown  Unknown                                    
ww3_shel           00000000014A2996  w3fld1md_mp_w3fld         553  w3fld1md.F90                               
ww3_shel           00000000013FE610  w3srcemd_mp_w3src        2181  w3srcemd.F90                               
ww3_shel           0000000000E0404F  w3wavemd_mp_w3wav        2224  w3wavemd.F90                               
ww3_shel           00000000004737EA  MAIN__                   2573  ww3_shel.F90                               
ww3_shel           000000000040FD52  Unknown               Unknown  Unknown                                    
libc-2.17.so       00002BA86A453555  __libc_start_main     Unknown  Unknown                                    
ww3_shel           000000000040FC69  Unknown               Unknown  Unknown                                    
srun: error: h10c36: task 1355: Aborted (core dumped)                                                          
srun: launch/slurm: _step_signal: Terminating StepId=53400451.0                                                
slurmstepd: error: *** STEP 53400451.0 ON h3c08 CANCELLED AT 2023-12-27T14:40:05 ***

Additional context
Fyi, this new issue #1159 also has floating point divide by zero. It's in a different subroutine, but same module, W3FLD1MD. The related pr #1163.

@MatthewMasarik-NOAA MatthewMasarik-NOAA added the bug Something isn't working label Jan 12, 2024
@mickaelaccensi
Copy link
Collaborator

good catch Matthew. The solution seems acceptable

@JessicaMeixner-NOAA
Copy link
Collaborator

FYI @breichl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants