From ed0a804d0a604a1dcca2fb4e622c3575a0229054 Mon Sep 17 00:00:00 2001 From: John Tramm Date: Mon, 13 Jan 2020 22:33:57 +0000 Subject: [PATCH] removed all event-based code from this branch --- include/openmc/event.h | 82 ------------------- src/event.cpp | 180 ----------------------------------------- src/output.cpp | 1 - src/simulation.cpp | 141 +------------------------------- 4 files changed, 1 insertion(+), 403 deletions(-) delete mode 100644 include/openmc/event.h delete mode 100644 src/event.cpp diff --git a/include/openmc/event.h b/include/openmc/event.h deleted file mode 100644 index bdcf80165..000000000 --- a/include/openmc/event.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef OPENMC_EVENT_H -#define OPENMC_EVENT_H - -#include "openmc/particle.h" -#include "openmc/tallies/filter.h" - -#include - - -namespace openmc { - -//============================================================================== -// Structs -//============================================================================== - -struct QueueItem{ - int64_t idx; // particle index in event-based buffer - double E; // particle energy - int material; // material that particle is in - Particle::Type type; - bool operator<(const QueueItem & rhs) const - { - // First, compare by type - if( type < rhs.type ) - return true; - if( type > rhs.type ) - return false; - - // At this point, we have the same particle types. - // Now, compare by material - - // TODO: Temporarily disabled as SMR problem has different material IDs for every pin - // Need to sort by material type instead... - /* - if( material < rhs.material) - return true; - if( material > rhs.material) - return false; - */ - - // At this point, we have the same particle type, in the same material. - // Now, compare by energy - return (E < rhs.E); - } -}; - -//============================================================================== -// Global variable declarations -//============================================================================== -// -namespace simulation { - -extern QueueItem * calculate_fuel_xs_queue; -extern QueueItem * calculate_nonfuel_xs_queue; -extern QueueItem * advance_particle_queue; -extern QueueItem * surface_crossing_queue; -extern QueueItem * collision_queue; -extern Particle * particles; -extern int64_t calculate_fuel_xs_queue_length; -extern int64_t calculate_nonfuel_xs_queue_length; -extern int64_t advance_particle_queue_length; -extern int64_t surface_crossing_queue_length; -extern int64_t collision_queue_length; -extern int64_t max_particles_in_flight; - -} // namespace simulation - -//============================================================================== -// Functions -//============================================================================== - -void init_event_queues(int64_t n_particles); -void free_event_queues(void); -void dispatch_xs_event(int64_t i); -void process_calculate_xs_events(QueueItem * queue, int64_t n); -void process_advance_particle_events(); -void process_surface_crossing_events(); -void process_collision_events(); - -} // namespace openmc - -#endif // OPENMC_EVENT_H diff --git a/src/event.cpp b/src/event.cpp deleted file mode 100644 index a4719694d..000000000 --- a/src/event.cpp +++ /dev/null @@ -1,180 +0,0 @@ -#include "openmc/event.h" -#include "openmc/material.h" - -namespace openmc { - -//============================================================================== -// Non-member functions -//============================================================================== - -void init_event_queues(int64_t n_particles) -{ - simulation::calculate_fuel_xs_queue = new QueueItem[n_particles]; - simulation::calculate_nonfuel_xs_queue = new QueueItem[n_particles]; - simulation::advance_particle_queue = new QueueItem[n_particles]; - simulation::surface_crossing_queue = new QueueItem[n_particles]; - simulation::collision_queue = new QueueItem[n_particles]; - simulation::particles = new Particle[n_particles]; -} - -void free_event_queues(void) -{ - delete[] simulation::calculate_fuel_xs_queue; - delete[] simulation::calculate_nonfuel_xs_queue; - delete[] simulation::advance_particle_queue; - delete[] simulation::surface_crossing_queue; - delete[] simulation::collision_queue; - delete[] simulation::particles; -} - -void dispatch_xs_event(int64_t i) -{ - Particle * p = simulation::particles + i; - int64_t idx; - if (p->material_ == MATERIAL_VOID) { - #pragma omp atomic capture - idx = simulation::calculate_nonfuel_xs_queue_length++; - simulation::calculate_nonfuel_xs_queue[idx].idx = i; - simulation::calculate_nonfuel_xs_queue[idx].E = p->E_; - simulation::calculate_nonfuel_xs_queue[idx].material = p->material_; - simulation::calculate_nonfuel_xs_queue[idx].type = p->type_; - } - else - { - if (model::materials[p->material_]->fissionable_) { - #pragma omp atomic capture - idx = simulation::calculate_fuel_xs_queue_length++; - simulation::calculate_fuel_xs_queue[idx].idx = i; - simulation::calculate_fuel_xs_queue[idx].E = p->E_; - simulation::calculate_fuel_xs_queue[idx].material = p->material_; - simulation::calculate_fuel_xs_queue[idx].type = p->type_; - } - else - { - #pragma omp atomic capture - idx = simulation::calculate_nonfuel_xs_queue_length++; - simulation::calculate_nonfuel_xs_queue[idx].idx = i; - simulation::calculate_nonfuel_xs_queue[idx].E = p->E_; - simulation::calculate_nonfuel_xs_queue[idx].material = p->material_; - simulation::calculate_nonfuel_xs_queue[idx].type = p->type_; - } - } -} - -void process_calculate_xs_events(QueueItem * queue, int64_t n) -{ - // Sort queue by energy - std::sort(queue, queue+n); - - // Save last_ members, find grid index - #pragma omp parallel for schedule(runtime) - for (auto i = 0; i < n; i++) { - Particle *p = simulation::particles + queue[i].idx; - p->event_calculate_xs_I(); - } - - #pragma omp parallel for schedule(runtime) - for( auto i = 0; i < n; i++ ) - { - Particle * p = simulation::particles + queue[i].idx; - p->event_calculate_xs_II(); - } - - int64_t start = simulation::advance_particle_queue_length; - int64_t end = start + n; - int64_t j = 0; - for( auto i = start; i < end; i++ ) - { - simulation::advance_particle_queue[i].idx = queue[j].idx; - simulation::advance_particle_queue[i].E = simulation::particles[queue[j].idx].E_; - simulation::advance_particle_queue[i].material = simulation::particles[queue[j].idx].material_; - simulation::advance_particle_queue[i].type = simulation::particles[queue[j].idx].type_; - j++; - } - simulation::advance_particle_queue_length += n; -} - -void process_advance_particle_events() -{ - #pragma omp parallel for schedule(runtime) - for (auto i = 0; i < simulation::advance_particle_queue_length; i++) { - Particle * p = simulation::particles + simulation::advance_particle_queue[i].idx; - p->event_advance(); - if( p->collision_distance_ > p->boundary_.distance ) - { - int64_t idx; - #pragma omp atomic capture - idx = simulation::surface_crossing_queue_length++; - simulation::surface_crossing_queue[idx].idx = simulation::advance_particle_queue[i].idx; - simulation::surface_crossing_queue[idx].E = p->E_; - simulation::surface_crossing_queue[idx].material = p->material_; - simulation::surface_crossing_queue[idx].type = p->type_; - } - else - { - int64_t idx; - #pragma omp atomic capture - idx = simulation::collision_queue_length++; - simulation::collision_queue[idx].idx = simulation::advance_particle_queue[i].idx; - simulation::collision_queue[idx].E = p->E_; - simulation::collision_queue[idx].material = p->material_; - simulation::collision_queue[idx].type = p->type_; - } - } - simulation::advance_particle_queue_length = 0; -} - -void process_surface_crossing_events() -{ - #pragma omp parallel for schedule(runtime) - for (auto i = 0; i < simulation::surface_crossing_queue_length; i++) { - Particle * p = simulation::particles + simulation::surface_crossing_queue[i].idx; - p->event_cross_surface(); - p->event_revive_from_secondary(); - if (p->alive_) - dispatch_xs_event(simulation::surface_crossing_queue[i].idx); - } - - simulation::surface_crossing_queue_length = 0; -} - -void process_collision_events() -{ - #pragma omp parallel for schedule(runtime) - for (auto i = 0; i < simulation::collision_queue_length; i++) { - Particle * p = simulation::particles + simulation::collision_queue[i].idx; - p->event_collide(); - p->event_revive_from_secondary(); - if (p->alive_) - dispatch_xs_event(simulation::collision_queue[i].idx); - } - - simulation::collision_queue_length = 0; -} - - -//============================================================================== -// Global variables -//============================================================================== - -namespace simulation { - -QueueItem* calculate_fuel_xs_queue; -QueueItem* calculate_nonfuel_xs_queue; -QueueItem* advance_particle_queue; -QueueItem* surface_crossing_queue; -QueueItem* collision_queue; - -Particle* particles; - -int64_t calculate_fuel_xs_queue_length {0}; -int64_t calculate_nonfuel_xs_queue_length {0}; -int64_t advance_particle_queue_length {0}; -int64_t surface_crossing_queue_length {0}; -int64_t collision_queue_length {0}; - -int64_t max_particles_in_flight {100000}; - -} // namespace simulation - -} // namespace openmc diff --git a/src/output.cpp b/src/output.cpp index 5a9d7de19..dbe1e2184 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -71,7 +71,6 @@ void title() // Write version information std::cout << - " Branch | Event-Based\n" << " | The OpenMC Monte Carlo Code\n" << " Copyright | 2011-2019 MIT and OpenMC contributors\n" << " License | http://openmc.readthedocs.io/en/latest/license.html\n" << diff --git a/src/simulation.cpp b/src/simulation.cpp index c750ed153..9bab85902 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -28,7 +28,6 @@ #include "openmc/tallies/tally_scoring.h" #include "openmc/tallies/trigger.h" #include "openmc/track_output.h" -#include "openmc/event.h" #ifdef _OPENMP #include @@ -45,20 +44,6 @@ namespace openmc { -double get_time() -{ - #ifdef _OPENMP - return omp_get_wtime(); - #endif - - #ifdef OPENMC_MPI - return MPI_Wtime(); - #endif - - unsigned long us_since_epoch = std::chrono::high_resolution_clock::now().time_since_epoch() / std::chrono::microseconds(1); - return (double) us_since_epoch / 1.0e6; -} - void transport_history_based_single_particle(Particle& p) { while(true) { @@ -86,112 +71,6 @@ void transport_history_based() } } -void transport_event_based() -{ - double stop, start; - double time_init = 0; - double time_fuel_xs = 0; - double time_nonfuel_xs = 0; - double time_advance = 0; - double time_collision = 0; - double time_surf = 0; - - - start = get_time(); - - int64_t remaining_work = simulation::work_per_rank; - int64_t source_offset = 0; - - stop = get_time(); - time_init += stop - start; - - // Subiterations to complete sets of particles - while (remaining_work > 0) { - start = get_time(); - - // Figure out work for this subiteration - int64_t n_particles = std::min(remaining_work, simulation::max_particles_in_flight); - - #pragma omp parallel for schedule(runtime) - for (auto i = 0; i < n_particles; i++) { - initialize_history(simulation::particles + i, source_offset + i + 1); - } - - // Add all particles to advance particle queue - #pragma omp parallel for schedule(runtime) - for (auto i = 0; i < n_particles; i++) { - dispatch_xs_event(i); - } - - stop = get_time(); - time_init += stop - start; - - int event_kernel_executions = 0; - while (true) { - event_kernel_executions++; - int64_t max = std::max({ - simulation::calculate_fuel_xs_queue_length, - simulation::calculate_nonfuel_xs_queue_length, - simulation::advance_particle_queue_length, - simulation::surface_crossing_queue_length, - simulation::collision_queue_length}); - if (max == 0) { - break; - } else if (max == simulation::calculate_fuel_xs_queue_length) { - start = get_time(); - process_calculate_xs_events(simulation::calculate_fuel_xs_queue, - simulation::calculate_fuel_xs_queue_length); - stop = get_time(); - time_fuel_xs += (stop-start); - simulation::calculate_fuel_xs_queue_length = 0; - } else if (max == simulation::calculate_nonfuel_xs_queue_length) { - start = get_time(); - process_calculate_xs_events(simulation::calculate_nonfuel_xs_queue, - simulation::calculate_nonfuel_xs_queue_length); - stop = get_time(); - time_nonfuel_xs += (stop-start); - simulation::calculate_nonfuel_xs_queue_length = 0; - } else if (max == simulation::advance_particle_queue_length) { - start = get_time(); - process_advance_particle_events(); - stop = get_time(); - time_advance += (stop-start); - } else if (max == simulation::surface_crossing_queue_length) { - start = get_time(); - process_surface_crossing_events(); - stop = get_time(); - time_surf += (stop-start); - } else if (max == simulation::collision_queue_length) { - start = get_time(); - process_collision_events(); - stop = get_time(); - time_collision += (stop-start); - } - } - - // Finish particle track output and contribute to global tally variables - #pragma omp parallel for schedule(runtime) - for (auto i = 0; i < n_particles; i++) { - Particle& p = simulation::particles[i]; - p.event_death(); - } - - remaining_work -= n_particles; - source_offset += n_particles; - - std::cout << "Event kernels retired: " << event_kernel_executions << std::endl; - } - if( mpi::rank == 0 ) - { - std::cout << "Particle Init Time: " << time_init << std::endl; - std::cout << "Fuel XS Time: " << time_fuel_xs << std::endl; - std::cout << "Non Fuel XS Time: " << time_nonfuel_xs << std::endl; - std::cout << "Advance Time: " << time_advance << std::endl; - std::cout << "Surface Time: " << time_surf << std::endl; - std::cout << "Collision Time: " << time_collision<< std::endl; - } -} - } // namespace openmc //============================================================================== @@ -230,14 +109,6 @@ int openmc_simulation_init() // fission bank allocate_banks(); init_shared_fission_bank(simulation::work_per_rank * 3); - - // If doing an event-based simulatino, intialize the particle buffer - // and event queues - #ifdef EVENT_BASED - int64_t event_buffer_length = std::min(simulation::work_per_rank, - simulation::max_particles_in_flight); - init_event_queues(event_buffer_length); - #endif // Allocate tally results arrays if they're not allocated yet for (auto& t : model::tallies) { @@ -322,10 +193,6 @@ int openmc_simulation_finalize() if (settings::check_overlaps) print_overlap_check(); free_shared_fission_bank(); - - #ifdef EVENT_BASED - free_event_queues(); - #endif // Reset flags simulation::need_depletion_rx = false; @@ -346,7 +213,6 @@ int openmc_next_batch(int* status) initialize_batch(); - // ======================================================================= // LOOP OVER GENERATIONS for (current_gen = 1; current_gen <= settings::gen_per_batch; ++current_gen) { @@ -356,11 +222,8 @@ int openmc_next_batch(int* status) // Start timer for transport simulation::time_transport.start(); - #ifdef EVENT_BASED - transport_event_based(); - #else + // Transport loop transport_history_based(); - #endif // Accumulate time for transport simulation::time_transport.stop(); @@ -368,9 +231,7 @@ int openmc_next_batch(int* status) finalize_generation(); } - finalize_batch(); - // Check simulation ending criteria if (status) {