Remove work_index on Fortran side

This commit is contained in:
Paul Romano 2018-10-15 07:45:26 -05:00
parent bbccbf436d
commit 242895e99b
7 changed files with 29 additions and 71 deletions

View file

@ -9,10 +9,8 @@
namespace openmc {
extern "C" void write_source_bank(hid_t group_id, int64_t* work_index,
Bank* source_bank);
extern "C" void read_source_bank(hid_t group_id, int64_t* work_index,
Bank* source_bank);
extern "C" void write_source_bank(hid_t group_id, Bank* source_bank);
extern "C" void read_source_bank(hid_t group_id, Bank* source_bank);
extern "C" void write_tally_results_nr(hid_t file_id);

View file

@ -383,9 +383,6 @@ contains
! Set up tally procedure pointers
call init_tally_routines()
! Determine how much work each processor should do
call calculate_work()
! Allocate source bank, and for eigenvalue simulations also allocate the
! fission bank
call allocate_banks()
@ -516,46 +513,6 @@ contains
end function openmc_simulation_finalize
!===============================================================================
! CALCULATE_WORK determines how many particles each processor should simulate
!===============================================================================
subroutine calculate_work()
integer :: i ! loop index
integer :: remainder ! Number of processors with one extra particle
integer(8) :: i_bank ! Running count of number of particles
integer(8) :: min_work ! Minimum number of particles on each proc
integer(8) :: work_i ! Number of particles on rank i
if (.not. allocated(work_index)) allocate(work_index(0:n_procs))
! Determine minimum amount of particles to simulate on each processor
min_work = n_particles/n_procs
! Determine number of processors that have one extra particle
remainder = int(mod(n_particles, int(n_procs,8)), 4)
i_bank = 0
work_index(0) = 0
do i = 0, n_procs - 1
! Number of particles for rank i
if (i < remainder) then
work_i = min_work + 1
else
work_i = min_work
end if
! Set number of particles
if (rank == i) work = work_i
! Set index into source bank for rank i
i_bank = i_bank + work_i
work_index(i+1) = i_bank
end do
end subroutine calculate_work
!===============================================================================
! ALLOCATE_BANKS allocates memory for the fission and source banks
!===============================================================================

View file

@ -162,5 +162,6 @@ extern "C" double k_generation(int i) { return simulation::k_generation.at(i - 1
extern "C" int k_generation_size() { return simulation::k_generation.size(); }
extern "C" void k_generation_clear() { simulation::k_generation.clear(); }
extern "C" void k_generation_reserve(int i) { simulation::k_generation.reserve(i); }
extern "C" int64_t work_index(int rank) { return simulation::work_index[rank]; }
} // namespace openmc

View file

@ -32,7 +32,6 @@ module simulation_header
logical(C_BOOL), bind(C) :: satisfy_triggers ! whether triggers are satisfied
integer(C_INT64_T), bind(C) :: work ! number of particles per processor
integer(C_INT64_T), allocatable :: work_index(:) ! starting index in source bank for each process
integer(C_INT64_T), bind(C) :: current_work ! index in source bank of current history simulated
! ============================================================================
@ -89,6 +88,12 @@ module simulation_header
import C_INT
integer(C_INT), value :: i
end subroutine
function work_index(rank) result(i) bind(C)
import C_INT, C_INT64_T
integer(C_INT), value :: rank
integer(C_INT64_T) :: i
end function
end interface
contains
@ -99,8 +104,6 @@ contains
subroutine free_memory_simulation()
if (allocated(work_index)) deallocate(work_index)
call k_generation_clear()
call entropy_clear()
end subroutine free_memory_simulation

View file

@ -264,7 +264,7 @@ void initialize_source()
}
// Read in the source bank
read_source_bank(file_id, simulation::work_index.data(), source_bank);
read_source_bank(file_id, source_bank);
// Close file
file_close(file_id);
@ -287,7 +287,7 @@ void initialize_source()
write_message("Writing out initial source...", 5);
std::string filename = settings::path_output + "initial_source.h5";
hid_t file_id = file_open(filename, 'w', true);
write_source_bank(file_id, simulation::work_index.data(), source_bank);
write_source_bank(file_id, source_bank);
file_close(file_id);
}
}

View file

