-
Notifications
You must be signed in to change notification settings - Fork 20
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
Don't compute log10(chl) for small chl #305
Conversation
if chl <= chl_min, we already have log10(chl_min) stored as a parameter. Avoiding the computation of log10(chl) in those cases prevents the possibility of a floating point exception, and lets us replace a max() statement with an if check so it shouldn't affect performance. This requires adding chl_min to the optics_type (which already has log10chl_min and log10chl_max).
Note that this fix will allow us to run CESM with |
testing: Verified this is bit-for-bit in a one month test run (with MARBL providing chlorophyll) |
@mnlevy1981 , do you know why this is needed in |
Huh, that's really odd. I'll add a commit to update !!! Only the surface CHL is used above in setting optics%sw_pen_band for all schemes.
!!! Seems inconsistent to use depth dependent CHL in opacity calculation. So if anything I would expect to need to update |
I see the problem you are talking about - trying to evaluate log10(chl) when chl=0 - but am not totally following the thread above. I think Mike is on track to replace that min/max compound function with an if block would be the most straight forward. The table is in log space so we need to do a two step test for chl > 0 then log10(chl) > log10_chl_min .AND. log10(chl) < log10_chl_max. lookup_ohlmann_swpen is called before lookup_ohlmann_opacity. Is that why swpen triggers error? |
In the CESM test suite, setting |
Would
|
previous commit only avoiding log10(0) in lookup_ohlmann_swpen() but we have another log10(chl) in the opacity function
@marshallward do you prefer your proposed formulation to what is currently in this PR? The |
@marshallward, does an if-block have greater performance implications and |
The short answer is that The long answer is that it's better "most of the time" to use the branchless expressions. (e.g. In this case, there's a lot of if-blocks outside of your function call, so it's probably not very important. I probably should have held my tongue. 😝 Apologies for any distraction! |
Thanks for the explanation. I have no complaints about learning from your knowledge and experience. |
I ran
Sidenote: is the ERI comparison failure known? It occurred while generating the baselines as well:
|
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
chl <= chl_min
, we already havelog10(chl_min)
stored as a parameter. Avoiding the computation oflog10(chl)
in those cases prevents the possibility of a floating point exception (ifchl <= 0
), and this approach replaces amax()
statement with anif
block so it shouldn't affect performance.This requires adding
chl_min
to theoptics_type
(which already haslog10chl_min
andlog10chl_max
).