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

horiz interp mixed precision #1067

Merged
merged 71 commits into from
Mar 29, 2023
Merged

Conversation

rem1776
Copy link
Contributor

@rem1776 rem1776 commented Nov 8, 2022

Description
updates horiz_interp for mixed precision and adds some derived types for both size reals
adds in explicit r4/r8 tests

How Has This Been Tested?
intel and gnu on amd

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(lon_src_1d(nlon_in), lat_src_1d(nlat_in))
allocate(lon_dst(nlon_out,nlat_out), lat_dst(nlon_out,nlat_out))
do i = 1, nlon_in
lon_src_1d(i) = (lon_in(i) + lon_in(i+1)) * 0.5
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also make numerical values of the same precision: real(0.5, FMS_HI_KIND_)

@@ -0,0 +1,818 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

How about make a separate include directory in horiz_interp for the *fh and *inc files?

end function is_lat_lon

!#####################################################################
#undef FMS_HI_KIND
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be consistent with mpp and have all the #defs and #undefs in a *.inc file. Perhaps separate *inc files for r4 and r8


!#####################################################################
#undef FMS_HI_KIND
#define FMS_HI_KIND 4
Copy link
Contributor

Choose a reason for hiding this comment

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

should use r4_kind instead of 4


end subroutine horiz_interp_bicubic_del


#undef FMS_HI_KIND
Copy link
Contributor

Choose a reason for hiding this comment

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

missing underscores for the macros

horiz_interp/horiz_interp_spherical.F90 Outdated Show resolved Hide resolved
horiz_interp/horiz_interp_spherical.F90 Outdated Show resolved Hide resolved
horiz_interp/horiz_interp_spherical.F90 Outdated Show resolved Hide resolved
horiz_interp/horiz_interp_conserve.F90 Show resolved Hide resolved
horiz_interp/include/horiz_interp.inc Outdated Show resolved Hide resolved
@@ -1473,6 +1473,7 @@ LOGICAL FUNCTION send_data_3d(diag_field_id, field, time, is_in, js_in, ks_in, &
ie_in=ie_in, je_in=je_in, ke_in=ke_in, weight=weight, err_msg=err_msg)
endif
END FUNCTION send_data_3d

Copy link
Contributor

Choose a reason for hiding this comment

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

extra line in diag_manager

@@ -102,650 +136,37 @@ subroutine horiz_interp_bicubic_init
if(module_is_initialized) return
call write_version_number("HORIZ_INTERP_BICUBIC_MOD", version)
module_is_initialized = .true.
tpi = 2.0*PI
tpi = real(2.0*PI, R8_KIND)
Copy link
Contributor

Choose a reason for hiding this comment

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

just in case .... real(2.0_r8_kind*PI, r8_kind) (pi is already r8)

end interface

