Reduced memory usage of the fission bank sort in the average case by adding the ability to use the empty portions of the fission bank allocation for storing the sorted fission bank. The sort only does this if there is enough space, otherwise, it will allocate extra space as was done before this commit.

This commit is contained in:
John Tramm 2020-01-17 18:08:14 +00:00
parent 9f29ca9943
commit 1c497e1759

View file

@ -79,9 +79,20 @@ void sort_fission_bank()
// TODO: C++17 introduces the exclusive_scan() function which could be
// used to replace everything above this point in this function.
// We need a scratch vector to make permutation of the fission bank into
// sorted order easy. Under normal usage conditions, the fission bank is
// over provisioned, so we can use that as scratch space.
Particle::Bank* sorted_bank;
std::vector<Particle::Bank> sorted_bank_holder;
// Create temporary scratch vector for permuting the fission bank
std::vector<Particle::Bank> sorted_bank(simulation::fission_bank_length);
// If there is not enough space, allocate a temporary vector and point to it
if (simulation::fission_bank_length > simulation::fission_bank_max / 2) {
sorted_bank_holder = std::vector<Particle::Bank>(simulation::fission_bank_length);
sorted_bank = sorted_bank_holder.data();
} else { // otherwise, point sorted_bank to unused portion of the fission bank
sorted_bank = &simulation::fission_bank[simulation::fission_bank_length];
}
// Use parent and progeny indices to sort fission bank
for (int64_t i = 0; i < simulation::fission_bank_length; i++) {
@ -92,9 +103,8 @@ void sort_fission_bank()
}
// Copy sorted bank into the fission bank
for (int64_t i = 0; i < simulation::fission_bank_length; i++) {
simulation::fission_bank[i] = sorted_bank[i];
}
std::copy(sorted_bank, sorted_bank + simulation::fission_bank_length,
simulation::fission_bank.get());
}
//==============================================================================