From c677e18ecf1fecfa60dc126dd43a54cbaf1253cc Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Thu, 12 Nov 2020 07:22:49 -0300 Subject: [PATCH] INTEGRALS: Add subroutine to flush and sync specific IO unit. Signed-off-by: Grzegorz Kowal --- sources/integrals.F90 | 48 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/sources/integrals.F90 b/sources/integrals.F90 index d6d5b19..b86777a 100644 --- a/sources/integrals.F90 +++ b/sources/integrals.F90 @@ -651,7 +651,9 @@ module integrals , avarr(7), mnarr(7), mxarr(7) write(eunit,efmt) step, time, dtn, dte, maxval(errors(:)), errors(:) - call flush() + call flush_and_sync(funit) + call flush_and_sync(sunit) + call flush_and_sync(eunit) end if #ifdef PROFILE @@ -663,6 +665,50 @@ module integrals !------------------------------------------------------------------------------- ! end subroutine store_integrals +! +!=============================================================================== +! +! subroutine FLUSH_AND_SYNC: +! ----------------------- +! +! Function flushes and fsyncs the I/O buffers. +! +! Arguments: +! +! iounit - the I/O unit to flash; +! +!=============================================================================== +! + subroutine flush_and_sync(iounit) + + use iso_fortran_env, only : error_unit + + implicit none + + interface + function fsync (fd) bind(c,name="fsync") + use iso_c_binding, only: c_int + integer(c_int), value :: fd + integer(c_int) :: fsync + end function fsync + end interface + + integer, intent(in) :: iounit + + integer :: ret + +!------------------------------------------------------------------------------- +! + call flush(iounit) + + ret = fsync(fnum(iounit)) + + if (ret /= 0) & + write(error_unit,"('Error calling FSYNC for unit:',1i4)") iounit + +!------------------------------------------------------------------------------- +! + end subroutine flush_and_sync !=============================================================================== !