Skip to content

Commit

Permalink
Merge pull request #1823 from GEOS-ESM/feature/mathomp4/fixes-for-nvidia
Browse files Browse the repository at this point in the history
Fixes for NVIDIA
  • Loading branch information
mathomp4 authored Nov 17, 2022
2 parents 1b2034e + b597aab commit b5fea99
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 45 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Defined real64 constants in consistent way
- Workarounds for NVIDIA compiler

### Added

Expand Down
55 changes: 29 additions & 26 deletions pfio/NetCDF4_FileFormatter.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module pFIO_NetCDF4_FileFormatterMod
procedure :: ___SUB(put_var,real64,2)
procedure :: ___SUB(put_var,real64,3)
procedure :: ___SUB(put_var,real64,4)


generic :: get_var => ___SUB(get_var,int32,0)
generic :: get_var => ___SUB(get_var,int32,1)
Expand Down Expand Up @@ -123,7 +123,7 @@ module pFIO_NetCDF4_FileFormatterMod
generic :: put_var => ___SUB(put_var,real64,4)

#include "undo_overload.macro"

procedure, private :: def_dimensions
procedure, private :: put_attributes
procedure, private :: put_var_attributes
Expand Down Expand Up @@ -165,7 +165,7 @@ subroutine create(this, file, unusable, mode, rc)
case (pFIO_NOCLOBBER)
mode_ = NF90_NOCLOBBER
end select

!$omp critical
status = nf90_create(file, IOR(mode_, NF90_NETCDF4), this%ncid)
!$omp end critical
Expand Down Expand Up @@ -315,10 +315,10 @@ subroutine write(this, cf, unusable, rc)

call this%def_variables(cf, rc=status)
_VERIFY(status)

call this%put_attributes(cf, NF90_GLOBAL, rc=status)
_VERIFY(status)

!$omp critical
status= nf90_enddef(this%ncid)
!$omp end critical
Expand Down Expand Up @@ -347,7 +347,7 @@ subroutine def_dimensions(this, cf, unusable, rc)
integer, pointer :: dim_len

integer :: nf90_len

dims => cf%get_dimensions()
iter = dims%begin()
do while (iter /= dims%end())
Expand Down Expand Up @@ -396,7 +396,7 @@ subroutine put_attributes(this, cf, varid, unusable, rc)
p_attribute => iter%value()
shp = p_attribute%get_shape()

if (size(shp) > 0) then
if (size(shp) > 0) then
attr_values => p_attribute%get_values()
_ASSERT(associated(attr_values), "should have values")

Expand Down Expand Up @@ -506,7 +506,7 @@ subroutine write_const_variables(this, cf, unusable, rc)
status = _FAILURE
end select
end if
call var_iter%next()
call var_iter%next()
enddo

_UNUSED_DUMMY(unusable)
Expand Down Expand Up @@ -557,7 +557,7 @@ subroutine write_coordinate_variables(this, cf, unusable, rc)
status = _FAILURE
end select
end if
call var_iter%next()
call var_iter%next()

enddo

Expand Down Expand Up @@ -613,7 +613,7 @@ subroutine put_var_attributes(this, var, varid, unusable, rc)
!$omp critical
status = nf90_put_att(this%ncid, varid, attr_name, q)
!$omp end critical
type is (stringWrap)
type is (stringWrap)
!$omp critical
status = nf90_put_att(this%ncid, varid, attr_name, q%value)
!$omp end critical
Expand Down Expand Up @@ -722,7 +722,7 @@ subroutine def_variables(this, cf, unusable, rc)
end if

deflation = var%get_deflation()
if (deflation > 0) then
if (deflation > 0) then
!$omp critical
status = nf90_def_var_deflate(this%ncid, varid, 1, 1, deflation)
!$omp end critical
Expand All @@ -731,7 +731,7 @@ subroutine def_variables(this, cf, unusable, rc)

call this%put_var_attributes(var, varid, rc=status)
_VERIFY(status)

deallocate(dimids)

call var_iter%next()
Expand Down Expand Up @@ -795,7 +795,7 @@ integer function get_fio_type(xtype, rc) result(fio_type)

return
end function get_fio_type

function read(this, unusable, rc) result(cf)
type (FileMetadata), target :: cf
class (NetCDF4_FileFormatter), intent(inout) :: this
Expand Down Expand Up @@ -860,7 +860,7 @@ subroutine inq_attributes(this, cf, varid, unusable, rc)
integer, optional, intent(out) :: rc

integer :: status

integer :: attnum, nAttributes
integer :: xtype
integer :: len
Expand Down Expand Up @@ -929,7 +929,7 @@ subroutine inq_attributes(this, cf, varid, unusable, rc)
deallocate(str)
case (NF90_STRING)
! W.Y. Note: pfio only supports global string attributes.
! varid is not passed in. NC_GLOBAL is used inside the call
! varid is not passed in. NC_GLOBAL is used inside the call
!$omp critical
status = pfio_get_att_string(this%ncid, trim(attr_name), str)
!$omp end critical
Expand All @@ -939,7 +939,7 @@ subroutine inq_attributes(this, cf, varid, unusable, rc)
case default
_RETURN(_FAILURE)
end select

end do

_RETURN(_SUCCESS)
Expand All @@ -955,7 +955,7 @@ subroutine inq_var_attributes(this, var, varid, unusable, rc)
integer, optional, intent(out) :: rc

integer :: status

integer :: attnum, nAttributes
integer :: xtype
integer :: len
Expand Down Expand Up @@ -1039,7 +1039,7 @@ subroutine inq_var_attributes(this, var, varid, unusable, rc)
_UNUSED_DUMMY(unusable)
end subroutine inq_var_attributes


subroutine inq_variables(this, cf, unusable, rc)
class (NetCDF4_FileFormatter), intent(inout) :: this
type (FileMetadata), target, intent(inout) :: cf
Expand Down Expand Up @@ -1068,6 +1068,8 @@ subroutine inq_variables(this, cf, unusable, rc)
integer :: iotype
type(Variable) :: v

integer :: fio_type
type(Variable) :: concrete_var

!$omp critical
status = nf90_inquire(this%ncid, nVariables=nVariables)
Expand All @@ -1079,7 +1081,7 @@ subroutine inq_variables(this, cf, unusable, rc)
status = nf90_inquire_variable(this%ncid, varid, name=var_name, xtype=xtype, ndims=ndims)
!$omp end critical
_VERIFY(status)

allocate(dimids(ndims))
!$omp critical
status = nf90_inquire_variable(this%ncid, varid, dimids=dimids)
Expand Down Expand Up @@ -1143,8 +1145,9 @@ subroutine inq_variables(this, cf, unusable, rc)
allocate(var, source=CoordinateVariable(v, coordinate_data))
deallocate(coordinate_data)
else
allocate(var, source=Variable(type= get_fio_type(xtype,rc=status), dimensions=dim_string))
_VERIFY(status)
Fio_type = get_fio_type(xtype, rc=status); _VERIFY(status)
Concrete_var = Variable(type=fio_type, dimensions=dim_string)
Allocate(var, source=concrete_var)
end if

call this%inq_var_attributes(var, varid, rc=status)
Expand Down Expand Up @@ -1228,7 +1231,7 @@ end subroutine inq_variables
# include "NetCDF4_put_var.H"
# undef _RANK
#undef _VARTYPE

! REAL64
#define _VARTYPE 5
# define _RANK 0
Expand All @@ -1252,8 +1255,8 @@ end subroutine inq_variables
# include "NetCDF4_put_var.H"
# undef _RANK
#undef _VARTYPE


#undef _TYPE


Expand All @@ -1272,7 +1275,7 @@ integer function inq_dim(this, dim_name, unusable, rc) result(length)
status = nf90_inq_dimid(this%ncid, name=dim_name, dimid=dimid)
!$omp end critical
_VERIFY(status)

length = 0
!$omp critical
status = nf90_inquire_dimension(this%ncid, dimid, len=length)
Expand All @@ -1298,7 +1301,7 @@ logical function is_coordinate_dimension(this, name)

! Sucess means that a dimension exists of the name name
is_coordinate_dimension = (status == 0)

end function is_coordinate_dimension

end module pFIO_NetCDF4_FileFormatterMod
Expand Down
Loading

0 comments on commit b5fea99

Please sign in to comment.