Skip to content

CI: pushing existing workflows down to 'develop' branch - #72

Open
cenamiller wants to merge 34 commits into
masterfrom
develop
Open

CI: pushing existing workflows down to 'develop' branch#72
cenamiller wants to merge 34 commits into
masterfrom
develop

Conversation

@cenamiller

Copy link
Copy Markdown
Collaborator

The development process on the NCAR/MPAS-Model-CI branch looked different than on the main MPAS-Dev/MPAS-Model repository, because of the need for the CI files to exist on the default 'master' branch. This means that instead of changes being pushed from develop -> master, in this case I need to push the changes on 'master' -> 'develop'. If the files exist on 'develop', I can test the new changes on the MPAS-Dev/MPAS-Model 'develop' branch when I sync my fork.

mgduda and others added 30 commits April 16, 2026 15:17
This merge introduces fixes from MPAS v8.4.0, and it connects the v8.4.0 tag to
future commits on 'develop'.

* master:
  Fix premature use of optional argument in mpas_get_stream_filename
  Update config_init_case Registry.xml description to include LES case
  Fix snow initialization over seaice points in MPAS-A
  Fix segfault when CAM radiation is activated in MPAS-Atmosphere
  Fix calls to mpas_halo_exch_group_full_halo_exch in mpas_halo_testing
  Update version number to 8.4.0
  fix the q2 diagnostics in NoahMP
…sphere core

The processing of GOCART-based water- and ice-friendly aerosols in the
init_atmosphere core currently supports only the aerosol-aware Thompson
microphysics scheme, but planned additions to MPAS-Atmosphere (specifically,
the TEMPO microphysics scheme) will make use of these same aerosol fields.
Accordingly, this commit generalizes the name of the 'mp_thompson_aers_in'
package to 'microphysics_aerosols' in the init_atmosphere core.
In the `mpas_io` module, the `MPAS_io_inq_var` subroutine allocates the `dimnames` array and returns it to a calling routine.
In this case, the calling routine is `MPAS_io_def_var`, which has a local pointer array, `inq_dimnames`, that corresponds to
the allocated `dimnames` and must be deallocated before this routine returns.

Direct leak of 152576 byte(s) in 162 object(s) allocated from:
    #0 0x7fe7202ef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x0000024709b7 in __mpas_io_MOD_mpas_io_inq_var /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io.F:1123
    #2 0x000002468a5b in __mpas_io_MOD_mpas_io_def_var /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io.F:1222
    #3 0x000002613e0a in __mpas_io_streams_MOD_mpas_streamaddfield_generic /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io_streams.F:1761
    #4 0x000002639406 in __mpas_io_streams_MOD_mpas_streamaddfield_1dreal /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io_streams.F:959
    #5 0x0000024a69fa in build_stream /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:4363
    #6 0x0000024b13d7 in write_stream /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:3251
    #7 0x0000024b6afd in __mpas_stream_manager_MOD_mpas_stream_mgr_write /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:2858
    #8 0x00000094afb5 in __atm_core_MOD_atm_core_run /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/core_atmosphere/mpas_atm_core.F:620
    #9 0x000000406341 in __mpas_subdriver_MOD_mpas_run /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:416
    #10 0x000000402942 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:20
    #11 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #12 0x7fe71f208680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #13 0x7fe71f208797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #14 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: c0332077ce07f118fef380e98497523209704432)
This one was difficult to find. Backtrace, for some reason, did not point to
the exact locations in the source code where subroutine calls are located.

In `mpas_stream_list.F` in the `MPAS_stream_list_create` subroutine,
memory is allocated for `list` pointer. This routine is called from
MPAS_stream_mgr_add_alarmat line 1271 and stored in new_alarm % streamList.
The new_alarm itself is allocated a few lines before (1269), and inserted
into manager % alarms_in at line 1279:

1266                ! If alarm is not already defined, we need to create a new alarm node
1267                nullify(new_alarm)
1268                if (.not. MPAS_stream_list_query(manager % alarms_in, alarmID, new_alarm, ierr=err_local)) then
1269                    allocate(new_alarm)
1270                    new_alarm % name = alarmID
1271                    call MPAS_stream_list_create(new_alarm % streamList, ierr=err_local)
1272                    if (err_local /= MPAS_STREAM_LIST_NOERR) then
1273                        if (present(ierr)) ierr = MPAS_STREAM_MGR_ERROR
1274                        STREAM_ERROR_WRITE('Problems while creating stream list for alarm')
1275                        return
1276                    end if
1277                    nullify(new_alarm % next)
1278
1279                    call MPAS_stream_list_insert(manager % alarms_in, new_alarm, ierr=err_local)
1280                    if (err_local /= MPAS_STREAM_LIST_NOERR) then
1281                        if (present(ierr)) ierr = MPAS_STREAM_MGR_ERROR
1282                        STREAM_ERROR_WRITE('Problems while adding input alarm to list')
1283                        return
1284                    end if
1285                end if

Similar actions are taken for manager % alarms_out. To prevent memory leaks,
before freeing up the list of input/output alarms we must first destroy the list
of "sub" alarms added to these two lists (manager % alarms_in and manager % alarms_out)
in MPAS_stream_mgr_finalize.

Direct leak of 15456 byte(s) in 7 object(s) allocated from:
    #0 0x7f59c3eef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x000002580ef6 in __mpas_stream_list_MOD_mpas_stream_list_create /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_list.F:38
    #2 0x0000024c7397 in __mpas_stream_manager_MOD_mpas_stream_mgr_add_alarm /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:1242
    #3 0x0000024d6bd7 in stream_mgr_add_alarm_c /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:6198
    #4 0x0000024fc7c1 in xml_stream_parser /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/xml_stream_parser.c:1348
    #5 0x00000040c916 in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:42
    #6 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #7 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #8 0x7f59c2e08680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #9 0x7f59c2e08797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #10 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: 3a2362d27fd37ec758776277d1ca8e2b27dea473)
Memory is allocated in `read_and_broadcast` function in stream_inquiry.c
and its address returned to `parse_streams_file` via `xml_buf` pointer.
This pointer is then passed to `ezxml_parse_str` function, but it is never
freed in `parse_streams_file` nor returned to the function that called
`parse_streams_file`. This means the ownership of the memory that xml_buf
points to is transferred to ezxml_parse_str. It is responsible for freeing
that memory.
In `ezxml_parse_str` the pointer to that memory buffer (char *s) is saved
in `root->m` so that it can be freed later in `ezxml_free()`. To indicate
that root->m should be freed, root->len must be set to -1.
This is how it's done in other functions.

Direct leak of 2915 byte(s) in 1 object(s) allocated from:
    #0 0x7f329f6ef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x0000024ff074 in read_and_broadcast /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/stream_inquiry.c:83
    #2 0x0000024ff2da in parse_streams_file /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/stream_inquiry.c:146
    #3 0x000002489642 in __mpas_stream_inquiry_MOD_streaminfo_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_inquiry.F:137
    #4 0x000000409cad in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:267
    #5 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #6 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #7 0x7f329e408680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #8 0x7f329e408797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #9 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: ab61abfcc5d576737ec24283b11ac29c6cd28819)
In `MPAS_io_put_att_text` (and also in other *_io_put_att_*) subroutine `new_attlist_node`
is allocated and added as a variable attribute to a field (if fieldname is present) or as
a global attribute to a handle. It should be deleted in `MPAS_io_close`.

Direct leak of 2592 byte(s) in 162 object(s) allocated from:
    #0 0x7fd0fbaef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x0000023be0e0 in __mpas_io_MOD_mpas_io_put_att_text /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io.F:6066
    #2 0x000002581ccd in __mpas_io_streams_MOD_put_get_field_atts /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io_streams.F:4341
    #3 0x00000263a195 in __mpas_io_streams_MOD_mpas_streamaddfield_1dreal /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io_streams.F:976
    #4 0x0000024a6aac in build_stream /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:4389
    #5 0x0000024b1489 in write_stream /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:3277
    #6 0x0000024b6baf in __mpas_stream_manager_MOD_mpas_stream_mgr_write /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:2884
    #7 0x00000094df25 in __atm_core_MOD_atm_core_run /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/core_atmosphere/mpas_atm_core.F:754
    #8 0x000000406341 in __mpas_subdriver_MOD_mpas_run /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:416
    #9 0x000000402942 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:20
    #10 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #11 0x7fd0fa808680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #12 0x7fd0fa808797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #13 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: d86a2755908f751ab1aef6095ced60ba65202ab8)
In all subroutines that add a new field to a pool, like `mpas_pool_add_field_2d_real`
in this case, a new mpas_pool_member_type is allocated, with `allocate(newmem)`,
and then a `mpas_pool_data_type` is allocated as a `data` component of newmem,
with `allocate(newmem % data)`.

When pool members are deallocated (in `pool_remove_member`) before deallocating the
pointer that points to a pool member type, a pool data type component must also be deallocated.

Direct leak of 1056 byte(s) in 1 object(s) allocated from:
    #0 0x7f94afcef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x0000021f2834 in __mpas_pool_routines_MOD_mpas_pool_add_field_2d_real /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_pool_routines.F:2215
    #2 0x0000023af006 in __mpas_halo_MOD_mpas_halo_exch_group_add_field /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_halo.F:511
    #3 0x000000964b6b in __mpas_atm_halos_MOD_atm_build_halo_groups /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/core_atmosphere/mpas_atm_halos.F:191
    #4 0x00000095a6f8 in __atm_core_MOD_atm_core_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/core_atmosphere/mpas_atm_core.F:103
    #5 0x00000040ce79 in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:394
    #6 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #7 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #8 0x7f94aec08680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #9 0x7f94aec08797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #10 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: 1c56ff6f6b8a8860cf4bb09f1474a7cfce529289)
