10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-23 04:43:50 +01:00

Fixed mmap

This commit is contained in:
Anthony Scemama 2017-07-12 23:23:46 +02:00
parent e1e786033c
commit 31efb20a18
3 changed files with 41 additions and 15 deletions

View File

@ -70,3 +70,12 @@ void munmap_fortran(size_t bytes, int fd, void* map)
} }
close(fd); close(fd);
} }
void msync_fortran(size_t bytes, int fd, void* map)
{
if (msync(map, bytes, MS_SYNC) == -1) {
perror("Error syncing the mmap file");
}
}

View File

@ -52,18 +52,14 @@ subroutine map_save_to_disk(filename,map)
map % consolidated_idx (map % map_size + 2_8) = k map % consolidated_idx (map % map_size + 2_8) = k
map % consolidated = .True. map % consolidated = .True.
integer*8 :: n_elements
n_elements = int(map % n_elements,8)
call munmap( (/ map % map_size + 2_8 /), 8, fd(1), c_pointer(1)) print *, 'Writing data to disk...'
call mmap(trim(filename)//'_consolidated_idx', (/ map % map_size + 2_8 /), 8, fd(1), .True., c_pointer(1)) call msync ( (/ map % map_size + 2_8 /), 8, fd(1), c_pointer(1))
call c_f_pointer(c_pointer(1),map % consolidated_idx, (/ map % map_size +2_8/)) call msync ( (/ n_elements /), cache_key_kind, fd(2), c_pointer(2))
call msync ( (/ n_elements /), integral_kind , fd(3), c_pointer(3))
call munmap( (/ map % n_elements /), cache_key_kind, fd(2), c_pointer(2)) print *, 'Done'
call mmap(trim(filename)//'_consolidated_key', (/ map % n_elements /), cache_key_kind, fd(2), .True., c_pointer(2))
call c_f_pointer(c_pointer(2),map % consolidated_key, (/ map % n_elements /))
call munmap( (/ map % n_elements /), integral_kind, fd(3), c_pointer(3))
call mmap(trim(filename)//'_consolidated_value', (/ map % n_elements /), integral_kind, fd(3), .True., c_pointer(3))
call c_f_pointer(c_pointer(3),map % consolidated_value, (/ map % n_elements /))
end end
@ -79,8 +75,6 @@ subroutine map_load_from_disk(filename,map)
integer*8 :: i,k,l integer*8 :: i,k,l
integer*4 :: j,n_elements integer*4 :: j,n_elements
if (map % consolidated) then if (map % consolidated) then
stop 'map already consolidated' stop 'map already consolidated'
endif endif

View File

@ -15,7 +15,14 @@ module mmap_module
integer(c_int), intent(in), value :: read_only integer(c_int), intent(in), value :: read_only
end function end function
subroutine c_munmap(length, fd, map) bind(c,name='munmap_fortran') subroutine c_munmap_fortran(length, fd, map) bind(c,name='munmap_fortran')
use iso_c_binding
integer(c_size_t), intent(in), value :: length
integer(c_int), intent(in), value :: fd
type(c_ptr), intent(in), value :: map
end subroutine
subroutine c_msync_fortran(length, fd, map) bind(c,name='msync_fortran')
use iso_c_binding use iso_c_binding
integer(c_size_t), intent(in), value :: length integer(c_size_t), intent(in), value :: length
integer(c_int), intent(in), value :: fd integer(c_int), intent(in), value :: fd
@ -61,7 +68,23 @@ module mmap_module
length = PRODUCT( shape(:) ) * bytes length = PRODUCT( shape(:) ) * bytes
fd_ = fd fd_ = fd
call c_munmap( length, fd_, map) call c_munmap_fortran( length, fd_, map)
end subroutine
subroutine msync(shape, bytes, fd, map)
use iso_c_binding
implicit none
integer*8, intent(in) :: shape(:) ! Shape of the array to map
integer, intent(in) :: bytes ! Number of bytes per element
integer, intent(in) :: fd ! File descriptor
type(c_ptr), intent(in) :: map ! C pointer
integer(c_size_t) :: length
integer(c_int) :: fd_
length = PRODUCT( shape(:) ) * bytes
fd_ = fd
call c_msync_fortran( length, fd_, map)
end subroutine end subroutine
end module mmap_module end module mmap_module