geoschem / geos-chem

GEOS-Chem "Science Codebase" repository. Contains GEOS-Chem science routines, run directory generation scripts, and interface code. This repository is used as a submodule within the GCClassic and GCHP wrappers, as well as in other modeling contexts (external ESMs).
http://geos-chem.org
Other
167 stars 163 forks source link

Remove array temporaries #1726

Closed lizziel closed 1 year ago

lizziel commented 1 year ago

Name and Institution (Required)

Name: Lizzie Lundgren Institution: Harvard University

Confirm you have reviewed the following documentation

New GEOS-Chem feature or discussion

I noticed several messages about array temporaries being created during review of an integration test log. I am noting them here as something to put on our to do list to fix. I don't think this is a new issue, but maybe went under the radar since the message only shows up with debug compiler flag on.

seasalt_mod.F90:

At line 227 of file /n/holyscratch01/jacob_lab/elundgren/testruns/gchp_14.2_updates/integration/CodeDir/src/GCHP_GridComp/GEOSChem_GridComp/geos-chem/GeosCore/seasalt_mod.F90
Fortran runtime warning: An array temporary was created for argument 'tc' of procedure 'wet_settling'
At line 252 of file /n/holyscratch01/jacob_lab/elundgren/testruns/gchp_14.2_updates/integration/CodeDir/src/GCHP_GridComp/GEOSChem_GridComp/geos-chem/GeosCore/seasalt_mod.F90
Fortran runtime warning: An array temporary was created for argument 'tc' of procedure 'wet_settling'
At line 277 of file /n/holyscratch01/jacob_lab/elundgren/testruns/gchp_14.2_updates/integration/CodeDir/src/GCHP_GridComp/GEOSChem_GridComp/geos-chem/GeosCore/seasalt_mod.F90
Fortran runtime warning: An array temporary was created for argument 'tc' of procedure 'wet_settling'
At line 302 of file /n/holyscratch01/jacob_lab/elundgren/testruns/gchp_14.2_updates/integration/CodeDir/src/GCHP_GridComp/GEOSChem_GridComp/geos-chem/GeosCore/seasalt_mod.F90
Fortran runtime warning: An array temporary was created for argument 'tc' of procedure 'wet_settling'
At line 327 of file /n/holyscratch01/jacob_lab/elundgren/testruns/gchp_14.2_updates/integration/CodeDir/src/GCHP_GridComp/GEOSChem_GridComp/geos-chem/GeosCore/seasalt_mod.F90
Fortran runtime warning: An array temporary was created for argument 'tc' of procedure 'wet_settling'
At line 352 of file /n/holyscratch01/jacob_lab/elundgren/testruns/gchp_14.2_updates/integration/CodeDir/src/GCHP_GridComp/GEOSChem_GridComp/geos-chem/GeosCore/seasalt_mod.F90
Fortran runtime warning: An array temporary was created for argument 'tc' of procedure 'wet_settling'

carbon_mod.F90:

At line 503 of file /n/holyscratch01/jacob_lab/elundgren/testruns/gchp_14.2_updates/integration/CodeDir/src/GCHP_GridComp/GEOSChem_GridComp/geos-chem/GeosCore/carbon_mod.F90
Fortran runtime warning: An array temporary was created for argument 'tc' of procedure 'chem_bcpo'
At line 512 of file /n/holyscratch01/jacob_lab/elundgren/testruns/gchp_14.2_updates/integration/CodeDir/src/GCHP_GridComp/GEOSChem_GridComp/geos-chem/GeosCore/carbon_mod.F90
Fortran runtime warning: An array temporary was created for argument 'tc' of procedure 'chem_bcpi'
At line 521 of file /n/holyscratch01/jacob_lab/elundgren/testruns/gchp_14.2_updates/integration/CodeDir/src/GCHP_GridComp/GEOSChem_GridComp/geos-chem/GeosCore/carbon_mod.F90
Fortran runtime warning: An array temporary was created for argument 'tc' of procedure 'chem_ocpo'
At line 530 of file /n/holyscratch01/jacob_lab/elundgren/testruns/gchp_14.2_updates/integration/CodeDir/src/GCHP_GridComp/GEOSChem_GridComp/geos-chem/GeosCore/carbon_mod.F90
Fortran runtime warning: An array temporary was created for argument 'tc' of procedure 'chem_ocpi'
yantosca commented 1 year ago

Hi @lizziel, you can assign this to me. I can take a look. I think I know where these are coming in.

lizziel commented 1 year ago

Thank you @yantosca!

yantosca commented 1 year ago

I believe the array temporary in seasalt_mod.F90 is caused by trying to pass State_Chm%Species(id_SALC)%Conc(:,:,:) to argument TC(:,:,:)

    !========================================================================
    ! Coarse mode (SALC) wet settling
    !========================================================================
    IF ( id_SALC > 0 ) THEN
       CALL Wet_Settling(                                                    &
            Input_Opt  = Input_Opt,                                          &
            State_Chm  = State_Chm,                                          &
            State_Diag = State_Diag,                                         &
            State_Grid = State_Grid,                                         &
            State_Met  = State_Met,                                          &
            TC         = State_Chm%Species(id_SALC)%Conc,                    &
            N          = 2,                                                  &
            RC         = RC                                                 )
...etc...

I am testing the fix:

    !========================================================================
    ! Coarse mode (SALC) wet settling
    !========================================================================
    IF ( id_SALC > 0 ) THEN
       CALL Wet_Settling(                                                    &
            Input_Opt  = Input_Opt,                                          &
            State_Chm  = State_Chm,                                          &
            State_Diag = State_Diag,                                         &
            State_Grid = State_Grid,                                         &
            State_Met  = State_Met,                                          &
            spcId      = id_SALC,                                            &
            N          = 2,                                                  &
            RC         = RC                                                 )

and then inside routine Wet_Settling we use a pointer reference near the top of the routine:

    ! Pointers
    REAL(fp), POINTER  :: TC(:,:,:)
    . . . 
    ! Point to the species concentration array in State_Chm%Species
    TC => State_Chm%Species(spcId)%Conc

and nullify the pointer before the end of the routine

   TC => NULL()

This avoids passing an array field of an object to the routine.

The TC array is is historical baggage from the pre State_Chm days. No need to pass the species array separately anymore since it is now in State_Chm.

yantosca commented 1 year ago

Likewise, passing State_Chm directly to the CHEM_BCPO, CHEM_BCPI, CHEM_OCPO, CHEM_OCPI routines also avoids the array temporaries.

msulprizio commented 1 year ago

The pull request (#1729) associated with this issue has now been merged into the 14.2.0 development branch.