The `dminfo` component of the `dom` object is allocated twice, first in `mpas_allocate_domain`
and then in `mpas_framework_init_phase1`. It is never deallocated. The second allocation is
unnecessary and should be removed. The deallocation should be added to `mpas_deallocate_domain`.

Also, `mpas_deallocate_domain` is called too early in `mpas_framework_finalize`, it should be
called after calls to `mpas_dmpar_finalize` and `mpas_finish_block_proc_list`.

In fact I think `mpas_deallocate_domain` should not be called at all from `mpas_framework_finalize`,
but from the module that called `mpas_allocate_domain`, which is `mpas_subdriver`.

Direct leak of 160 byte(s) in 1 object(s) allocated from:
    #0 0x7f8370cef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x00000215d335 in __mpas_domain_routines_MOD_mpas_allocate_domain /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_domain_routines.F:46
    #2 0x00000040908c in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:194
    #3 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #4 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #5 0x7f836fa08680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #6 0x7f836fa08797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #7 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: e8ced93cd7d700e184ed309fa9f3c945cd2d3e8a)

Direct leak of 160 byte(s) in 1 object(s) allocated from:
    #0 0x7f8370cef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x00000236c37d in __mpas_framework_MOD_mpas_framework_init_phase1 /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_framework.F:68
    #2 0x000000409131 in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:202
    #3 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #4 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #5 0x7f836fa08680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #6 0x7f836fa08797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #7 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: e8ced93cd7d700e184ed309fa9f3c945cd2d3e8a)
In `mpas_domain_routines.F` several pool objects which are components of the domain
and block structure are allocated explicitly in `mpas_allocate_domain` and
`mpas_allocate_block` and then again in `mpas_pool_create_pool` subroutiens called
from these two functions.

To avoid memory leaks the explicit allocations should be removed.

Direct leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0x7f5ba74ef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x00000215d0f0 in __mpas_domain_routines_MOD_mpas_allocate_block /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_domain_routines.F:91
    #2 0x000002529bfd in __mpas_block_creator_MOD_mpas_block_creator_finalize_block_phase1 /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_block_creator.F:1017
    #3 0x000002158a90 in __mpas_bootstrapping_MOD_mpas_bootstrap_framework_phase1 /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_bootstrapping.F:385
    #4 0x00000040c49c in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:356
    #5 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #6 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #7 0x7f5ba6208680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #8 0x7f5ba6208797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #9 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: f25761ad95db227da9a5bcfb5c7400f929e4a29e)

Direct leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0x7f5ba74ef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x00000215dafc in __mpas_domain_routines_MOD_mpas_allocate_domain /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_domain_routines.F:50
    #2 0x00000040908c in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:194
    #3 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #4 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #5 0x7f5ba6208680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #6 0x7f5ba6208797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #7 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: f25761ad95db227da9a5bcfb5c7400f929e4a29e)
In `xml_stream_parser` function there is this block of code:

            packages = strdup(packagelist);
            package = strsep(&packages, ";");
            ... // more calls to strsep
            free(packages);

Here, `strdup` allocates memory for a copy of `packagelist` and saves a pointer
to that memory block in `packages`, which is later used in `free`.
However, the `strsep` function modifies that pointer by advancing it through
the allocated memory as it parses the string. It eventually returns NULL,
which caused free to fail to deallocate memory.

Solution is simply to keep a copy of the original pointer and use it to free the allocated memory.

Direct leak of 58 byte(s) in 5 object(s) allocated from:
    #0 0x7fcf6c6e8ac4 in strdup (/lib64/libasan.so.8+0xe8ac4) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x0000024fc518 in xml_stream_parser /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/xml_stream_parser.c:1381
    #2 0x00000040c916 in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:42
    #3 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #4 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #5 0x7fcf6b608680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #6 0x7fcf6b608797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #7 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: 66ceb08b660eaf75bed2d3da86b4743a3541832e)
These two leaks are similar. In `MPAS_io_inq_dim` new dimlist_type node is
allocated (line 594), in `MPAS_io_inq_var` new fieldlist_type node is allocated (line 860).

They must be deallocated in `MPAS_io_close`

Direct leak of 48 byte(s) in 3 object(s) allocated from:
    #0 0x7fcf4c0ef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x000002472c16 in __mpas_io_MOD_mpas_io_inq_dim /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io.F:594
    #2 0x00000214f5ad in __mpas_bootstrapping_MOD_mpas_bootstrap_framework_phase2 /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_bootstrapping.F:612
    #3 0x00000040cdd6 in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:389
    #4 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #5 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #6 0x7fcf4ae08680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #7 0x7fcf4ae08797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #8 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: 002a28b14293b75e2eca1ab9aeac8be59516cd63)

Direct leak of 32 byte(s) in 2 object(s) allocated from:
    #0 0x7fcf4c0ef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x00000246bba9 in __mpas_io_MOD_mpas_io_inq_var /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io.F:860
    #2 0x000002650ba8 in __mpas_io_streams_MOD_mpas_seekstream /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io_streams.F:339
    #3 0x0000024b2409 in write_stream /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:3353
    #4 0x0000024b640d in __mpas_stream_manager_MOD_mpas_stream_mgr_write /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:2884
    #5 0x00000094df25 in __atm_core_MOD_atm_core_run /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/core_atmosphere/mpas_atm_core.F:754
    #6 0x000000406341 in __mpas_subdriver_MOD_mpas_run /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:416
    #7 0x000000402942 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:20
    #8 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #9 0x7fcf4ae08680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #10 0x7fcf4ae08797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #11 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: 002a28b14293b75e2eca1ab9aeac8be59516cd63)
In `mpas_dmpar_init_multihalo_exchange_list` subrotine called from mpas_block_creator.F
exchList is allocated. The exchLists has halo components, which are also exchLists.
These are passed back to mpas_block_creator and are eventually saved into the block's
exchange lists: cellsToSend, cellsToRecv, cellsToCopy, edgesToSend, edgesToRecv,
verticesToSend, verticesToRecv and verticesToCopy.

When these lists are deallocated in `mpas_deallocate_block`, instead of just deallocating
exchList pointers, a subroutine `mpas_dmpar_destroy_mulithalo_exchange_list` should be
used to properly destroy and deallocate halo subcomponents.

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7fdff4aef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x0000022ce9d8 in __mpas_dmpar_MOD_mpas_dmpar_init_multihalo_exchange_list /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_dmpar.F:6466
    #2 0x0000025501f4 in __mpas_block_creator_MOD_mpas_block_creator_build_0_and_1halo_edge_fields /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_block_creator.F:334
    #3 0x000002156ba9 in __mpas_bootstrapping_MOD_mpas_bootstrap_framework_phase1 /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_bootstrapping.F:266
    #4 0x00000040c49c in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:356
    #5 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #6 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #7 0x7fdff3808680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #8 0x7fdff3808797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #9 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: 94eaf12a29734d8a2ed692e6fb9b037dcf35135f)
In `mpas_pool_add_package` subroutine which adds a package to a pool, after the
new pool member is allocated, the data subcomponent is allocated, which also
allocates the logical value `simple_logical`.

That value must be deallocated before the data pointer (dptr) is deallocated in `mpas_pool_destroy_pool`.

Direct leak of 20 byte(s) in 5 object(s) allocated from:
    #0 0x7f85b0cef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x0000021bfb89 in __mpas_pool_routines_MOD_mpas_pool_add_package /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_pool_routines.F:5207
    #2 0x0000024baa91 in __mpas_stream_manager_MOD_mpas_stream_mgr_add_pkg /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:2297
    #3 0x0000024d68ba in stream_mgr_add_pkg_c /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_stream_manager.F:6321
    #4 0x0000024fbede in xml_stream_parser /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/xml_stream_parser.c:1385
    #5 0x00000040c916 in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:42
    #6 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #7 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #8 0x7f85afc08680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #9 0x7f85afc08797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: f83cdcaffde35587075ea80e05bcb894963a4bdd)
    #10 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: bec3816af189fbcb144ed6ff0cbaef36c9dc9016)
In `mpas_block_creator_build_0halo_cell_fields` local array `sendingHaloLayers`
must be deallocated before this subrotine returns

Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x7fb58d2ef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x0000025538dc in __mpas_block_creator_MOD_mpas_block_creator_build_0halo_cell_fields /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_block_creator.F:160
    #2 0x000002156b05 in __mpas_bootstrapping_MOD_mpas_bootstrap_framework_phase1 /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_bootstrapping.F:259
    #3 0x00000040c49c in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:356
    #4 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #5 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #6 0x7fb58c008680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: 79bea8ccf296ed42137a854a0cb75020bb783545)
    #7 0x7fb58c008797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: 79bea8ccf296ed42137a854a0cb75020bb783545)
    #8 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: 62d0976668433575208c249f3d706b6b133aa425)
In `atm_setup_derived_dimensions` subroutine dimension values are allocated
locally if they are not already in a dimensionPool, and they must be deleted after
being added to the dimensionPool.

