mirror of
https://github.com/LCPQ/quantum_package
synced 2024-12-23 21:03:56 +01:00
Move mmap.f90
This commit is contained in:
parent
39366f7ec1
commit
ac40124ac6
@ -1,72 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
|
|
||||||
|
|
||||||
void* mmap_fortran(char* filename, size_t bytes, int* file_descr, int read_only)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int fd;
|
|
||||||
int result;
|
|
||||||
void* map;
|
|
||||||
|
|
||||||
if (read_only == 1)
|
|
||||||
{
|
|
||||||
fd = open(filename, O_RDONLY, (mode_t)0600);
|
|
||||||
if (fd == -1) {
|
|
||||||
printf("%s:\n", filename);
|
|
||||||
perror("Error opening mmap file for reading");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
map = mmap(0, bytes, PROT_READ, MAP_SHARED, fd, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fd = open(filename, O_RDWR | O_CREAT, (mode_t)0600);
|
|
||||||
if (fd == -1) {
|
|
||||||
printf("%s:\n", filename);
|
|
||||||
perror("Error opening mmap file for writing");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
result = lseek(fd, bytes, SEEK_SET);
|
|
||||||
if (result == -1) {
|
|
||||||
close(fd);
|
|
||||||
printf("%s:\n", filename);
|
|
||||||
perror("Error calling lseek() to stretch the file");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
result = write(fd, "", 1);
|
|
||||||
if (result != 1) {
|
|
||||||
close(fd);
|
|
||||||
printf("%s:\n", filename);
|
|
||||||
perror("Error writing last byte of the file");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
map = mmap(0, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (map == MAP_FAILED) {
|
|
||||||
close(fd);
|
|
||||||
printf("%s:\n", filename);
|
|
||||||
perror("Error mmapping the file");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
*file_descr = fd;
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
void munmap_fortran(size_t bytes, int fd, void* map)
|
|
||||||
{
|
|
||||||
if (munmap(map, bytes) == -1) {
|
|
||||||
perror("Error un-mmapping the file");
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
module mmap_module
|
|
||||||
|
|
||||||
use iso_c_binding
|
|
||||||
|
|
||||||
interface
|
|
||||||
|
|
||||||
! File descriptors
|
|
||||||
! ----------------
|
|
||||||
|
|
||||||
type(c_ptr) function c_mmap_fortran(filename, length, fd, read_only) bind(c,name='mmap_fortran')
|
|
||||||
use iso_c_binding
|
|
||||||
character(c_char), intent(in) :: filename(*)
|
|
||||||
integer(c_size_t), intent(in), value :: length
|
|
||||||
integer(c_int), intent(out) :: fd
|
|
||||||
integer(c_int), intent(in), value :: read_only
|
|
||||||
end function
|
|
||||||
|
|
||||||
subroutine c_munmap(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
|
|
||||||
|
|
||||||
end interface
|
|
||||||
|
|
||||||
contains
|
|
||||||
|
|
||||||
subroutine mmap(filename, shape, bytes, fd, read_only, map)
|
|
||||||
use iso_c_binding
|
|
||||||
implicit none
|
|
||||||
character*(*), intent(in) :: filename ! Name of the mapped file
|
|
||||||
integer*8, intent(in) :: shape(:) ! Shape of the array to map
|
|
||||||
integer, intent(in) :: bytes ! Number of bytes per element
|
|
||||||
logical, intent(in) :: read_only ! If true, mmap is read-only
|
|
||||||
integer, intent(out) :: fd ! File descriptor
|
|
||||||
type(c_ptr), intent(out) :: map ! C Pointer
|
|
||||||
|
|
||||||
integer(c_long) :: length
|
|
||||||
integer(c_int) :: fd_
|
|
||||||
|
|
||||||
length = PRODUCT( shape(:) ) * bytes
|
|
||||||
if (read_only) then
|
|
||||||
map = c_mmap_fortran( trim(filename)//char(0), length, fd_, 1)
|
|
||||||
else
|
|
||||||
map = c_mmap_fortran( trim(filename)//char(0), length, fd_, 0)
|
|
||||||
endif
|
|
||||||
fd = fd_
|
|
||||||
end subroutine
|
|
||||||
|
|
||||||
subroutine munmap(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_long) :: length
|
|
||||||
integer(c_int) :: fd_
|
|
||||||
|
|
||||||
length = PRODUCT( shape(:) ) * bytes
|
|
||||||
fd_ = fd
|
|
||||||
call c_munmap( length, fd_, map)
|
|
||||||
end
|
|
||||||
|
|
||||||
end module mmap_module
|
|
||||||
|
|
||||||
|
|
@ -207,6 +207,7 @@ subroutine create_microlist(minilist, N_minilist, key_mask, microlist, idx_micro
|
|||||||
do j=1,n_element(1)
|
do j=1,n_element(1)
|
||||||
nt = list(j,1)
|
nt = list(j,1)
|
||||||
idx_microlist(cur_microlist(nt)) = i
|
idx_microlist(cur_microlist(nt)) = i
|
||||||
|
! TODO : Page faults
|
||||||
do k=1,Nint
|
do k=1,Nint
|
||||||
microlist(k,1,cur_microlist(nt)) = minilist(k,1,i)
|
microlist(k,1,cur_microlist(nt)) = minilist(k,1,i)
|
||||||
microlist(k,2,cur_microlist(nt)) = minilist(k,2,i)
|
microlist(k,2,cur_microlist(nt)) = minilist(k,2,i)
|
||||||
|
@ -1060,6 +1060,7 @@ subroutine i_H_psi_minilist(key,keys,idx_key,N_minilist,coef,Nint,Ndet,Ndet_max,
|
|||||||
i_in_coef = idx_key(idx(ii))
|
i_in_coef = idx_key(idx(ii))
|
||||||
!DIR$ FORCEINLINE
|
!DIR$ FORCEINLINE
|
||||||
call i_H_j(keys(1,1,i_in_key),key,Nint,hij)
|
call i_H_j(keys(1,1,i_in_key),key,Nint,hij)
|
||||||
|
! TODO : Cache misses
|
||||||
i_H_psi_array(1) = i_H_psi_array(1) + coef(i_in_coef,1)*hij
|
i_H_psi_array(1) = i_H_psi_array(1) + coef(i_in_coef,1)*hij
|
||||||
enddo
|
enddo
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
Pseudo Bitmask ZMQ Mmap
|
Pseudo Bitmask ZMQ
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Mmap
|
|
@ -623,6 +623,7 @@ subroutine search_key_big_interval(key,X,sze,idx,ibegin_in,iend_in)
|
|||||||
idx = ibegin + istep
|
idx = ibegin + istep
|
||||||
do while (istep > 16)
|
do while (istep > 16)
|
||||||
idx = ibegin + istep
|
idx = ibegin + istep
|
||||||
|
! TODO : Cache misses
|
||||||
if (cache_key < X(idx)) then
|
if (cache_key < X(idx)) then
|
||||||
iend = idx
|
iend = idx
|
||||||
istep = ishft(idx-ibegin,-1)
|
istep = ishft(idx-ibegin,-1)
|
||||||
@ -912,17 +913,17 @@ subroutine map_save_to_disk(filename,map)
|
|||||||
map % consolidated = .True.
|
map % consolidated = .True.
|
||||||
|
|
||||||
|
|
||||||
call munmap( (/ map % map_size + 2_8 /), 8, fd(1), c_pointer(1))
|
! call munmap( (/ map % map_size + 2_8 /), 8, fd(1), c_pointer(1))
|
||||||
call mmap(trim(filename)//'_consolidated_idx', (/ map % map_size + 2_8 /), 8, fd(1), .True., c_pointer(1))
|
! call mmap(trim(filename)//'_consolidated_idx', (/ map % map_size + 2_8 /), 8, fd(1), .True., c_pointer(1))
|
||||||
call c_f_pointer(c_pointer(1),map % consolidated_idx, (/ map % map_size +2_8/))
|
! call c_f_pointer(c_pointer(1),map % consolidated_idx, (/ map % map_size +2_8/))
|
||||||
|
!
|
||||||
call munmap( (/ map % n_elements /), cache_key_kind, fd(2), c_pointer(2))
|
! call munmap( (/ map % n_elements /), cache_key_kind, fd(2), c_pointer(2))
|
||||||
call mmap(trim(filename)//'_consolidated_key', (/ map % n_elements /), cache_key_kind, fd(2), .True., c_pointer(2))
|
! 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 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 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 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 /))
|
! call c_f_pointer(c_pointer(3),map % consolidated_value, (/ map % n_elements /))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user