From 4142dac47578e5c92d3446a5a36af1097d7fe45e Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 5 Jun 2018 23:34:18 +0200 Subject: [PATCH] Accelerated write --- src/libezfio_util.irp.f | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/libezfio_util.irp.f b/src/libezfio_util.irp.f index 358eb3b..dadc34b 100644 --- a/src/libezfio_util.irp.f +++ b/src/libezfio_util.irp.f @@ -94,6 +94,28 @@ subroutine libezfio_openz(filename,mode,err) endif end +subroutine libezfio_reopenz_unformatted(filename,mode,err) + implicit none + BEGIN_DOC +! Opens a compressed file + END_DOC + character*(*) :: filename, mode + character*(1024) :: fifo + integer :: err + fifo = trim(filename)//'.'//trim(PID_str) + err=1 + + if (mode(1:1) == 'r') then + call ezfio_error(irp_here,'Mode '//trim(mode)//' is not implemented.') + else if (mode(1:1) == 'w') then + close(unit=libezfio_iunit) + open(unit=libezfio_iunit,file=trim(fifo),form='UNFORMATTED',action='WRITE',access='STREAM',position='APPEND') + err=0 + else + call ezfio_error(irp_here,'Mode '//trim(mode)//' is not implemented.') + endif +end + subroutine libezfio_closez(filename,mode) implicit none BEGIN_DOC @@ -220,7 +242,7 @@ subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat) integer :: err integer :: i character*(1024) :: l_filename(2) - character*(32), allocatable :: buffer(:) + character*(25), allocatable :: buffer(:) if (libezfio_read_only) then call ezfio_error(irp_here,'Read-only file.') endif @@ -232,16 +254,19 @@ subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat) if (err == 0) then write(libezfio_iunit,'(I3)') rank write(libezfio_iunit,'(30(I20,X))') dims(1:rank) + close(unit=libezfio_iunit) allocate (buffer(dim_max)) !$OMP PARALLEL DO PRIVATE(i) do i=1,dim_max - write(buffer(i), %(fmt)s) dat(i) + write(buffer(i)(1:24), %(fmt)s) dat(i) + buffer(i)(25:25) = ACHAR(10) enddo !$OMP END PARALLEL DO - write(libezfio_iunit,'(A)') buffer(1:dim_max) - deallocate(buffer) + call libezfio_reopenz_unformatted(trim(l_filename(1)),'wb',err) + write(libezfio_iunit) buffer call libezfio_closez(trim(l_filename(1)),'w') + deallocate(buffer) endif call system( 'mv -f '//trim(l_filename(1))//' '//trim(l_filename(2)) ) end