From 39603156ffd79bb76879e46cc6acce23edff4209 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 22 Mar 2012 17:18:45 -0400 Subject: [PATCH] Can read binary source in parallel now. --- src/bank_header.F90 | 1 + src/source.F90 | 46 +++++++++++++++++++++++++++++++++++++++- src/utils/read_source.py | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/bank_header.F90 b/src/bank_header.F90 index 0b42aa155a..dd255c5f0b 100644 --- a/src/bank_header.F90 +++ b/src/bank_header.F90 @@ -9,6 +9,7 @@ module bank_header !=============================================================================== type Bank + sequence integer(8) :: id ! Unique ID real(8) :: xyz(3) ! location of bank particle real(8) :: uvw(3) ! diretional cosines diff --git a/src/source.F90 b/src/source.F90 index a9de74bed1..f72bb76c54 100644 --- a/src/source.F90 +++ b/src/source.F90 @@ -11,6 +11,10 @@ module source use random_lcg, only: prn, set_particle_seed use string, only: to_str +#ifdef MPI + use mpi +#endif + implicit none contains @@ -232,6 +236,45 @@ contains integer(8) :: i ! index in source_bank integer(8) :: n_sites ! number of sites in binary file +#ifdef MPI + integer :: fh ! file handle + integer(MPI_OFFSET_KIND) :: offset ! offset in memory (0=beginning of file) +#endif + +#ifdef MPI + ! ========================================================================== + ! PARALLEL I/O USING MPI-2 ROUTINES + + ! Open binary source file for reading + call MPI_FILE_OPEN(MPI_COMM_WORLD, 'source.binary', MPI_MODE_RDONLY, & + MPI_INFO_NULL, fh, mpi_err) + + offset = 0 + call MPI_FILE_READ_AT(fh, offset, n_sites, 1, MPI_INTEGER8, & + MPI_STATUS_IGNORE, mpi_err) + + ! Set proper offset for source data on this processor + offset = 8*(1 + rank*maxwork*7) + + do i = 1, work + ! Read position, angle, and energy -- note that we have used some + ! trickery here! The third argument gives the starting memory location, + ! and we have told it to read seven real(8)'s. Since xyz is only three + ! real(8)'s, it will write to the uvw and E members since those come next + ! in memory. We have guaranteed this by making the Bank type sequential. + + call MPI_FILE_READ_AT(fh, offset, source_bank(i) % xyz, 7, MPI_REAL8, & + MPI_STATUS_IGNORE, mpi_err) + offset = offset + 56 + + end do + + ! Close binary source file + call MPI_FILE_CLOSE(fh, mpi_err) + +#else + ! ========================================================================== + ! SERIAL I/O USING FORTRAN INTRINSIC ROUTINES ! Open binary source file for reading open(UNIT=UNIT_SOURCE, FILE='source.binary', STATUS='old', & @@ -240,7 +283,7 @@ contains ! Read number of source sites in file read(UNIT=UNIT_SOURCE) n_sites - do i = 1, maxwork + do i = 1, work ! Set ID for source site source_bank(i) % id = i ! bank_first + i - 1 @@ -251,6 +294,7 @@ contains ! Close binary source file close(UNIT=UNIT_SOURCE) +#endif end subroutine read_source_binary diff --git a/src/utils/read_source.py b/src/utils/read_source.py index 6da8ff5008..dc43be9dfa 100755 --- a/src/utils/read_source.py +++ b/src/utils/read_source.py @@ -8,7 +8,7 @@ class SourceFile(object): self.f = open(filename, 'r') # Read number of source sites - self.n_sites = struct.unpack('l', self.f.read(8))[0] + self.n_sites = struct.unpack('q', self.f.read(8))[0] # Create list to store source sites self.sites = []