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

remove most hamocc #ifdefs in favorite of new logicals #264

Closed
wants to merge 47 commits into from

Conversation

mvertens
Copy link
Contributor

@mvertens mvertens commented Aug 1, 2023

This is a draft PR that is a prototype implementation to move away from #ifdefs in BLOM and particularly in HAMOCC to the greatest extent possible. Most modeling efforts have adopted the approach to have the least number of #ifdefs possible.
This is a result of the fact that the code itself is not really tested until all possible #ifdef combinations are invoked. The more #ifdefs there are - the greater is the challenge to do this. By minimizing #ifdefs - the compilation can at least detect if there are inconsistencies in various branches that would always be compiled regardless of if they are actually invoked run time.

The approach I am suggesting is to introduce a new module in hamocc - mo_ifdefs.F90 that contains logicals that are parameters and that are triggerred by the presence of the #ifdefs.

#ifdef BROMO
  logical, parameter :: use_BROMO = .true.
#else
  logical, parameter :: use_BROMO = .false.
#endif

In the code itself - the majority of the #ifdefs are then replaced with logicals like (e.g. in aufw_bgc.F90):

       if (use_BROMO) then
         CALL write_netcdf_var(ncid,'bromo',locetra(1,1,1,ibromo),2*kpke,0)
      end if

