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

mixed precision tridiagonal #1363

Merged
merged 11 commits into from
Sep 28, 2023
Merged

mixed precision tridiagonal #1363

merged 11 commits into from
Sep 28, 2023

Conversation

rem1776
Copy link
Contributor

@rem1776 rem1776 commented Sep 12, 2023

Description
mixed precision for tridiagonal mod.

For this module the optional a,b,c arguments are always required for the first call to tri_invert and are stored in the module to be used if not provided. One change to note is that the previous close_tridiagonal routine did not set init_tridiagonal to false so that was added in.

For mixed precision support, I created separate copies of these module level variables that are exclusive to calls using each kind. That behavior can then be overidden with the store_both_kinds argument so that calls with either kind will store to both module level variables. This meant adding in separate init_tridiagonal logicals for the two kinds as well. I figured this approach provides more flexibility, but we could also just simplify it and always store r8_kind. Also adds a unit test.

Fixes # (issue)

How Has This Been Tested?
oneapi 23.2 on the amd box

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • New check tests, if applicable, are included
  • make distcheck passes

allocate(TRID_REAL_TYPE%cc(size(x,1),size(x,2),size(x,3)))
!$OMP END SINGLE

TRID_REAL_TYPE%e(:,:,1) = - a(:,:,1) / b(:,:,1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Fortran question, I don't see how this works. a and b are optional arguments so if they're not present... do a and b exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its just the way this module is written. It's kind of like instead of an init routine you provide the first call to tri_invert with a,b, and c, and then those values are stored and used when the optional arguments aren't provided. It assumes a,b, and c will all be there or not at all.

I'll add present checks for b and c as well just to be safe.

tridiagonal/include/tridiagonal.inc Show resolved Hide resolved
do i=1, IN_LEN/2
end=IN_LEN-i+1
if(mod(i, 2) .eq. 1) then
ref_array(1,1,i) = -(i/2) + (mod(i,2)* IN_LEN/2)
Copy link
Contributor

Choose a reason for hiding this comment

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

real()'s needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'll add one to the whole thing but the math here (divisions) needs to done with int's so that the value * k is accurate.

ref_array = ref_array * k
! check
do i=1, IN_LEN
if(ABS(x(1,1,i) - ref_array(1,1,i)) .gt. 0.1e-12_kindl) then
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for this mismatch, answers not agreeing?

Copy link
Contributor

Choose a reason for hiding this comment

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

for i=1, is the answer supposed to be 8/9? It seems like both x and ref_array are off then hence the discrepancy

@rem1776 rem1776 marked this pull request as ready for review September 18, 2023 18:41
#endif

!> Tests the tridiagonal module routines (tri_invert and close_tridiagonal)
!! Tests reals with the kind value set above,
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps for the future TODO, FMS tridiagonal solver could be compared to the LAPACK version to check that it's implemented correctly

@mlee03
Copy link
Contributor

mlee03 commented Sep 20, 2023

Yay ready to be merged?! Woot!

test_fms/tridiagonal/test_tridiagonal.F90 Outdated Show resolved Hide resolved
@rem1776 rem1776 merged commit acc1368 into NOAA-GFDL:mixedmode Sep 28, 2023
16 of 19 checks passed
rem1776 added a commit that referenced this pull request Oct 6, 2023
* mixed precision column_diagnostics  (#1076)

* mixed precision mosaic2  (#1074)

* mixed precision topography unit tests (#1364)

* mixed precision tridiagonal (#1363)

* mixed precision: add test for coupler_types and data_override changes (#1361)

* Mixed precision `amip_interp_mod` (#1365)

BREAKING CHANGE: Several variables and arrays which were previously public have been made private.
These variables and arrays are not used in ice_amip or ocean_amip.
amip_interp_type(r4_kind) and amip_interp_type(r8_kind) should be used for
r4_kind and r8_kind precision, respectively. amip_interp_type without a kind
parameter defaults to r8_kind.

Co-authored-by: rem1776 <[email protected]>
Co-authored-by: mlee03 <[email protected]>
Co-authored-by: Caitlyn McAllister <[email protected]>
Co-authored-by: Jesse Lentz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants