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
BLING "spring cleaning" #778
base: master
Are you sure you want to change the base?
Conversation
This looks great to me! |
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.
I took a quick look, and this looks good. I have 3 comments:
- looks like TAF is getting 3 recomputation warnings now, in AD experiment
global_oce_biogeo_bling
. Now the gradient check did not change at all but seeing some changes to AD-Monitor foradptracer03
andadptracer06
(2 digit match only). - it would be good to have the "local time refinement" to also work when
pkg/cal
is compiled but not used (useCAL=F
) as well as when it's not even compiled, since it's not too difficult to change (see comment below). - the time-window boundaries (12:00 and 13:30) could be changed to parameter, if not run-time params at least fortran
PARAMETER
(locally inbling_light.F
). This could help to follow what the code is doing and also in case this time-window needs to be changed.
pkg/bling/bling_light.F
Outdated
C Satellite chlorophyll | ||
#ifdef ALLOW_CAL | ||
c mydate is utc time | ||
diffutc = XC(i,j,bi,bj)/360.*24 |
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.
I think it would not be difficult to have something equivalent for the case useCAL = F
. I could suggest some changes in this routine if you like.
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.
I'm not sure what the equivalent of the variable localtime is when pkg/cal is not used. Suggestions appreciated!
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.
In addition, the code only makes sense, if XC
holds the longitude, i.e. not for cartesian coordinates. Do you want to catch that case?
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.
Ideally yes! And anything else that I've missed, because it's not in the setup I'm used to :)
pkg/bling/bling_bio_nitrogen.F
Outdated
@@ -1895,6 +1899,8 @@ SUBROUTINE BLING_BIO_NITROGEN( | |||
CALL DIAGNOSTICS_FILL(N_reminp, 'BLGNREM ',0,Nr,2,bi,bj,myThid) | |||
CALL DIAGNOSTICS_FILL(P_reminp, 'BLGPREM ',0,Nr,2,bi,bj,myThid) | |||
CALL DIAGNOSTICS_FILL(no3_adj, 'BLGNONEN',0,Nr,2,bi,bj,myThid) | |||
C 2d global variables | |||
CALL DIAGNOSTICS_FILL(chl_sat, 'BLGCHLSA',0,1,1,bi,bj,myThid) |
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.
An alternative would be to move this DIAGNOSTICS_FILL
call directly inside bling_light.F
where it's computed.
And I did not check carefully, but if variable chl_sat
is just used for diagnostics, then it could be changed to a local variable inside bling_light.F
and removed from common block. Now this might not be a good idea if you have in mind of computing some cost function from it.
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.
I'm moving the diagnostic_fill call inside bling_light.F as suggested.
chl_sat is going to be used in the cost function, so I'm going to keep it as a global variable.
pkg/bling/bling_bio_nitrogen.F
Outdated
Phy_lg_local(i,j,k) = max( epsln, Phy_lg_local(i,j,k) ) | ||
Phy_sm_local(i,j,k) = max( epsln, Phy_sm_local(i,j,k) ) | ||
Phy_diaz_local(i,j,k) = max( epsln, Phy_diaz_local(i,j,k) ) | ||
|
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.
To avoid the new recomputation warnings (the associated recomputations make the run much longer: ALL increases from 128s to 434s, because ADTHE_MAIN_LOOP increases from 52s to 358s) can be avoided without store directives, see below, but most of this routine is actually recomputed in the AD-code and one may want to fix that.
Phy_lg_local(i,j,k) = max( epsln, Phy_lg_local(i,j,k) ) | |
Phy_sm_local(i,j,k) = max( epsln, Phy_sm_local(i,j,k) ) | |
Phy_diaz_local(i,j,k) = max( epsln, Phy_diaz_local(i,j,k) ) | |
#ifdef ALLOW_AUTODIFF_TAMC | |
C avoid recomputation warnings | |
ENDIF | |
ENDDO | |
ENDDO | |
ENDDO | |
DO k=1,Nr | |
DO j=jmin,jmax | |
DO i=imin,imax | |
IF ( maskC(i,j,k,bi,bj).EQ.oneRS ) THEN | |
#endif | |
Phy_lg_local(i,j,k) = max( epsln, Phy_lg_local(i,j,k) ) | |
Phy_sm_local(i,j,k) = max( epsln, Phy_sm_local(i,j,k) ) | |
Phy_diaz_local(i,j,k) = max( epsln, Phy_diaz_local(i,j,k) ) | |
It's not clear to me why this needs to be "hidden from the adjoint" (as stated the routine
|
@jm-c Thank you for the feedback - great suggestions! I’m working on it. |
@mjlosch Thank you for your help! Yes, if you can push your version of bling_bio_nitrogen.F, that would be great. I'm working on addressing your other suggestions. |
This change speeds up ADTHE_MAIN_LOOP in verification/global_oce_bio_bling by a factor of 7 (!), mainly because it fixes the extensive recomputations. Relative to the version prior to this PR the speed up is small. With this commit (on my laptop): User/System/Wall clock time: 51.93 sec / 0.30 sec / 52.59 sec Before: User/System/Wall clock time: 358.49 sec / 0.35 sec / 360.67 sec
@jm-c Regarding your comment "1" above, I think Martin's edits will have solved the recomputations. Should I do something about "changes to AD-Monitor for adptracer03 and adptracer06"? In response to comment "3" I'm making the time-window boundaries run-time parameters. |
@mjlosch Regarding your comment "2": the "adj" variables are meant to keep track for the adjustments for budget calculations. If the bling_min_val code doesn't need to be hidden from the adjoint, should I remove it from bling_ad.flow and bling_ad_diff.list? I'm moving the purely diagnostic fields to the diagnostics section as suggested in comment "3". |
about comment 2: yes, you could do that, but that will give you recomputation warnings that need to be dealt with via store directives. The question is if you really need that. I can push something, if you like. Also in |
@averdy I saw the 2 new parameters |
- remove bling_write_pickup.f from bling_ad_diff.list because the call is not visible to taf anyway - remove bling_read_pickup.f from bling_ad_diff.list because there are flow directives (avoid another warning)
… bling_cleanup
@averdy I am going to revert your last commit, because it "undo" all the changes that have been added since last November (and, as a result, this PR now affects 273 files). I went back 1 commit on my clone and I've checked that I have |
I remove the last commit by doing:
so I used a "forced push", and regarding updates, if you already have a local copy of this branch, using simply "git pull" might not work well. For this case, either (a) removing this branch from your local copy ("git branch -D bling_cleanup") and getting it back after a "git fetch", as mentionned earlier, or (b) with "git fetch [remote] ; git checkout bling_cleanup ; git restore . " might do it too. |
Thank you @jm-c! I've updated my local copy. |
LGTM |
@averdy Sorry for waiting so long. |
@jm-c That sounds great! |
Also, as I am looking at the details of this local-time window, it seems that the current version is not very accurate: |
so my little changes are going to fix also this inaccuracy. |
- rename the 2 new params to "chlsat_locTimWindow(2)" (in decimal hour) - use "decimal hour" consistently (this fix inaccurate time-window criteria). - allow to be used without pkg/cal
just to avoid un-used variables
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. I run fwd, adm TAF and Tapenade testreport for exp. global_oce_biogeo_bling
and all look good. I see minor changes to AD-monitor for the TAF one but I guess it's expected given the changes in store directives. @mjlosch do you agree ?
@averdy From my side, this PR is good to be merged. So, when you have time, please check/review my set of recent changes and let us know if you aggree or not. |
@jm-c It looks great!! Thank you so much for improving this code! |
I agree, this looks like the usual round-off issue with recomputation vs restoring from tape (common block). Nothing to worry about. |
What changes does this PR introduce?
What is the current behaviour?
What is the new behaviour
Does this PR introduce a breaking change?
No
Other information:
Suggested addition to
tag-index
(To avoid unnecessary merge conflicts, please don't update
tag-index
. One of the admins will do that when merging your pull request.)