Since this is a generated routine, the changes must be made in src/tools/registry/gen_inc.c

Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x7fa3a06ef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x0000008e638a in __atm_core_interface_MOD_atm_setup_derived_dimensions /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/src/core_atmosphere/block_dimension_routines.inc:171
    #2 0x00000251c432 in __mpas_block_creator_MOD_mpas_block_creator_finalize_block_phase2 /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_block_creator.F:1275
    #3 0x000002151669 in __mpas_bootstrapping_MOD_mpas_bootstrap_framework_phase2 /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_bootstrapping.F:675
    #4 0x00000040cdd6 in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:389
    #5 0x000000402934 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #6 0x0000004029b2 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #7 0x7fa39f608680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: 79bea8ccf296ed42137a854a0cb75020bb783545)
    #8 0x7fa39f608797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: 79bea8ccf296ed42137a854a0cb75020bb783545)
    #9 0x000000402844 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x402844) (BuildId: 66c1f6616f19ebcc31fb59115fab767050354512)
In `MPAS_io_init` it is not necessary to allocate `ioContext % smiol_context`, it will be allocated in `SMIOLf_init`

Direct leak of 28 byte(s) in 1 object(s) allocated from:
    #0 0x7f6c6e4ef41f in malloc (/lib64/libasan.so.8+0xef41f) (BuildId: 2a7b18228484f7c17d959b022f3ff6aaaf687b3c)
    #1 0x00000242e24c in __mpas_io_MOD_mpas_io_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_io.F:213
    #2 0x00000236bff6 in __mpas_framework_MOD_mpas_framework_init_phase2 /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/framework/mpas_framework.F:155
    #3 0x000000408f59 in __mpas_subdriver_MOD_mpas_init /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas_subdriver.F:257
    #4 0x000000401fb4 in mpas /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:18
    #5 0x000000402032 in main /home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/src/driver/mpas.F:10
    #6 0x7f6c6d408680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: 79bea8ccf296ed42137a854a0cb75020bb783545)
    #7 0x7f6c6d408797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: 79bea8ccf296ed42137a854a0cb75020bb783545)
    #8 0x000000401ec4 in _start (/home/dusan/sufs/simple-mpas/src/MPAS-Model-develop/build/bin/mpas_atmosphere+0x401ec4) (BuildId: 4e38fd7d901cf1506c34e3522552d885e5afaebd)
