From 242895e99bbe9f76e050146d8a38f00230c05e40 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 15 Oct 2018 07:45:26 -0500 Subject: [PATCH] Remove work_index on Fortran side --- include/openmc/state_point.h | 6 ++--- src/simulation.F90 | 43 ------------------------------------ src/simulation.cpp | 1 + src/simulation_header.F90 | 9 +++++--- src/source.cpp | 4 ++-- src/state_point.F90 | 12 +++++----- src/state_point.cpp | 25 +++++++++++---------- 7 files changed, 29 insertions(+), 71 deletions(-) diff --git a/include/openmc/state_point.h b/include/openmc/state_point.h index 6541a67fc..058edc09c 100644 --- a/include/openmc/state_point.h +++ b/include/openmc/state_point.h @@ -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); diff --git a/src/simulation.F90 b/src/simulation.F90 index b94166f87..0d6c534f1 100644 --- a/src/simulation.F90 +++ b/src/simulation.F90 @@ -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 !=============================================================================== diff --git a/src/simulation.cpp b/src/simulation.cpp index 0d94966ed..13fe6fa50 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -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 diff --git a/src/simulation_header.F90 b/src/simulation_header.F90 index 65a36654f..1844c8da6 100644 --- a/src/simulation_header.F90 +++ b/src/simulation_header.F90 @@ -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 diff --git a/src/source.cpp b/src/source.cpp index 1290c5f0d..3427579ee 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -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); } } diff --git a/src/state_point.F90 b/src/state_point.F90 index f861f871a..52b01557d 100644 --- a/src/state_point.F90 +++ b/src/state_point.F90 @@ -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 diff --git a/src/state_point.cpp b/src/state_point.cpp index 4bd91e121..2383a5ed1 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -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(work_index[openmc::mpi::rank])}; + hsize_t start[] {static_cast(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 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(work_index[i+1] - work_index[i])}; + hsize_t count[] {static_cast(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(work_index[i])}; + hsize_t start[] {static_cast(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(work_index[openmc::mpi::rank])}; + hsize_t start[] {static_cast(simulation::work_index[mpi::rank])}; H5Sselect_hyperslab(dspace, H5S_SELECT_SET, start, nullptr, dims, nullptr); #ifdef PHDF5