Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#1934 closed Bug (fixed)

Bug in diawri.F90:dia_wri() for kinetic energy (eken)

Reported by: pderian Owned by: nemo
Priority: low Milestone:
Component: OPA Version: release-3.6
Keywords: eken, output, kinetic energy Cc:
Severity: Workplan status:
Comments:

Description

Context

Experienced "Segmentation fault - invalid memory reference" crashes in diawri.F90:dia_wri() (with key_iomput) when trying to output kinetic energy (field id="eken").

Analysis

Looking at dia_wri(), there is these lines 297-299:

      IF ( iom_use("eken") ) THEN
         rke(:,:,jk) = 0._wp                               !      kinetic energy
         DO jk = 1, jpkm1
            ...

It is unclear why the "rke(:,:,jk) = 0._wp" assignment involves the jk variable in this context. The value of the later is not guaranteed and out-of-bound crash could occur?

Fix


Commenting said line 298 fixes the issue.

Commit History (2)

ChangesetAuthorTimeChangeLog
8465timgraham2017-08-25T10:34:47+02:00

#1934 and #1935 - correct calculation of KE in diawri.F90

8464timgraham2017-08-25T10:31:40+02:00

#1934 and #1935 - correct KE calculation in diawri.F90

Change History (3)

comment:1 Changed 3 months ago by Tim Graham

Coincidentally we were looking at this bit of code earlier this morning for another reason. The error you have seen is a bug but the suggested fix is not correct. Line 298 should be replaced with

         rke(:,:,jpk) = 0._wp                               !      kinetic energy

so that the bottom grid point is set to zero (this is because the loop at line 299 only goes to jpkm1. If this is not done then with some compilers invalid values will occur in the bottom grid cell and will cause an error in XIOS later and these errors are really hard to find.

The reason we were looking at the code is that the units suggest that there is a bug. I'll open another ticket for this though.

Last edited 3 months ago by Nicolas MARTIN (previous) (diff)

comment:2 Changed 3 months ago by pderian

I see; thanks Tim for the correct fix!

comment:3 Changed 3 months ago by Tim Graham

  • Resolution set to fixed
  • Status changed from new to closed

Fixed at r8464 of nemo_v3_6_stable and r8465 in the trunk along with another more serious issue in ticket #1935

Note: See TracTickets for help on using tickets.