… (PR MPAS-Dev#1449)

This merge generalizes the name of the 'mp_thompson_aers_in' package in the
init_atmosphere core.

The processing of GOCART-based water- and ice-friendly aerosols in the
init_atmosphere core currently supports only the aerosol-aware Thompson
microphysics scheme, but planned additions to MPAS-Atmosphere (specifically,
the TEMPO microphysics scheme) will make use of these same aerosol fields.
Accordingly, this merge generalizes the name of the 'mp_thompson_aers_in'
package to 'microphysics_aerosols' in the init_atmosphere core.

* atmosphere/generalize_mp_aerosols_package:
  Generalize the name of the 'mp_thompson_aers_in' package in init_atmosphere core
This commit adds default initialization for the members of the met_data derived
type in the init_atm_read_met module. Without well-defined values for some
members, unpredictable floating-point exceptions were possible, e.g.,

  Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.

  Backtrace for this error:
  #0  0x15494ec288ff in ???
  #1  0x59ddc0 in __init_atm_read_met_MOD_read_next_met_field
        at src/core_init_atmosphere/mpas_init_atm_read_met.F:388
  #2  0x4ccb7a in __init_atm_cases_MOD_init_atm_case_lbc
        at src/core_init_atmosphere/mpas_init_atm_cases.F:6218
  #3  0x58a373 in __init_atm_cases_MOD_init_atm_setup_case
        at src/core_init_atmosphere/mpas_init_atm_cases.F:327
  #4  0x497807 in __init_atm_core_MOD_init_atm_core_run
        at src/core_init_atmosphere/mpas_init_atm_core.F:92
  #5  0x406084 in __mpas_subdriver_MOD_mpas_run
        at src/driver/mpas_subdriver.F:416
  #6  0x4046da in mpas
        at src/driver/mpas.F:20
  #7  0x404745 in main
        at src/driver/mpas.F:10

By initializing the members of the met_data type, these unpredictable errors can
be avoided.
This merge fixes small memory leaks in various parts of the model, mostly within
the framework. When the model was compiled with the address sanitizer compiler
flag, hundreds of memory leaks were reported. All of them are located in the
code executed during initialization, and they do not contribute to ever
increasing memory consumption during model execution. Nonetheless, addressing
these leaks cleans up the address sanitizer report, making it easier to spot
other memory leaks.

* dev_fix_mem_leaks:
  Fix memory leak in mpas_io.F
  Fix memory leak in block_dimension_routines.inc
  Fix memory leak in mpas_block_creator.F
  Fix memory leak in mpas_pool_routines.F
  Fix memory leak in mpas_domain_routines.F
  Fix memory leak in mpas_io.F
  Fix memory leak in xml_stream_parser
  Fix memory leak in mpas_domain_routines.F
  Fix memory leak in mpas_framework.F and mpas_domain_routines.F
  Fix memory leak in mpas_pool_routines.F
  Fix memory leak in mpas_io.F
  Fix memory leak in stream_inquiry.c
  Fix memory leak in mpas_stream_manager.F
  Fix memory leak in mpas_io.F
…PAS-Dev#1453)

This merge adds default initialization for the members of the met_data derived
type in the init_atm_read_met module. Without well-defined values for some
members, unpredictable floating-point exceptions were possible, e.g.,

  Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.

  Backtrace for this error:
  #0  0x15494ec288ff in ???
  #1  0x59ddc0 in __init_atm_read_met_MOD_read_next_met_field
        at src/core_init_atmosphere/mpas_init_atm_read_met.F:388
  #2  0x4ccb7a in __init_atm_cases_MOD_init_atm_case_lbc
        at src/core_init_atmosphere/mpas_init_atm_cases.F:6218
  #3  0x58a373 in __init_atm_cases_MOD_init_atm_setup_case
        at src/core_init_atmosphere/mpas_init_atm_cases.F:327
  #4  0x497807 in __init_atm_core_MOD_init_atm_core_run
        at src/core_init_atmosphere/mpas_init_atm_core.F:92
  #5  0x406084 in __mpas_subdriver_MOD_mpas_run
        at src/driver/mpas_subdriver.F:416
  #6  0x4046da in mpas
        at src/driver/mpas.F:20
  #7  0x404745 in main
        at src/driver/mpas.F:10

By initializing the members of the met_data type, these unpredictable errors can
be avoided.

* init_atmosphere/met_data_default_init:
  Provide default initialization for members of the met_data derived type
The previous commit (ae45a18) aimed to fix memory leaks that occurred while
setting up derived dimensions by deallocating dimensions after they were
allocated and added to the dimension pool (since the pool assigns the value of
the dimension to its own internal memory, it is up to calling code to free any
memory allocated for the dimension argument to mpas_pool_add_dimension).
However, any later derived dimensions that depended on a dimension whose value
came from a namelist or other registry definiton would generate a segmentation
fault after referencing an unassociated pointer to the now deallocated
dimension.

For example, in the init_atmosphere core, the 'nVertLevels' dimension is set
based on the namelist option 'config_nvertlevels', and the 'nVertLevelsP1'
dimension is subsequently set to 'nVertLevels+1'.

This commit fixes this issue by re-setting pointers to point to pool-owned
memory after a dimension has been allocated, added to the dimension pool, and
freed.
…utines.inc

The parse_dimensions_from_registry C code in the registry is responsible for
generating the block_dimension_routines.inc file, and this commit makes changes
in parse_dimensions_from_registry to clean up whitespace / indentation issues in
the generated Fortran code. The changes in this commit otherwise have no impact
on results.
…PAS-Dev#1458)

This merge fixes a bug in registry-generated code for setting up derived
dimensions.

Previous work (in PR MPAS-Dev#1451, commit ae45a18) introduced changes to eliminate
memory leaks that occurred while setting up derived dimensions in the
registry-generated 'block_dimension_routines.inc' code. The approach taken in
that work involved deallocating dimensions after they were allocated and added
to the dimension pool, since the pool assigns the value of the dimension to its
own internal memory, and it is up to calling code to free any memory allocated
for the dimension argument to 'mpas_pool_add_dimension'. However, as an
unintended side effect, any later derived dimensions that depended on a
dimension whose value came from a namelist or other registry definition would
generate a segmentation fault after referencing an unassociated pointer to the
now deallocated dimension.

For example, in the init_atmosphere core, the 'nVertLevels' dimension is set
based on the namelist option 'config_nvertlevels', and the 'nVertLevelsP1'
dimension is subsequently set to 'nVertLevels+1'.

This merge fixes this issue by re-setting pointers to point to pool-owned memory
after a dimension has been allocated, added to the dimension pool, and freed.

Additionally, this merge fixes up the indentation in the registry-generated
code in 'block_dimension_routines.inc'.
…_function

Adding a dm_info object allows a core's package setup function to make use of
MPI when setting up packages. For example, a core may read data from a file only
on MPI rank 0 and broadcast the resulting values to other MPI ranks rather than
having each MPI rank independently open and read the file.

In addition to updating the mpas_setup_packages_function abstract interface in
mpas_core_types.inc with an additional 'dminfo' argument, this commit updates
the call to domain_ptr % core % setup_packages in mpas_init to include the
dminfo argument, and it also updates the *_setup_packages functions in each
core's interface module.
)

This merge adds a 'dm_info' object to the argument list of the
'mpas_setup_packages_function' core interface function. Adding a 'dm_info'
object allows a core's package setup function to make use of MPI when setting up
packages. For example, a core may read data from a file only on MPI rank 0 and
broadcast the resulting values to other MPI ranks rather than having each MPI
rank independently open and read the file.

In addition to updating the 'mpas_setup_packages_function' abstract interface in
'mpas_core_types.inc' with an additional 'dminfo' argument, this merge updates
the call to 'domain_ptr % core % setup_packages' in 'mpas_init' to include the
'dminfo' argument, and it also updates the '*_setup_packages' functions in each
core's interface module.
…module

This commit adds a new private subroutine, mpas_split_string_new, to the
init_atm_core_interface module. The purpose of this subroutine is essentially
the same as the mpas_split_string routine in the mpas_string_utils module, but
the maximum length of any substring does not need to be assumed in
mpas_split_string_new, whereas the mpas_split_string subroutine requires the
caller to declare a pointer to an array of strings of a specific length.
Eventually, this routine could be migrated to mpas_string_utils and used as a
replacement for mpas_split_string.
This commit defines new packages for hydrometeors, one package per hydrometeor,
in the init_atmosphere core, and it provides two means of activating these
packages.

1) If the new namelist option config_active_hydrometeors is set to
   'detect_automatically', packages will be set up by scanning through the
   fields in the initial intermediate file, with packages being activated only
   for those hydrometeors that are present in the file.

2) Alternatively, and to avoid the need to scan through all fields in the
   initial intermediate file, config_active_hydrometeors may be set to a
   semicolon-separated list of zero or more hydrometeor names (e.g., 'qc;qr').
   Packages for those specified hydrometeors will be active, and the packages
   for all unspecified hydrometeors will be inactive.

A new subroutine, setup_hydrometeor_packages, handles the details of the
hydrometeor package setup, and this routine is called from
init_atm_setup_packages only if config_init_case is 7 or 9, and if met_stage_out
is true.
This merge introduces fixes from MPAS v8.4.1, and it connects the v8.4.1 tag to
future commits on 'develop'.

* master:
  Atmosphere core allocates surface arrays based on sfclay choice not PBL choice
  Fix broken builds with GEN_F90=true by adding missing include paths to Makefiles
  This commit mirrors a similar commit in MONAN. It fixes a cryptic bug that ...
  Limit the saturation vapor pressure e_s used in the Kessler microphysics
  Avoid implicit save attribute during variable declaration in atm_srk3
  Add missing dummy argument intent in atm_compute_dyn_tend
  Fix Fortran standard violation due to undefined pointer actual argument in atm_srk3
  Check for duplicate namelist options in active_when attributes
  Update version number to 8.4.1
…PAS-Dev#1467)

This merge defines new packages for hydrometeors, one package per hydrometeor,
in the init_atmosphere core, and it provides two means of activating these
packages.

 1. If the new namelist option 'config_active_hydrometeors' is set to
    'detect_automatically', packages will be set up by scanning through the
    fields in the initial intermediate file, with packages being activated only
    for those hydrometeors that are present in the file.

 2. Alternatively, and to avoid the need to scan through all fields in the
    initial intermediate file, 'config_active_hydrometeors' may be set to to a
    semicolon-separated list of zero or more hydrometeor names (e.g., 'qc;qr').
    Packages for those specified hydrometeors will be active, and the packages
    for all unspecified hydrometeors will be inactive.

A new subroutine, 'setup_hydrometeor_packages', handles the details of the
hydrometeor package setup, and this routine is called from
'init_atm_setup_packages' only if 'config_init_case' is 7 or 9, and if
'met_stage_out' is true.

* init_atmosphere/hydrometeor_packages:
  Apply packages to individual hydrometeors in the init_atmosphere core
  Add new routine mpas_split_string_new to the init_atm_core_interface module
…ex strings

When the 'pattern' argument to the check_regex_match function in
regex_matching.c is not a regular expression, a simple string comparison is
sufficient and the cost of compiling a regular expression can be avoided. This
commit adds an optimized code path in the check_regex_match function for this
case.

Thanks to Yu-Tze Hong (@aspenhong) and Ying-Jhang Wu (@yjwu890355) from the
Central Weather Administration (CWA), Taipei, Taiwan, for identifying this
opportunity for optimization and for providing an initial version of these code
changes.
mgduda and others added 3 commits June 11, 2026 13:30
…ev#1466)

This merge provides an optimized code path in the check_regex_match function for
non-regex strings. When the pattern argument to the check_regex_match function
in regex_matching.c is not a regular expression, a simple string comparison is
sufficient and the cost of compiling a regular expression can be avoided.

Thanks to Yu-Tze Hong (@aspenhong) and Ying-Jhang Wu (@yjwu890355) from the
Central Weather Administration (CWA), Taipei, Taiwan, for identifying this
opportunity for optimization and for providing an initial version of these code
changes.

* framework/optimize_regex_match:
  Add documentation for the check_regex_match function in regex_matching.c
  Provide optimized code path in check_regex_match function for non-regex strings
