Skip to content

Commit d1d0415

Browse files
committed
read large adjncy
1 parent bebcb5a commit d1d0415

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

src/generate_databases/save_arrays_solver_hdf5.F90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ subroutine save_arrays_solver_mesh_hdf5()
137137
integer(kind=8) :: sum_neighbors_adjncy, offset_neighbors_adjncy_this_proc
138138
integer(kind=8), dimension(0:NPROC-1) :: offset_neighbors_adjncy_i8
139139

140-
141140
! saves mesh file external_mesh.h5
142141
tempstr = "/external_mesh.h5"
143142
filename = LOCAL_PATH(1:len_trim(LOCAL_PATH))//trim(tempstr)

src/shared/hdf5_manager.F90

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ module manager_hdf5
194194
interface h5_read_dataset_collect_hyperslab
195195
module procedure h5_read_dataset_1d_l_collect_hyperslab ! logical
196196
module procedure h5_read_dataset_1d_i_collect_hyperslab ! integer
197+
module procedure h5_read_dataset_1d_i64_collect_hyperslab ! integer 64-bit
197198
module procedure h5_read_dataset_2d_i_collect_hyperslab
198199
module procedure h5_read_dataset_3d_i_collect_hyperslab
199200
module procedure h5_read_dataset_4d_i_collect_hyperslab
@@ -2605,7 +2606,60 @@ subroutine h5_read_dataset_1d_i_collect_hyperslab(dataset_name, data, offset_in,
26052606
call h5_close_dataset()
26062607
end subroutine h5_read_dataset_1d_i_collect_hyperslab
26072608

2609+
!
2610+
!-------------------------------------------------------------------------------
26082611
!
2612+
2613+
subroutine h5_read_dataset_1d_i64_collect_hyperslab(dataset_name, data, offset_in, if_collective)
2614+
implicit none
2615+
character(len=*), intent(in) :: dataset_name
2616+
integer, dimension(:), intent(inout), target :: data
2617+
integer(kind=8), dimension(:), intent(in) :: offset_in
2618+
logical, intent(in) :: if_collective
2619+
! local parameters
2620+
integer :: rank = 1
2621+
integer(HSIZE_T), dimension(1) :: dim
2622+
integer(HSIZE_T), dimension(1) :: count ! size of hyperslab
2623+
integer(HSSIZE_T), dimension(1) :: offset ! the position where the datablock is inserted
2624+
2625+
dim = shape(data)
2626+
offset = offset_in ! convert data type
2627+
2628+
! open dataset
2629+
call h5_open_dataset2(trim(dataset_name))
2630+
2631+
! select a place where data is inserted.
2632+
count(1) = dim(1)
2633+
2634+
! select hyperslab in the file
2635+
call h5screate_simple_f(rank,count, mem_dspace_id, error)
2636+
call check_error()
2637+
call h5dget_space_f(dataset_id, file_dspace_id, error)
2638+
call check_error()
2639+
call h5sselect_hyperslab_f(file_dspace_id, H5S_SELECT_SET_F, offset, count, error)
2640+
call check_error()
2641+
call h5_create_dataset_prop_list(if_collective)
2642+
2643+
call h5_check_arr_dim(dim)
2644+
2645+
! write array using Fortran pointer
2646+
!call h5dread_f(dataset_id, H5T_NATIVE_INTEGER, data, dim, error, &
2647+
! file_space_id=file_dspace_id, mem_space_id=mem_dspace_id, xfer_prp=plist_id)
2648+
! use F2003 API
2649+
f_ptr = c_loc(data(1))
2650+
call h5dread_f(dataset_id, H5T_NATIVE_INTEGER, f_ptr, error, &
2651+
file_space_id=file_dspace_id, mem_space_id=mem_dspace_id, xfer_prp=plist_id)
2652+
if (error /= 0) write(*,*) 'hdf5 dataset write failed for ', dataset_name
2653+
call check_error()
2654+
call h5_close_prop_list(dataset_name)
2655+
call h5sclose_f(mem_dspace_id, error)
2656+
call check_error()
2657+
call h5sclose_f(file_dspace_id, error)
2658+
call check_error()
2659+
call h5_close_dataset()
2660+
end subroutine h5_read_dataset_1d_i64_collect_hyperslab
2661+
2662+
26092663
!-------------------------------------------------------------------------------
26102664
!
26112665

src/specfem3D/read_mesh_databases_hdf5.F90

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ subroutine read_mesh_databases_hdf5()
158158
integer, dimension(0:NPROC-1) :: offset_neighbors_xadj
159159
integer, dimension(0:NPROC-1) :: offset_neighbors_adjncy
160160

161+
! avoid integer overflow
162+
integer(kind=8) :: sum_offset_neighbors_adjncy_this_proc
163+
integer(kind=8), dimension(0:NPROC-1) :: offset_neighbors_adjncy_i8
161164

162165
! user output
163166
if (myrank == 0) then
@@ -203,6 +206,8 @@ subroutine read_mesh_databases_hdf5()
203206
! mesh adjacency
204207
call h5_read_dataset_collect_hyperslab("offset_neighbors_xadj",offset_neighbors_xadj, (/0/), H5_COL)
205208
call h5_read_dataset_collect_hyperslab("offset_neighbors_adjncy",offset_neighbors_adjncy, (/0/), H5_COL)
209+
! convert to 8-byte integers
210+
offset_neighbors_adjncy_i8 = offset_neighbors_adjncy
206211

207212
! info about external mesh simulation
208213
dsetname = "nspec"
@@ -1631,8 +1636,9 @@ subroutine read_mesh_databases_hdf5()
16311636
call h5_read_dataset_collect_hyperslab(dsetname, neighbors_xadj, &
16321637
(/sum(offset_neighbors_xadj(0:myrank-1))/), H5_COL)
16331638
dsetname = "neighbors_adjncy"
1639+
sum_offset_neighbors_adjncy_this_proc = sum(offset_neighbors_adjncy_i8(0:myrank-1))
16341640
call h5_read_dataset_collect_hyperslab(dsetname, neighbors_adjncy, &
1635-
(/sum(offset_neighbors_adjncy(0:myrank-1))/), H5_COL)
1641+
(/sum_offset_neighbors_adjncy_this_proc/), H5_COL)
16361642
endif
16371643
call bcast_all_i_for_database(neighbors_xadj(1), size(neighbors_xadj))
16381644
call bcast_all_i_for_database(neighbors_adjncy(1), size(neighbors_adjncy))

0 commit comments

Comments
 (0)