-
Notifications
You must be signed in to change notification settings - Fork 237
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
ctrl/autodiff cleanup #471
Conversation
- part 1: AUTODIFF.h, ctrl.h - instead declare them locally, to remove many "unused" warnings for tmpfld2/3d, ilev_?, max_lev?, fname_$varname - also remove some locally declared unused variable
@jm-c The next step is to move |
I guess I will need help with debugging the OpenAD tests. I don't even think I can compile the forward code without OpenAD installed and set up. How annoying. |
@mjlosch I can take a look at OpenAD setup. |
I don't like the CPP option idea too much. If you think it's OK to modify tamc.h this substantially, I'll go ahead an give it a try (preferably only in one commit). We can always revert if it does not look good. Should I do this before you look at OpenAD or should I wait? |
I took a look at global_ocean.90x40x15 OpenAD error. I tried gdb but did not help to see where the error comes from inside S/R OpenAD_external_forcing_surf (file: external_forcing_surf_cb2m_oad.f). Then I diff it with version from unmodified OpenAD built but did not help (given that many variables are numbered and these numbers change). Note that if I were to compare external_forcing_surf.f I would not see any difference.
|
I am not sure, how I can contribute to debugging the OpenAD problem (where can I find instructions to download and setup OpenAD?).
|
@jahn found a fix so that it works with: before PR 471 we had in ctrl.h (and obviously this works):
Now when you put back the common block:
and this works, too. Leaving OpenAD aside, tmpfld2/3d clearly do not need to be in a common block, because they are always used as local variable arrays. The purpose of this PR #471 is to clean that up, declare the variables locally and by this means get rid of the unused warning messages. If we now instead put @jm-c @heimbach please comment. In particular, Patrick, can you remember, why you commented out the common blocks? in 57b21c8 (6 years ago, ...) |
@mjlosch changing these 2 local arrays to global one (in common block) is not really the way we want to go. |
You are asking a lot of my Swiss cheese (aka memory)...
One thing is that OpenAD will convert all common blocks into modules (this was required at the inception of OpenAD, and later attempts to undo this need have been unsuccessful since then). If I remember correctly (probably incorrectly), this c2m conversion caused trouble for tmpfld2d, tmpfld3d. Bould would have to dig deeper…
p.
… On May 13, 2021, at 8:04 AM, Martin Losch ***@***.***> wrote:
@jahn found a fix so that it works with:
before PR 471 we had in ctrl.h (and obviously this works):
cph common /controlvars_r/
cph & tmpfld2d
cph & , tmpfld3d
_RL tmpfld2d(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL tmpfld3d(1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy)
Now when you put back the common block:
common /controlvars_r/
& tmpfld2d
& , tmpfld3d
_RL tmpfld2d(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL tmpfld3d(1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy)
and this works, too.
Leaving OpenAD aside, tmpfld2/3d clearly do not need to be in a common block, because they are always used as local variable arrays. The purpose of this PR #471 is to clean that up, declare the variables locally and by this means get rid of the unused warning messages.
If we now instead put tmpld2/3d back into a common block again (provided this works with OpenAD), this would get rid of the unused warnings, but would have these fields defined globally. Does it matter at all?
@jm-c @heimbach please comment. In particular, Patrick, can you remember, why you commented out the common blocks? in 57b21c8 (6 years ago, ...)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@heimbach apparently having the common block now seems to work, but we don't really want to have them, do we? @jm-c are you suggesting that I put back into "ctrl.h":
and then add a |
@mjlosch Yes, this is what I had in mind. I don't think it's a bad compromise given where we are now with OpenAD. |
use CPP-flag ALLOW_OPENAD to switch declarations of tmpfld2/3d in and out.
That worked really well ... hmph. |
I just hope this works.
FWIW, the tmpfld*d related errors with OpenAD also go away if one initializes the local fields to zero in each subroutine. |
I like that solution much better than what I have done now. @jahn it would be great if you could make this change, i.e. remove the declaration again from ctrl.h and all of the |
Shall I do this between "#ifdef ALLOW_OPENAD"? @jm-c? |
If you asked me, then it's always a good idea to initialise fields before they are used. I didn't think of that because I just moved the declarations around. I don't think that we need |
There is one occurrence of tmpfld2d/3d in pkg/admtlm/admtlm_bypassad.F where the fields are clearly used uninitialized. The first use is this:
Can someone explain to me why this is? |
To me this looks like very old and unmaintained code. Do we have an example experiment for this? We should probably leave this as it is, so that it is clear that it needs work, if someone tries to use the code? |
@jahn @jm-c @heimbach
the errors are related to Maybe Patrick can confirm, but my impression is that this package is basically an example of how to use the AD-code to compute leading growing modes (perform an SVD to get the larges singular vectors), but that this hasn't been used in a long while, not maintained and that it is not expected to work out of the box. It wouldn't take too much effort to fix the compile time errors, but it would take (me) quite some time (which I will not invest) to make this work properly. I suggest that we leave this alone for now and, if we decide to bring this code up-to-date, have a separate PR for this. |
Thanks for looking into this. I'll just put the declaration, so as to not introduce yet another error. I also left the code_oad files alone. Initialization doesn't seem necessary and I did not want to make these genarr code examples too messy. |
I think I am done here. There's much more to clean up, but I would like to keep the number of modified files below 200 (-: |
@mjlosch 2 preliminary comments:
|
kpp_calc.F: fix a shelfice related index problem and some beautification
@mjlosch I started to look over some of the changes here but, since there are many updated files, I am not done yet. There is one thing that might be useful to add to this PR, because it's closely related to the changes already in: Normally, tamc.h should not be included in any set-up that uses OpenAD, and could, in theory, be removed form files "cb2mFiles" (as you did with tamc_keys). Do you think it's worth to try ? And unrelated: I was going to make a PR on verification_other with modifications needed after this PR is merged, unless you are already ready to do this (I started this but not yet done). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me. Some changes in kpp_calc.F related to useShelfIce might need some little adjustment but over all looks like every thing is in order.
@jm-c
Please go ahead, I haven't started that yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If this is OK for everyone, could merge this PR soon, like tomorrow. |
- document fixing missing keys decalartion in shelfice_thermodynamics.F - update description related to PR MITgcm#471 (ctrl_cleanup).
* ctrl/autodiff cleanup follow-up * make tamc.h template consistent with recent changes - forgot to adjust the tamc.h template (which is never used) - remove all local keys and variables, add a comment and an include statement * remove unnecessary "#include PACKAGES_CONFIG.h" from all tamc.h * A little cleanup * Document a fix + update previous comments - document fixing missing keys decalartion in shelfice_thermodynamics.F - update description related to PR #471 (ctrl_cleanup). * fake update Co-authored-by: Martin Losch <martin.losch@awi.de> Co-authored-by: Jean-Michel Campin <jmc@mit.edu>
Stats: over the full set (18 built) of AD verification experiments, number of compiler warning for unused variables got reduced by more than 27, from > 31.k to 1146. |
Left over from PR MITgcm#471 where local keys have been moved out of tamc.h: All pieces of code that is tested (in regression tests) got updated. But some pieces that are not tested might not have been updated (e.g., see PR MITgcm#482): bling_bio.F : fixed for the case #define USE_BLING_V1 bling_light.F : fixed for the case #define PHYTO_SELF_SHADING obcs_calc_stevens.F : missing AUTODIFF_OPTIONS.h + missing local keys declarations obcs_sponge.F : missing AUTODIFF_OPTIONS.h + missing local keys declarations
* add missing AUTODIFF_OPTIONS.h need to include AUTODIFF_OPTIONS.h to get ALLOW_AUTODIFF_TAMC defined * Add missing declaration of local keys for TAF store-dir Left over from PR #471 where local keys have been moved out of tamc.h: All pieces of code that is tested (in regression tests) got updated. But some pieces that are not tested might not have been updated (e.g., see PR #482): bling_bio.F : fixed for the case #define USE_BLING_V1 bling_light.F : fixed for the case #define PHYTO_SELF_SHADING obcs_calc_stevens.F : missing AUTODIFF_OPTIONS.h + missing local keys declarations obcs_sponge.F : missing AUTODIFF_OPTIONS.h + missing local keys declarations * Remove included "tamc.h" (not needed). * Remove included "tamc.h" (not needed). also change 1 ALLOW_AUTODIFF_TAMC into ALLOW_AUTODIFF * replace ALLOW_AUTODIFF with ALLOW_AUTODIFF_TAMC around TAF-store-dir * replace byte by kind, store cflZon/Mer and gFacZ/M to avoid warnings * Remove inluded "tamc.h" if not needed. also: - remove included "AUTODIFF_OPTIONS.h" if only there for tamc.h. - change 1 ALLOW_AUTODIFF_TAMC to ALLOW_AUTODIFF in seaice_calc_strainrates.F - + minor edits (remove few trailing blank). * Minor ALLOW_AUTODIFF <-> ALLOW_AUTODIFF_TAMC adjustment * minor: change some indentation in comments * Remove TAF store-dirs and included "tamc.h" Storage dir for OB temp and salt are not necessary since it's done in forward_step.F (in checkpoint_lev1_directives.h -> obcs_ad_check_lev1_dir.h). Simplify the code by removing them here (in obcs_songe.f). * Finish removing TAF store-dirs Forgot to remove/cleanup the rest of this file in previous commit; done now. * Switch to #define ALLOW_OBCS_STEVENS Note: the Stevens OB code is not used in this set-up so that compiling this code is not necessary (and does increase the number of written tapes) but does not change results. The ONLY reason it is turned on here is to check that this code compiles in Adjoint set-up. * document few updates in tamc.h included files. Co-authored-by: Martin Losch <martin.losch@awi.de>
What changes does this PR introduce?
This is part of a cleanup of pkg/ctrl and autodiff.
What is the current behaviour?
Many variables are declared in header files, but are really local variables, see part of #440, in particular:
What is the new behaviour
local variables are removed from pkg/ctrl/ctrl.h and pkg/autodiff/AUTODIFF.h and declared locally. Number of "unused" warnings reduced.
Does this PR introduce a breaking change?
No, unless any of you customized files in your local code directories rely on these variables. In that case, you'll have to declare the variables in question locally.
Other information:
Draft PR in order to discuss further steps, if any.
Suggested addition to
tag-index
o pkg/ctrl/autodiff