Note that the work around to deal with ibromo values of -1 (when #BROMO is not defined) is to define loctre as

      REAL :: locetra(kpie,kpje,2*kpke,-1:nocetra) ! local array for reading

But to initialize locetra as

      locetra(:,:,:,1:)=trc(1:kpie,1:kpje,:,itrbgc:itrbgc+ntrbgc-1)

Multiple compilation errors were found when this was implemented. Below is a brief summary

The following were not defined when the ifdefs were removed - which means they would not have worked if the ifdefs were turned on

beleg_vars.F90(254): error #6404: This name does not have a type, and must have an explicit type.   [IPOWC13]
beleg_vars.F90(255): error #6404: This name does not have a type, and must have an explicit type.   [IPOWC14]
beleg_vars.F90(256): error #6404: This name does not have a type, and must have an explicit type.   [ISSSO13]
beleg_vars.F90(257): error #6404: This name does not have a type, and must have an explicit type.   [ISSSO14]
beleg_vars.F90(258): error #6404: This name does not have a type, and must have an explicit type.   [ISSSC13]
beleg_vars.F90(259): error #6404: This name does not have a type, and must have an explicit type.   [ISSSC14]

carchm.F90(636): error #6404: This name does not have a type, and must have an explicit type.   [KS]
carchm.F90(642): error #6410: This name has not been declared as an array or a function.        [SEDLAY]
carchm.F90(643): error #6410: This name has not been declared as an array or a function.        [POWTRA]
carchm.F90(644): error #6404: This name does not have a type, and must have an explicit type.   [ISSSO14]
carchm.F90(645): error #6404: This name does not have a type, and must have an explicit type.   [ISSSC14]
carchm.F90(646): error #6404: This name does not have a type, and must have an explicit type.   [IPOWC14]

aufw_bgc.F90(891): error #6404: This name does not have a type, and must have an explicit type.   [ISSSO13]
aufw_bgc.F90(892): error #6404: This name does not have a type, and must have an explicit type.   [ISSSO14]
aufw_bgc.F90(893): error #6404: This name does not have a type, and must have an explicit type.   [ISSSC13]
aufw_bgc.F90(894): error #6404: This name does not have a type, and must have an explicit type.   [ISSSC14]
aufw_bgc.F90(895): error #6404: This name does not have a type, and must have an explicit type.   [IPOWC13]
aufw_bgc.F90(896): error #6404: This name does not have a type, and must have an explicit type.   [IPOWC14]
aufw_bgc.F90(907): error #6404: This name does not have a type, and must have an explicit type.   [IATMC13]
aufw_bgc.F90(908): error #6404: This name does not have a type, and must have an explicit type.   [IATMC14]
aufw_bgc.F90(911): error #6404: This name does not have a type, and must have an explicit type.   [IATMNCO2]

aufr_bgc.F90(483): error #6404: This name does not have a type, and must have an explicit type.   [ISSSO13]
aufr_bgc.F90(484): error #6404: This name does not have a type, and must have an explicit type.   [ISSSO14]
aufr_bgc.F90(485): error #6404: This name does not have a type, and must have an explicit type.   [ISSSC13]
aufr_bgc.F90(486): error #6404: This name does not have a type, and must have an explicit type.   [ISSSC14]
aufr_bgc.F90(487): error #6404: This name does not have a type, and must have an explicit type.   [IPOWC13]
aufr_bgc.F90(488): error #6404: This name does not have a type, and must have an explicit type.   [IPOWC14]
aufr_bgc.F90(502): error #6404: This name does not have a type, and must have an explicit type.   [IATMC13]
aufr_bgc.F90(503): error #6404: This name does not have a type, and must have an explicit type.   [IATMC14]
aufr_bgc.F90(509): error #6404: This name does not have a type, and must have an explicit type.   [PREI13]
aufr_bgc.F90(511): error #6404: This name does not have a type, and must have an explicit type.   [PREI14]
aufr_bgc.F90(524): error #6404: This name does not have a type, and must have an explicit type.   [IATMNCO2]
aufr_bgc.F90(591): error #6404: This name does not have a type, and must have an explicit type.   [IPOWC]
aufr_bgc.F90(593): error #6404: This name does not have a type, and must have an explicit type.   [ISSSO]
aufr_bgc.F90(595): error #6404: This name does not have a type, and must have an explicit type.   [ISSSC]

accfields.F90(195): error #6404: This name does not have a type, and must have an explicit type.   [JATMO2]
accfields.F90(196): error #6404: This name does not have a type, and must have an explicit type.   [JATMN2]

ncout_hamocc.F90(482): error #6404: This name does not have a type, and must have an explicit type.   [JATMO2]
ncout_hamocc.F90(482): error #6404: This name does not have a type, and must have an explicit type.   [SRF_ATMO2]
ncout_hamocc.F90(483): error #6404: This name does not have a type, and must have an explicit type.   [JATMN2]
ncout_hamocc.F90(483): error #6404: This name does not have a type, and must have an explicit type.   [SRF_ATMN2]

aufr_bgc.F90(133): error #6580: Name in only-list does not exist or is not accessible.   [IPOWC]
aufr_bgc.F90(133): error #6580: Name in only-list does not exist or is not accessible.   [ISSSO]
aufr_bgc.F90(133): error #6580: Name in only-list does not exist or is not accessible.   [ISSSC]

aufw_bgc.F90(125): error #6580: Name in only-list does not exist or is not accessible.   [IPOWC]
aufw_bgc.F90(125): error #6580: Name in only-list does not exist or is not accessible.   [ISSSO]
aufw_bgc.F90(125): error #6580: Name in only-list does not exist or is not accessible.   [ISSSC]
aufw_bgc.F90(126): error #6580: Name in only-list does not exist or is not accessible.   [JATMO2]
aufw_bgc.F90(126): error #6580: Name in only-list does not exist or is not accessible.   [JATMN2]
aufr_bgc.F90(134): error #6580: Name in only-list does not exist or is not accessible.   [JATMO2]
aufr_bgc.F90(134): error #6580: Name in only-list does not exist or is not accessible.   [JATMN2]
aufw_bgc.F90(680): error #6404: This name does not have a type, and must have an explicit type.   [RMASKS]
aufr_bgc.F90(527): error #6404: This name does not have a type, and must have an explicit type.   [IATMNCO2]
aufr_bgc.F90(594): error #6404: This name does not have a type, and must have an explicit type.   [IPOWC]
aufr_bgc.F90(596): error #6404: This name does not have a type, and must have an explicit type.   [ISSSO]

The following is a bug in aufr_bgc - ipowc does not exist
      powtra2(i,j,k,ipowc13)=powtra2(i,j,k,ipowc)*rco213*bifr13
      powtra2(i,j,k,ipowc14)=powtra2(i,j,k,ipowc)*rco214*bifr14

The following is also a bug in aufr_bgc - issso and isssc do not exist
      sedlay2(i,j,k,issso13)=sedlay2(i,j,k,issso)*rco213*bifr13
      sedlay2(i,j,k,issso14)=sedlay2(i,j,k,issso)*rco214*bifr14
      sedlay2(i,j,k,isssc13)=sedlay2(i,j,k,isssc)*rco213
      sedlay2(i,j,k,isssc14)=sedlay2(i,j,k,isssc)*rco214

in hamocc4bcm.F90 - there is the following use statement but no corresponding module or call
      use mo_boxatm,      only: update_boxatm ERROR: there is no mo_boxatm
      if (use_BOXATM) then
         CALL update_boxatm(kpie,kpje,pdlxp,pdlyp)
      end if

NOTE: I realize that this is an invasive PR and as such maybe its not the time to do it. But I wanted to get the idea out there regarding the downside of an #ifdef based approach.

NOTE: The hamocc arrays are still not being dynamically allocated - but are based on parameter values as before in this implementation.

@jmaerz jmaerz mentioned this pull request Aug 2, 2023
@jmaerz
Copy link
Collaborator

jmaerz commented Aug 2, 2023

Dear @mvertens , @TomasTorsvik , @JorgSchwinger , as announced in the PM, we discussed the pull requests and the potential order of bringing in all the exciting new techniques and developments into iHAMOCC/BLOM. Since this pull request (#264) is quite invasive: @mvertens , would you be ok, if we would first i) add the boxatm routine, ii) potentially make minor changes in the sedshi.F90, routine and iii) , currently most useful, pull in #261 so that you would have to update this pull request (#264), before eventually merging it into master? We would let you know, once the master branch is prepared for an update of #264.

We further discussed that the if(use_...) statements for the initialization of parameters in most cases could be left out eventually, once the ifdefs are removed, so that in the new module mo_parambgc_ini simply some lines need to be removed when adopting the run-time solution for the pre-processor flags.



use mo_ifdefs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and potentially in other routines: it would be nice to explicitly incorporate all used switches, coming from mo_ifdefs (or potentially later from mo_control_bgc).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the latest changes I have pushed back there is no long the mo_ifdefs.F90 routine - all the logic has been migrated to mo_control_bgc.F90.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mvertens
Copy link
Contributor Author

mvertens commented Aug 2, 2023

@jmaerz- your plan sounds very good. However, we need to bring in #263 and #259 before we bring in #264.
Below is a new summary - with a question regarding 1.

  1. new PR: add the boxatm routine and potentially make minor changes in the sedshi.F90. (DONE)
  2. bring in Feature iHAMOCC nml #261 (DONE)
  3. bring in refactor buildnml to use the CIME-CCS python based namelist generation capabilities #263
    • create baselines for namelist refactor.
  4. bring in New capability to have BLOM optionally use DMS and BROMO fluxes computed in mediator #259
    • with the default being to keep the code bfb by setting do_bgc_aofluxes=.true.
    • verify that results are bfb with baselines created in 4.)
  5. bring in remove most hamocc #ifdefs in favorite of new logicals #264
    • verify that results are bfb with baselines created in 4.
  6. create new PR where do_bgc_aofluxes = .false.
    • have the mediator compute dms and bromo fluxes - this will also require a new CMEPS tag AND a new noresm snapshot to pull in the new CMEPS tag for creating the DMS and BROMO fluxes.
    • create new baselines.
    • introduce new namelist capability for do_bgc_aofluxes.

@JorgSchwinger
Copy link
Contributor

  1. dd the boxatm routine and potentially make minor changes in the sedshi.F90, routine - what PR would this be in???

I am preparing a PR based on current master with mo_boxatm added right now. If I encounter no further problems, this PR will be available in a few hours.

@mvertens
Copy link
Contributor Author

mvertens commented Aug 2, 2023

@JorgSchwinger - thanks for the clarification. I have updated my comment.

@mvertens mvertens added the enhancement New feature or request label Aug 2, 2023
@JorgSchwinger
Copy link
Contributor

  1. new PR: add the boxatm routine and potentially make minor changes in the sedshi.F90.

With merging #265 and #266 this milestone has been reached.

@mvertens
Copy link
Contributor Author

mvertens commented Aug 4, 2023

@JorgSchwinger - thanks so much for your work on 1.

@jmaerz
Copy link
Collaborator

jmaerz commented Aug 9, 2023

Merge #261 has now also been carried out - so point 2 of the above list is also done.

@JorgSchwinger
Copy link
Contributor

Dear @mvertens, @TomasTorsvik , and @jmaerz

This PR comes with a lot of fixes for missing variables in only lists. I'm currently trying to get current master up to date for running C-isotopes with sediment switched on (we want this for the upcoming release), so I need to put in many of these fixes that are here already.

This is fine for me, but it will certainly lead to a bunch of merge conflicts when we want to merge this branch in. Any thoughts or advise on this?

@jmaerz
Copy link
Collaborator

jmaerz commented Sep 27, 2023

Hi @JorgSchwinger , @mvertens and @TomasTorsvik , if I got you right during talking to you over lunch, @JorgSchwinger , you would want to merge your changes for the carbon isotopes into master (currently, there is no pull request for this, which should come soon - probably within this week from @monsieuralok ). I suspect that there will be some work needed to bring the ifdefs branch to a state that it can be easily merged with master (due to a number of merge conflicts). I would suggest to update the ifdefs branch (merge master into ifdefs to get a common hook) once the master includes the updates for the carbon isotopes. Then perform the pull request for #264 after a final round of review. Hence the question to @mvertens , if you would be willing to do it this way or do you see/suggest to perform different steps?

Further, since #259 is also pending, the above scenario probably also holds for #259, which, if I understand it correctly, shall be pulled in before this pull request (#264). Since it is thus far a recurrent discussion issue: both #259 and #264 should not affect compatibility with MCT - somehow, we have to ensure this for the current version and at least until the INES interim release.

@mvertens
Copy link
Contributor Author

@JorgSchwinger - please go ahead and bring your changes in. I am fine handling the merge conflicts when we decide to bring this in.

In addition, I need to create baselines for the current code so that upcoming PRs can test against it. I should have done this as part of the previous PR - but got pulled into working for integrating the oslo aerosols code into the latest version of Noresm/CAM. I'm trying to generate those baselines now - but am running into some strange failures for some of the tests. I'll provide an update once I know more.

@TomasTorsvik
Copy link
Contributor

@mvertens - would it be possible to merge this PR into BLOM master without doing #259 first? I was discussing with Jörg and Jöran today, and we see that removing CPP flags could be useful to have in the upcoming release, but we were wondering if this could somehow be done independently of the DMS and BROMO development.

@mvertens
Copy link
Contributor Author

mvertens commented Oct 11, 2023

@TomasTorsvik - great idea. I think that's the right thing to do. Do you want this PR to go next? If so - let me work on this over the next day or two and make this PR no longer draft. I've created baselines for the previous tag - so it should be easy for me to validate that this will not change answers.

@NorESMhub NorESMhub deleted a comment from tomas Oct 11, 2023
@mvertens
Copy link
Contributor Author

The PR is now closed in favor of #280 and #281.

@mvertens mvertens closed this Oct 16, 2023
@mvertens mvertens deleted the feature/refactor_ifdefs branch May 15, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants