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

Clean unused var #579

Merged
merged 11 commits into from
Jan 5, 2022
Merged

Clean unused var #579

merged 11 commits into from
Jan 5, 2022

Conversation

jm-c
Copy link
Member

@jm-c jm-c commented Dec 20, 2021

What changes does this PR introduce?

Remove or avoid un-used (local) variables in (TAF) AD built and clean-up (a little) pkg/smooth.

What is the current behaviour?

Most un-used variables have been removed from FWD verification experiment built but still many seen in AD verification exp. built (although the number went down by > x 31 after merging PR #471).

What is the new behaviour

clean up by removing or just avoiding some un-used variables

Does this PR introduce a breaking change?

no real code change, zero change in results.

Other information:

a) for now, no changes in pkg/streamice (left AD exp halfpipe_streamice on the side).
b) there is still unused variables left in src files that are processed by TAF, but, since TAF remove them, it's less an issue + don't notice any warning.

Suggested addition to tag-index

o pkgs:

  • remove/avoid unused variables from AD verification exp. built except from
    halfpipe_streamice (pkg/streamice); also clean-up a bit pkg/smooth.

clean-up to keep all local variables declared in single place (and no longer in middle of src file)
also bring more consistent upper/lower case writing
- add missing CTRL_OPTIONS.h (S/R was mostly empty without ALLOW_DEPTH_CONTROL
  being defined);
- comment out resetting of "writeBinaryPrec" (which is not safe);
- call PRINT_ERROR & PRINT_MESSAGE with myThid argument;
- avoid un-used variables.
- remove/avoid un-used variables
- separate S/R arg and local var
- fix/improve indentation
- more consistent upper/lower case writing
@jm-c jm-c added the adjoint Affects the adjoint model; label triggers full OpenAD test label Dec 20, 2021
@jm-c
Copy link
Member Author

jm-c commented Dec 21, 2021

Some stats: for all AD verification exp, the number of used variable warnings in all built when down from 31,700 before PR #471 to 1062 with current master, and now down to 40 with this PR (including 38 from halfpipe_streamice built).

Also will remove few more unused var that don't show up in AD built log file because TAF remove them.

also simplify and clean a bit some src files (e.g., skip copy of tile loop
 range into local vars itlo,ithi & jtlo,jthi )
@mjlosch
Copy link
Member

mjlosch commented Dec 27, 2021

@jm-c just a comment/suggestion: These variables defined as parameters in tamc.h:

      integer nyears_chkpt
      integer nmonths_chkpt
      integer ndays_chkpt
      integer ngeom_chkpt
      integer ncheck_chkpt

are not used anywhere in the code, as far as I can see. They do not produce unused-warning messages, because of the parameter statements, but they are unused, nevertheless. Maybe we can remove them in the PR as well?

@jm-c jm-c requested a review from mjlosch December 27, 2021 14:47
@jm-c
Copy link
Member Author

jm-c commented Dec 27, 2021

@mjlosch Thaks for the sugestion. I will remove these unsed "parameters"

@mjlosch
Copy link
Member

mjlosch commented Dec 27, 2021

Not yet a review, but just a comment: in the context of #529 I already removed a few unused variables from pkg/streamice. Further I noticed that "ECCO_CPPOPTIONS.h" is still being used in "global_ocean_ebm" and "halfpipe_streamice". I cannot remember why. I have started a branch to fix that, and this may be yet another chance to clean up some TAF-related aspects of streamice (by no means everything). I will wait for this and #529 to be merged before proceeding and turning that branch into a PR.

Copy link
Member

@mjlosch mjlosch left a comment

Choose a reason for hiding this comment

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

This is a very useful (and tedidious) clean-up PR. Obviously, I did not check all 96 files. With

grep -B4 "Warning: Unused variable" */build/make.tr_log

I found only 39 warnings, all but one in halfpipe_streamice. The only other one in bottom_ctrl_5x5, which could be suppressed by a cpp-flag in ctrl_unpack.F (in analogy to ctrl_pack.F):

#if (defined ALLOW_OBCS || defined ECCO_CTRL_DEPRECATED)
      character*( 80) weighttype
#endif

