From f1d9cef124e256cfbe2971159d75c704add8bbad Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 22 Mar 2012 18:02:50 -0400 Subject: [PATCH] Reading/writing binary source now works in parallel. --- src/source.F90 | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/source.F90 b/src/source.F90 index ab5719e20c..fb35728f7e 100644 --- a/src/source.F90 +++ b/src/source.F90 @@ -207,18 +207,50 @@ contains subroutine write_source_binary() - ! open binary source file for writing +#ifdef MPI + integer :: fh ! file handle + integer(MPI_OFFSET_KIND) :: offset ! offset in memory (0=beginning of file) + + ! ========================================================================== + ! PARALLEL I/O USING MPI-2 ROUTINES + + ! Open binary source file for reading + call MPI_FILE_OPEN(MPI_COMM_WORLD, 'source.binary', MPI_MODE_CREATE + & + MPI_MODE_WRONLY, MPI_INFO_NULL, fh, mpi_err) + + if (master) then + offset = 0 + call MPI_FILE_WRITE_AT(fh, offset, n_particles, 1, MPI_INTEGER8, & + MPI_STATUS_IGNORE, mpi_err) + end if + + ! Set proper offset for source data on this processor + offset = 8*(1 + rank*maxwork*8) + + ! Write all source sites + call MPI_FILE_WRITE_AT(fh, offset, source_bank(1), work, MPI_BANK, & + MPI_STATUS_IGNORE, mpi_err) + + ! Close binary source file + call MPI_FILE_CLOSE(fh, mpi_err) + +#else + ! ========================================================================== + ! SERIAL I/O USING FORTRAN INTRINSIC ROUTINES + + ! Open binary source file for writing open(UNIT=UNIT_SOURCE, FILE='source.binary', STATUS='replace', & ACCESS='stream') - ! write the number of particles + ! Write the number of particles write(UNIT=UNIT_SOURCE) n_particles - ! write information from the source bank + ! Write information from the source bank write(UNIT=UNIT_SOURCE) source_bank(1:work) - ! close binary source file + ! Close binary source file close(UNIT=UNIT_SOURCE) +#endif end subroutine write_source_binary