NCAR / MOM6

NCAR/CESM fork of the Modular Ocean Model v.6 (MOM6)
Other
2 stars 18 forks source link

Axis and Field labels not allocated properly when appended to IO handle lists. #261

Closed alperaltuntas closed 8 months ago

alperaltuntas commented 8 months ago

When running MOM6 in DEBUG mode with the intel compiler, we get the following error:

forrtl: severe (408): fort: (8): Attempt to fetch from allocatable variable LABEL when it is not allocated

Upon closer look, it seems that the issue results from the way register_axis_nc and register_netcdf_axis work. The register_axis_nc function acts as a wrapper for the register_netcdf_axis function. While register_axis_nc sets the axis%label member, the latter function does not. When register_axis_nc appends a copy of the provided axis to the handle%axes list, this appended copy lacks an allocated and assigned %label member, as it is constructed through the register_netcdf_axis function. Consequently, when the %get method is invoked to retrieve an axis instance, the returned axis does not possess an allocated and assigned label member.

This issue applies to the field instances as well, since register_field_nc and register_netcdf_field functions exhibit the same behavior.

This may be one of (many?) issues contributing to the recent memory-related issues.

I am currently testing a fix and will follow up with a PR.

marshallward commented 8 months ago

Thanks for working out the problem, Alper. Leaving axis%label (and field%label) unset on the netcdf side seems rather disastrous; I'm sorry for any headaches this may have caused. I think we never saw this because we do everything through the get_netcdf_fields mega-function, which does set those labels.

I guess the simplest fix is to also set %label in ~register_field_nc and register_axis_nc~? (Ed: see below)

alperaltuntas commented 8 months ago

I guess the simplest fix is to also set %label in register_field_nc and register_axis_nc?

Actually, I thought It would be better to set %label in register_netcdf_axis and register_netcdf_field instead, since those functions construct the axis and field instances. Would that be okay?

marshallward commented 8 months ago

Sorry, I mistyped, I agree with what you wrote :sweat_smile:

marshallward commented 8 months ago

Oh, just to clarify, the axis%label = label still needs to exist in register_axis_nc. This is actually a MOM_axis, rather than a netcdf_axis. The issue that you identified is that the label in netcdf_axis was never set! (Except in the kooky case of get_netcdf_fields.)