!> @addtogroup horiz_interp_bilinear_mod
!> @{

real, parameter :: epsln=1.e-10
real(r8_kind), parameter :: epsln=1.d-10
Copy link
Contributor

Choose a reason for hiding this comment

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

1.e-10_r8_kind

integer, parameter :: num_nbrs_default = 4
real, parameter :: large=1.e20
real, parameter :: epsln=1.e-10
real(R8_KIND), parameter :: large=1.d20
Copy link
Contributor

Choose a reason for hiding this comment

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

d's

real, parameter :: large=1.e20
real, parameter :: epsln=1.e-10
real(R8_KIND), parameter :: large=1.d20
real(R8_KIND), parameter :: epsln=1.d-10
Copy link
Contributor

Choose a reason for hiding this comment

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

d here too

enddo
enddo

! --- area of output grid boxes ---

do n = 1, nlat_out
do m = 1, nlon_out
Interp%area_dst(m,n) = dlon_out(m) * dsph_out(n)
Interp%HI_KIND_TYPE_%area_dst(m,n) = dlon_out(m) * dsph_out(n)
Copy link
Contributor

Choose a reason for hiding this comment

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

math here too

if(dot < -1.) dot = -1.
spherical_distance = acos(dot)
if(dot > 1.0_kindl) dot = 1.0_kindl
if(dot < real(-1.d0, FMS_HI_KIND_)) dot = -1.0_kindl
Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency, 1.0_kindl

do while (continue_search .and. step_size > 0)
do while (step <= map_src_size .and. continue_search)
! count land points as nearest neighbors
d = spherical_distance(theta_dst(i,j),phi_dst(i,j),theta_src(step),phi_src(step))
d = HORIZ_INTERP_SPHERICAL_DISTANCE_(theta_dst(i,j),phi_dst(i,j),theta_src(step),phi_src(step))
Copy link
Contributor

Choose a reason for hiding this comment

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

these got changed to macros, there are several more in this subroutine

2*0.0_kindl, -1.0_kindl, 1.0_kindl, 6*0.0_kindl, -1.0_kindl, 1.0_kindl, 2*0.0_kindl, 2.0_kindl, &
-2.0_kindl, 2*0.0_kindl, -1.0_kindl, 1.0_kindl/



d1d2=d1*d2
do i=1,4
Copy link
Contributor

Choose a reason for hiding this comment

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

line 493, 0.0_kindl

real :: tavr
integer :: ipass = 0
integer, parameter :: kindl = FMS_HI_KIND_
real(FMS_HI_KIND_), parameter :: blank = real(-1.d30, FMS_HI_KIND_)
Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency, 1.e30_lkind

@rem1776
Copy link
Contributor Author

rem1776 commented Mar 24, 2023

@mlee03 this is updated now, anything I didn't comment on should be fixed.

real(HI_TEST_KIND_), allocatable, dimension(:,:) :: lat_out_2D, lon_out_2D
real(HI_TEST_KIND_), allocatable, dimension(:,:,:) :: wghts
!! array sizes and number of lat/lon per index
integer :: dlon_src, dlat_src, dlon_dst, dlat_dst
Copy link
Contributor

Choose a reason for hiding this comment

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

should be real

real(HI_TEST_KIND_), parameter :: SMALL = 1.0e-10_lkind

! set up longitude and latitude of source/destination grid.
dlon_src = (lon_src_end-lon_src_beg)/ni_src
Copy link
Contributor

Choose a reason for hiding this comment

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

real(ni_src,HI_TEST_KIND_) and below too


allocate(lon_in_1D(ni_src+1), lat_in_1D(nj_src+1))
do i = 1, ni_src+1
lon_in_1D(i) = lon_src_beg + (i-1)*dlon_src
Copy link
Contributor

Choose a reason for hiding this comment

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

real(i-1, Hi_TEST_KIND_)

@rem1776 rem1776 merged commit cdabf07 into NOAA-GFDL:mixedmode Mar 29, 2023
rem1776 added a commit to rem1776/FMS that referenced this pull request May 3, 2023
rem1776 added a commit to rem1776/FMS that referenced this pull request May 25, 2023
rem1776 added a commit that referenced this pull request Jun 2, 2023
…re, and fms_mod (#1239)

* feat: mixed precision axis_utils2 (#1104)

* feat: mixed precision fms_mod (#1147)

* feat: horiz interp mixed precision (#1067)

* mixed precision sat_vapor_pressure  (#1095)

* feat: add mixed precision axis_utils unit tests (#1172)

* fix: move type definitions to before first usage to fix nvhpc bug (#1187)

* fix: change allocatable type for intel errors (#1221)

Co-authored-by: Caitlyn McAllister <65364559+mcallic2@users.noreply.github.com>
Co-authored-by: Jesse Lentz <42011922+J-Lentz@users.noreply.github.com>
Co-authored-by: MiKyung Lee <58964324+mlee03@users.noreply.github.com>
rem1776 added a commit that referenced this pull request Jun 16, 2023
…re, and fms_mod (#1239) (#1258)

* feat: mixed precision axis_utils2 (#1104)

* feat: mixed precision fms_mod (#1147)

* feat: horiz interp mixed precision (#1067)

* mixed precision sat_vapor_pressure  (#1095)

* feat: add mixed precision axis_utils unit tests (#1172)

* fix: move type definitions to before first usage to fix nvhpc bug (#1187)

* fix: change allocatable type for intel errors (#1221)

Co-authored-by: Caitlyn McAllister <65364559+mcallic2@users.noreply.github.com>
Co-authored-by: Jesse Lentz <42011922+J-Lentz@users.noreply.github.com>
Co-authored-by: MiKyung Lee <58964324+mlee03@users.noreply.github.com>
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.

None yet

4 participants