Copilot AI review requested due to automatic review settings July 22, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates MPAS framework/core code to improve memory/resource cleanup, extend the core package setup interface to pass dminfo, and adds init_atmosphere logic/configuration for selectively activating hydrometeor packages (qc/qr) based on a namelist option or automatic detection from intermediate files.

Changes:

  • Extend setup_packages core-interface signatures to accept dminfo and update the driver/callers accordingly.
  • Fix multiple memory/resource management issues (Fortran deallocations, pool member removal cleanup, C string ownership/freeing).
  • Add init_atmosphere hydrometeor package activation (config_active_hydrometeors) plus Registry updates (packages/vars/options).

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/tools/registry/gen_inc.c Adjust generated Fortran dimension assignment to re-point dimension pointers to pool memory (and tweak logging indentation).
src/framework/xml_stream_parser.c Fix strsep()/free() ownership by preserving the original strdup() pointer.
src/framework/regex_matching.c Add fast-path for non-regex patterns; improve matching documentation/comments.
src/framework/mpas_stream_manager.F Ensure per-alarm streamList items are destroyed before destroying the alarms lists.
src/framework/mpas_pool_routines.F Improve pool cleanup: handle package data in pool destroy; deallocate ptr % data when removing pool members.
src/framework/mpas_io.F Fix deallocation leaks in close paths; adjust SMIOL init usage; clean up temporary allocations.
src/framework/mpas_framework.F Remove dminfo allocation in init phase1; reorder finalize to deallocate domain after other finalization steps.
src/framework/mpas_domain_routines.F Remove redundant allocations (configs/packages/struct pools created via pool routines); add dminfo deallocation; use dmpar exchange-list destroy helpers.
src/framework/mpas_core_types.inc Extend mpas_setup_packages_function abstract interface to include dminfo.
src/framework/mpas_block_creator.F Deallocate sendingHaloLayers after use to avoid leaks.
src/external/ezxml/ezxml.c Mark parse-string memory as malloc-owned using a sentinel in root->len so ezxml_free() frees correctly.
src/driver/mpas_subdriver.F Update core%setup_packages invocation to pass domain_ptr % dminfo.
src/core_test/mpas_test_core_interface.F Update test core setup_packages signature to include dminfo.
src/core_sw/mpas_sw_core_interface.F Update SW core setup_packages signature to include dminfo.
src/core_seaice/model_forward/mpas_seaice_core_interface.F Update seaice core setup_packages signature to include dminfo.
src/core_ocean/driver/mpas_ocn_core_interface.F Update ocean core setup_packages signature to include dminfo.
src/core_landice/mode_forward/mpas_li_core_interface.F Update landice core setup_packages signature to include dminfo.
src/core_init_atmosphere/Registry.xml Add config_active_hydrometeors; rename aerosol package; add qc/qr packages; gate qc/qr vars by package.
src/core_init_atmosphere/mpas_init_atm_read_met.F Provide default initial values/null pointer initialization for met_data fields.
src/core_init_atmosphere/mpas_init_atm_core_interface.F Implement hydrometeor package setup (automatic detection or list); add a new string-splitting helper.
src/core_atmosphere/mpas_atm_core_interface.F Update atmosphere core setup_packages signature to include dminfo.
Comments suppressed due to low confidence (1)

src/framework/regex_matching.c:72

  • Use MAX_LEN instead of the literal 1024 in snprintf so the buffer length stays consistent if MAX_LEN ever changes.
	*imatch = 0;
	len = snprintf(bracketed_pattern, 1024, "^%s$", pattern);
	if ( len >= MAX_LEN ) {
		*imatch = -1;

j = j + 1
if (i > len(string)) exit
end do
subStrings(n_strs)(j:max_strlen) = ''
<nml_option name="config_active_hydrometeors" type="character" default_value="detect_automatically"
units="-"
description="The set of hydrometeor species that are to be processed from input intermediate files when generating ICs and LBCs for real-data simulations."
possible_values="`detect_automatically', or a semicolon-separated list of hydrometeor names (e.g., `qc;qr'"/>
int l, i, j;

root->m = s;
root->len = -1; // so we know to free s in ezxml_free()
Comment on lines 53 to 70
subroutine mpas_framework_init_phase1(dminfo, external_comm)!{{{

#ifdef MPAS_USE_MPI_F08
use mpi_f08, only : MPI_Comm
#endif

implicit none

type (dm_info), pointer :: dminfo
#ifdef MPAS_USE_MPI_F08
type (MPI_Comm), intent(in), optional :: external_comm
#else
integer, intent(in), optional :: external_comm
#endif

allocate(dminfo)
call mpas_dmpar_init(dminfo, external_comm)

end subroutine mpas_framework_init_phase1!}}}
CI: pushing existing workflows down to 'develop' branch
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

Successfully merging this pull request may close these issues.

4 participants