@ -36,17 +36,15 @@ module state_point
implicit none
interface
subroutine write_source_bank(group_id, work_index, bank_) bind(C)
subroutine write_source_bank(group_id, bank_) bind(C)
import HID_T, C_INT64_T, Bank
integer(HID_T), value :: group_id
integer(C_INT64_T), intent(in) :: work_index(*)
type(Bank), intent(in) :: bank_(*)
end subroutine write_source_bank
subroutine read_source_bank(group_id, work_index, bank_) bind(C)
subroutine read_source_bank(group_id, bank_) bind(C)
import HID_T, C_INT64_T, Bank
integer(HID_T), value :: group_id
integer(C_INT64_T), intent(in) :: work_index(*)
type(Bank), intent(out) :: bank_(*)
end subroutine read_source_bank
end interface
@ -440,7 +438,7 @@ contains
if (master .or. parallel) then
file_id = file_open(filename_, 'a', parallel=.true.)
end if
call write_source_bank(file_id, work_index, source_bank)
call write_source_bank(file_id, source_bank)
if (master .or. parallel) call file_close(file_id)
end if
end function openmc_statepoint_write
@ -478,7 +476,7 @@ contains
file_id = file_open(filename_, 'w', parallel=.true.)
call write_attribute(file_id, "filetype", 'source')
end if
call write_source_bank(file_id, work_index, source_bank)
call write_source_bank(file_id, source_bank)
if (master .or. parallel) call file_close(file_id)
end subroutine write_source_point
@ -684,7 +682,7 @@ contains
end if
! Write out source
call read_source_bank(file_id, work_index, source_bank)
call read_source_bank(file_id, source_bank)
end if

View file

@ -38,7 +38,7 @@ hid_t h5banktype() {
void
write_source_bank(hid_t group_id, int64_t* work_index, Bank* source_bank)
write_source_bank(hid_t group_id, Bank* source_bank)
{
hid_t banktype = h5banktype();
@ -54,7 +54,7 @@ write_source_bank(hid_t group_id, int64_t* work_index, Bank* source_bank)
hid_t memspace = H5Screate_simple(1, count, nullptr);
// Select hyperslab for this dataspace
hsize_t start[] {static_cast<hsize_t>(work_index[openmc::mpi::rank])};
hsize_t start[] {static_cast<hsize_t>(simulation::work_index[mpi::rank])};
H5Sselect_hyperslab(dspace, H5S_SELECT_SET, start, nullptr, count, nullptr);
// Set up the property list for parallel writing
@ -84,21 +84,22 @@ write_source_bank(hid_t group_id, int64_t* work_index, Bank* source_bank)
std::vector<Bank> temp_source {source_bank, source_bank + simulation::work};
#endif
for (int i = 0; i < openmc::mpi::n_procs; ++i) {
for (int i = 0; i < mpi::n_procs; ++i) {
// Create memory space
hsize_t count[] {static_cast<hsize_t>(work_index[i+1] - work_index[i])};
hsize_t count[] {static_cast<hsize_t>(simulation::work_index[i+1] -
simulation::work_index[i])};
hid_t memspace = H5Screate_simple(1, count, nullptr);
#ifdef OPENMC_MPI
// Receive source sites from other processes
if (i > 0)
MPI_Recv(source_bank, count[0], openmc::mpi::bank, i, i,
openmc::mpi::intracomm, MPI_STATUS_IGNORE);
MPI_Recv(source_bank, count[0], mpi::bank, i, i,
mpi::intracomm, MPI_STATUS_IGNORE);
#endif
// Select hyperslab for this dataspace
dspace = H5Dget_space(dset);
hsize_t start[] {static_cast<hsize_t>(work_index[i])};
hsize_t start[] {static_cast<hsize_t>(simulation::work_index[i])};
H5Sselect_hyperslab(dspace, H5S_SELECT_SET, start, nullptr, count, nullptr);
// Write data to hyperslab
@ -117,8 +118,8 @@ write_source_bank(hid_t group_id, int64_t* work_index, Bank* source_bank)
#endif
} else {
#ifdef OPENMC_MPI
MPI_Send(source_bank, simulation::work, openmc::mpi::bank, 0, openmc::mpi::rank,
openmc::mpi::intracomm);
MPI_Send(source_bank, simulation::work, mpi::bank, 0, mpi::rank,
mpi::intracomm);
#endif
}
#endif
@ -127,7 +128,7 @@ write_source_bank(hid_t group_id, int64_t* work_index, Bank* source_bank)
}
void read_source_bank(hid_t group_id, int64_t* work_index, Bank* source_bank)
void read_source_bank(hid_t group_id, Bank* source_bank)
{
hid_t banktype = h5banktype();
@ -142,13 +143,13 @@ void read_source_bank(hid_t group_id, int64_t* work_index, Bank* source_bank)
hid_t dspace = H5Dget_space(dset);
hsize_t dims_all[1];
H5Sget_simple_extent_dims(dspace, dims_all, nullptr);
if (work_index[openmc::mpi::n_procs] > dims_all[0]) {
if (simulation::work_index[mpi::n_procs] > dims_all[0]) {
fatal_error("Number of source sites in source file is less "
"than number of source particles per generation.");
}
// Select hyperslab for each process
hsize_t start[] {static_cast<hsize_t>(work_index[openmc::mpi::rank])};
hsize_t start[] {static_cast<hsize_t>(simulation::work_index[mpi::rank])};
H5Sselect_hyperslab(dspace, H5S_SELECT_SET, start, nullptr, dims, nullptr);
#ifdef PHDF5