Skip to content

Commit

Permalink
Fixed some MPI issues in new LSM
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvstratum committed Jul 21, 2020
1 parent 3f8c6ac commit 5925ee2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
63 changes: 40 additions & 23 deletions src/modlsm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1474,47 +1474,64 @@ end subroutine init_heterogeneous
! Read the input table with the (van Genuchten) soil parameters
!
subroutine read_soil_table
use modmpi, only : myid, comm3d, mpierr, mpi_logical, my_real, mpi_integer
implicit none
integer :: table_size, ncid, dimid, varid

! Open the NetCDF file and read the table size
print*,'Reading "van_genuchten_parameters.nc"'
call check( nf90_open('van_genuchten_parameters.nc', nf90_nowrite, ncid) )
call check( nf90_inq_dimid(ncid, 'index', dimid) )
call check( nf90_inquire_dimension(ncid, dimid, len=table_size) )
if (myid == 0) then
! Open the NetCDF file and read the table size
print*,'Reading "van_genuchten_parameters.nc"'
call check( nf90_open('van_genuchten_parameters.nc', nf90_nowrite, ncid) )
call check( nf90_inq_dimid(ncid, 'index', dimid) )
call check( nf90_inquire_dimension(ncid, dimid, len=table_size) )
end if

call MPI_BCAST(table_size, 1, mpi_integer, 0, comm3d, mpierr)

! Allocate variables
allocate( &
theta_res(table_size), theta_wp(table_size), theta_fc(table_size), &
theta_sat(table_size), gamma_theta_sat(table_size), &
vg_a(table_size), vg_l(table_size), vg_n(table_size) )

! Read variables
call check( nf90_inq_varid(ncid, 'theta_res', varid) )
call check( nf90_get_var(ncid, varid, theta_res) )
if (myid == 0) then
! Read variables
call check( nf90_inq_varid(ncid, 'theta_res', varid) )
call check( nf90_get_var(ncid, varid, theta_res) )

call check( nf90_inq_varid(ncid, 'theta_wp', varid) )
call check( nf90_get_var(ncid, varid, theta_wp) )

call check( nf90_inq_varid(ncid, 'theta_wp', varid) )
call check( nf90_get_var(ncid, varid, theta_wp) )
call check( nf90_inq_varid(ncid, 'theta_fc', varid) )
call check( nf90_get_var(ncid, varid, theta_fc) )

call check( nf90_inq_varid(ncid, 'theta_fc', varid) )
call check( nf90_get_var(ncid, varid, theta_fc) )
call check( nf90_inq_varid(ncid, 'theta_sat', varid) )
call check( nf90_get_var(ncid, varid, theta_sat) )

call check( nf90_inq_varid(ncid, 'theta_sat', varid) )
call check( nf90_get_var(ncid, varid, theta_sat) )
call check( nf90_inq_varid(ncid, 'gamma_sat', varid) )
call check( nf90_get_var(ncid, varid, gamma_theta_sat) )

call check( nf90_inq_varid(ncid, 'gamma_sat', varid) )
call check( nf90_get_var(ncid, varid, gamma_theta_sat) )
call check( nf90_inq_varid(ncid, 'alpha', varid) )
call check( nf90_get_var(ncid, varid, vg_a) )

call check( nf90_inq_varid(ncid, 'alpha', varid) )
call check( nf90_get_var(ncid, varid, vg_a) )
call check( nf90_inq_varid(ncid, 'l', varid) )
call check( nf90_get_var(ncid, varid, vg_l) )

call check( nf90_inq_varid(ncid, 'l', varid) )
call check( nf90_get_var(ncid, varid, vg_l) )
call check( nf90_inq_varid(ncid, 'n', varid) )
call check( nf90_get_var(ncid, varid, vg_n) )

call check( nf90_inq_varid(ncid, 'n', varid) )
call check( nf90_get_var(ncid, varid, vg_n) )
call check( nf90_close(ncid) )
end if

call check( nf90_close(ncid) )
! Broadcast to other MPI tasks
call MPI_BCAST(theta_res, table_size, my_real, 0, comm3d, mpierr)
call MPI_BCAST(theta_wp, table_size, my_real, 0, comm3d, mpierr)
call MPI_BCAST(theta_fc, table_size, my_real, 0, comm3d, mpierr)
call MPI_BCAST(theta_sat, table_size, my_real, 0, comm3d, mpierr)
call MPI_BCAST(gamma_theta_sat, table_size, my_real, 0, comm3d, mpierr)
call MPI_BCAST(vg_a, table_size, my_real, 0, comm3d, mpierr)
call MPI_BCAST(vg_l, table_size, my_real, 0, comm3d, mpierr)
call MPI_BCAST(vg_n, table_size, my_real, 0, comm3d, mpierr)

end subroutine read_soil_table

Expand Down
1 change: 1 addition & 0 deletions src/modstartup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ subroutine startup(path)
call MPI_BCAST(itot ,1,MPI_INTEGER,0,commwrld,mpierr)
call MPI_BCAST(jtot ,1,MPI_INTEGER,0,commwrld,mpierr)
call MPI_BCAST(kmax ,1,MPI_INTEGER,0,commwrld,mpierr)
call MPI_BCAST(kmax_soil ,1,MPI_INTEGER,0,commwrld,mpierr)
call MPI_BCAST(xsize ,1,MY_REAL ,0,commwrld,mpierr)
call MPI_BCAST(ysize ,1,MY_REAL ,0,commwrld,mpierr)
call MPI_BCAST(xlat ,1,MY_REAL ,0,commwrld,mpierr)
Expand Down

0 comments on commit 5925ee2

Please sign in to comment.