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

Bugfix/avoid hangs in parallel write of scalars #17

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/neasyf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
!>
!> ! Writing string scalars will automatically create a corresponding
!> ! dimension of the correct length as the trimmed string
!> call neasfy_write(ncid, "scalar_text", "Some text as a variable")
!> call neasyf_write(ncid, "scalar_text", "Some text as a variable")
!>
!> call neasyf_close(ncid)
!> ```
Expand Down Expand Up @@ -1121,6 +1121,7 @@ subroutine neasyf_write_integer_int8_rank_0(parent_id, name, values, dim_ids, di
use netcdf, only : nf90_inq_varid, nf90_def_var, nf90_put_var, nf90_put_att, &
NF90_ENOTVAR, nf90_def_dim, nf90_inq_dimid, nf90_var_par_access, &
NF90_ENOPAR, NF90_NOERR
use netcdf, only : nf90_enddef, NF90_ENOTINDEFINE
use netcdf, only : NF90_EDIMMETA
!> Name of the variable
character(len=*), intent(in) :: name
Expand Down Expand Up @@ -1216,6 +1217,10 @@ subroutine neasyf_write_integer_int8_rank_0(parent_id, name, values, dim_ids, di
varid = var_id
end if

status = nf90_enddef(parent_id)
if (.not. (status == NF90_NOERR .or. status == NF90_ENOTINDEFINE)) then
call neasyf_error(status, ncid=parent_id, var=name, varid=var_id)
end if
if (present(count)) then
if (product(count) == 0) return
end if
Expand Down Expand Up @@ -2327,6 +2332,7 @@ subroutine neasyf_write_integer_int16_rank_0(parent_id, name, values, dim_ids, d
use netcdf, only : nf90_inq_varid, nf90_def_var, nf90_put_var, nf90_put_att, &
NF90_ENOTVAR, nf90_def_dim, nf90_inq_dimid, nf90_var_par_access, &
NF90_ENOPAR, NF90_NOERR
use netcdf, only : nf90_enddef, NF90_ENOTINDEFINE
use netcdf, only : NF90_EDIMMETA
!> Name of the variable
character(len=*), intent(in) :: name
Expand Down Expand Up @@ -2422,6 +2428,10 @@ subroutine neasyf_write_integer_int16_rank_0(parent_id, name, values, dim_ids, d
varid = var_id
end if

status = nf90_enddef(parent_id)
if (.not. (status == NF90_NOERR .or. status == NF90_ENOTINDEFINE)) then
call neasyf_error(status, ncid=parent_id, var=name, varid=var_id)
end if
if (present(count)) then
if (product(count) == 0) return
end if
Expand Down Expand Up @@ -3533,6 +3543,7 @@ subroutine neasyf_write_integer_int32_rank_0(parent_id, name, values, dim_ids, d
use netcdf, only : nf90_inq_varid, nf90_def_var, nf90_put_var, nf90_put_att, &
NF90_ENOTVAR, nf90_def_dim, nf90_inq_dimid, nf90_var_par_access, &
NF90_ENOPAR, NF90_NOERR
use netcdf, only : nf90_enddef, NF90_ENOTINDEFINE
use netcdf, only : NF90_EDIMMETA
!> Name of the variable
character(len=*), intent(in) :: name
Expand Down Expand Up @@ -3628,6 +3639,10 @@ subroutine neasyf_write_integer_int32_rank_0(parent_id, name, values, dim_ids, d
varid = var_id
end if

status = nf90_enddef(parent_id)
if (.not. (status == NF90_NOERR .or. status == NF90_ENOTINDEFINE)) then
call neasyf_error(status, ncid=parent_id, var=name, varid=var_id)
end if
if (present(count)) then
if (product(count) == 0) return
end if
Expand Down Expand Up @@ -4739,6 +4754,7 @@ subroutine neasyf_write_real_real32_rank_0(parent_id, name, values, dim_ids, dim
use netcdf, only : nf90_inq_varid, nf90_def_var, nf90_put_var, nf90_put_att, &
NF90_ENOTVAR, nf90_def_dim, nf90_inq_dimid, nf90_var_par_access, &
NF90_ENOPAR, NF90_NOERR
use netcdf, only : nf90_enddef, NF90_ENOTINDEFINE
use netcdf, only : NF90_EDIMMETA
!> Name of the variable
character(len=*), intent(in) :: name
Expand Down Expand Up @@ -4834,6 +4850,10 @@ subroutine neasyf_write_real_real32_rank_0(parent_id, name, values, dim_ids, dim
varid = var_id
end if

status = nf90_enddef(parent_id)
if (.not. (status == NF90_NOERR .or. status == NF90_ENOTINDEFINE)) then
call neasyf_error(status, ncid=parent_id, var=name, varid=var_id)
end if
if (present(count)) then
if (product(count) == 0) return
end if
Expand Down Expand Up @@ -5945,6 +5965,7 @@ subroutine neasyf_write_real_real64_rank_0(parent_id, name, values, dim_ids, dim
use netcdf, only : nf90_inq_varid, nf90_def_var, nf90_put_var, nf90_put_att, &
NF90_ENOTVAR, nf90_def_dim, nf90_inq_dimid, nf90_var_par_access, &
NF90_ENOPAR, NF90_NOERR
use netcdf, only : nf90_enddef, NF90_ENOTINDEFINE
use netcdf, only : NF90_EDIMMETA
!> Name of the variable
character(len=*), intent(in) :: name
Expand Down Expand Up @@ -6040,6 +6061,10 @@ subroutine neasyf_write_real_real64_rank_0(parent_id, name, values, dim_ids, dim
varid = var_id
end if

status = nf90_enddef(parent_id)
if (.not. (status == NF90_NOERR .or. status == NF90_ENOTINDEFINE)) then
call neasyf_error(status, ncid=parent_id, var=name, varid=var_id)
end if
if (present(count)) then
if (product(count) == 0) return
end if
Expand Down Expand Up @@ -7151,6 +7176,7 @@ subroutine neasyf_write_character_rank_0(parent_id, name, values, dim_ids, dim_n
use netcdf, only : nf90_inq_varid, nf90_def_var, nf90_put_var, nf90_put_att, &
NF90_ENOTVAR, nf90_def_dim, nf90_inq_dimid, nf90_var_par_access, &
NF90_ENOPAR, NF90_NOERR
use netcdf, only : nf90_enddef, NF90_ENOTINDEFINE
!> Name of the variable
character(len=*), intent(in) :: name
!> NetCDF ID of the parent group/file
Expand Down Expand Up @@ -7230,6 +7256,10 @@ subroutine neasyf_write_character_rank_0(parent_id, name, values, dim_ids, dim_n
varid = var_id
end if

status = nf90_enddef(parent_id)
if (.not. (status == NF90_NOERR .or. status == NF90_ENOTINDEFINE)) then
call neasyf_error(status, ncid=parent_id, var=name, varid=var_id)
end if
if (present(count)) then
if (product(count) == 0) return
end if
Expand Down
9 changes: 8 additions & 1 deletion src/neasyf.in.f90
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
!>
!> ! Writing string scalars will automatically create a corresponding
!> ! dimension of the correct length as the trimmed string
!> call neasfy_write(ncid, "scalar_text", "Some text as a variable")
!> call neasyf_write(ncid, "scalar_text", "Some text as a variable")
!>
!> call neasyf_close(ncid)
!> ```
Expand Down Expand Up @@ -545,6 +545,9 @@ subroutine neasyf_write_${clean(TYPE_NAME)}$_rank_${RANK}$(parent_id, name, valu
use netcdf, only : nf90_inq_varid, nf90_def_var, nf90_put_var, nf90_put_att, &
NF90_ENOTVAR, nf90_def_dim, nf90_inq_dimid, nf90_var_par_access, &
NF90_ENOPAR, NF90_NOERR
#:if (RANK == 0)
use netcdf, only : nf90_enddef, NF90_ENOTINDEFINE
#:endif
#:if not (RANK == 0 and TYPE_NAME.startswith("character"))
use netcdf, only : NF90_EDIMMETA
#:endif
Expand Down Expand Up @@ -677,6 +680,10 @@ subroutine neasyf_write_${clean(TYPE_NAME)}$_rank_${RANK}$(parent_id, name, valu
end if

#:if RANK == 0
status = nf90_enddef(parent_id)
if (.not. (status == NF90_NOERR .or. status == NF90_ENOTINDEFINE)) then
call neasyf_error(status, ncid=parent_id, var=name, varid=var_id)
end if
if (present(count)) then
if (product(count) == 0) return
end if
Expand Down
Loading