Should be we add that? Otherwise, LGTM and should be merged quickly, because it affects so many files and hence current PRs, for which we need to make sure, that they don't break this cleanup. The earlier we do this, the better.

@jm-c
Copy link
Member Author

jm-c commented Jan 2, 2022

@mjlosch Thanks for the review. I fixed ctrl_unpack.F the way you suggested (I probably missed this one in the first round of changes).
Regarding un-used parameters in tamc.h, it seems better (from my point of view) to do this in an other PR, since:
a) this would require to update all tamc.h from all AD verification exp. code_ad, since the reference version in pkg/autodiff is never used. So probably better to do this in a PR focused on verfication//code_ad cleaning.
b) the only "
_chkpt" that is used, i.e., nthreads_chkpt, could also be removed from tamc.h and from few src files,
at least as I see it, because it should never be different from unity. So maybe something to sort out at the same time as removing all the others.

@jm-c
Copy link
Member Author

jm-c commented Jan 2, 2022

And regarding this:

Not yet a review, but just a comment: in the context of #529 I already removed a few unused variables from pkg/streamice. Further I noticed that "ECCO_CPPOPTIONS.h" is still being used in "global_ocean_ebm" and "halfpipe_streamice". I cannot remember why. I have started a branch to fix that, and this may be yet another chance to clean up some TAF-related aspects of streamice (by no means everything). I will wait for this and #529 to be merged before proceeding and turning that branch into a PR.

I avoided changing anything in pkg/streamice so no risk of conflicts. And regarding CPP header files from verification code_ad dir I also noticed #577 which could be cleaned-up as well.

@mjlosch
Copy link
Member

mjlosch commented Jan 3, 2022

@jm-c it's not clear to me why weighttype is commented out in "ctrl_unpack.F" once for the generic controls (2D)

cc write(weighttype(1:80),'(80a)') ' '
cc write(weighttype(1:80),'(a)') "wunit"

but three times in "ctrl_pack.F". To me this appears totally inconsistent. Plus, weighttype is not used in any of the generic controls, as far as I can see. So instead of 28566e3 we could remove (or comment out) weighttype consistently with "ctrl_pack.F". Maybe we can have an opinion from the ECCO crowd (@owang01 , @ifenty).

@jm-c
Copy link
Member Author

jm-c commented Jan 3, 2022

@mjlosch I will follow your suggestion and go back 1 commit (to d1cea20 ) and comment out these internal "write". Since these 'write" do not do anything and are commented out in 1/3 places in this routine and all 3/3 in ctrl_pack.F it's just cleaner to have also 3/3 commented out here.

@jm-c
Copy link
Member Author

jm-c commented Jan 3, 2022

@mjlosch I agree that, since this PR involves many files, it would be easier if it could be merged relatively soon.
So if you agree with both latest changes + my comments, we could merge it in the coming days.

@mjlosch
Copy link
Member

mjlosch commented Jan 4, 2022

@jm-c your latest changes look good to me. Let's merge this.

@jm-c
Copy link
Member Author

jm-c commented Jan 4, 2022

OK, unless someone disagree, will merge this PR tomorrow.

jm-c added a commit to averdy/MITgcm that referenced this pull request May 22, 2024
just to avoid un-used variables
jm-c added a commit that referenced this pull request May 22, 2024
* BLING "spring cleaning"

* clean up store directives and restructure a little for easier AD

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

* clean up diagnostics, chl_sat

* clean up diagnostics, chl_sat

* adjust cpp-flags to reduce number of taf-not-necessary-warnings

* make s/r bling_min_val visible to taf, adjust store directives

- 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)

* add chlsat_t parameters to namelist and set default values

* remove double blank line

* improve new chl_sat time-window

- 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

* bring back PR #579 changes

just to avoid un-used variables

* minor adjustment

* document improvements in pkg/bling

---------

Co-authored-by: averdy <averdy@mist.ucsd.edu>
Co-authored-by: Jean-Michel Campin <jmc@mit.edu>
Co-authored-by: mjlosch <Martin.Losch@awi.de>
Co-authored-by: Jean-Michel Campin <jmc@ocean.mit.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adjoint Affects the adjoint model; label triggers full OpenAD test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants