From 65418f56b4617e45b9f38319a6525c30eec7cba1 Mon Sep 17 00:00:00 2001 From: John Tramm Date: Wed, 8 Jan 2020 19:55:34 +0000 Subject: [PATCH] changes to int64_t for event-based particle queueing variables --- CMakeLists.txt | 17 +++++++++++------ include/openmc/event.h | 20 ++++++++++---------- src/event.cpp | 42 +++++++++++++++++++++--------------------- src/simulation.cpp | 19 +++++++++---------- 4 files changed, 51 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7dfbbad6e..2f58d03d89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) # Command line options #=============================================================================== -option(openmp "Enable shared-memory parallelism with OpenMP" ON) -option(profile "Compile with profiling flags" OFF) -option(debug "Compile with debug flags" OFF) -option(optimize "Turn on all compiler optimization flags" OFF) -option(coverage "Compile with coverage analysis flags" OFF) -option(dagmc "Enable support for DAGMC (CAD) geometry" OFF) +option(openmp "Enable shared-memory parallelism with OpenMP" ON) +option(profile "Compile with profiling flags" OFF) +option(debug "Compile with debug flags" OFF) +option(optimize "Turn on all compiler optimization flags" OFF) +option(coverage "Compile with coverage analysis flags" OFF) +option(dagmc "Enable support for DAGMC (CAD) geometry" OFF) +option(event-based "Enable event-based simulation mode" OFF) #=============================================================================== # MPI for distributed-memory parallelism @@ -335,6 +336,10 @@ if(dagmc) target_include_directories(libopenmc PRIVATE ${DAGMC_INCLUDE_DIRS}) endif() +if(event-based) + target_compile_definitions(libopenmc PRIVATE EVENT_BASED) +endif() + #=============================================================================== # openmc executable #=============================================================================== diff --git a/include/openmc/event.h b/include/openmc/event.h index d66a19047e..bdcf801659 100644 --- a/include/openmc/event.h +++ b/include/openmc/event.h @@ -14,7 +14,7 @@ namespace openmc { //============================================================================== struct QueueItem{ - int idx; // particle index in event-based buffer + int64_t idx; // particle index in event-based buffer double E; // particle energy int material; // material that particle is in Particle::Type type; @@ -56,12 +56,12 @@ extern QueueItem * advance_particle_queue; extern QueueItem * surface_crossing_queue; extern QueueItem * collision_queue; extern Particle * particles; -extern int calculate_fuel_xs_queue_length; -extern int calculate_nonfuel_xs_queue_length; -extern int advance_particle_queue_length; -extern int surface_crossing_queue_length; -extern int collision_queue_length; -extern int max_particles_in_flight; +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 @@ -69,10 +69,10 @@ extern int max_particles_in_flight; // Functions //============================================================================== -void init_event_queues(int n_particles); +void init_event_queues(int64_t n_particles); void free_event_queues(void); -void dispatch_xs_event(int i); -void process_calculate_xs_events(QueueItem * queue, int n); +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(); diff --git a/src/event.cpp b/src/event.cpp index 0f6988a677..a4719694dc 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -7,7 +7,7 @@ namespace openmc { // Non-member functions //============================================================================== -void init_event_queues(int n_particles) +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]; @@ -27,10 +27,10 @@ void free_event_queues(void) delete[] simulation::particles; } -void dispatch_xs_event(int i) +void dispatch_xs_event(int64_t i) { Particle * p = simulation::particles + i; - int idx; + int64_t idx; if (p->material_ == MATERIAL_VOID) { #pragma omp atomic capture idx = simulation::calculate_nonfuel_xs_queue_length++; @@ -61,29 +61,29 @@ void dispatch_xs_event(int i) } } -void process_calculate_xs_events(QueueItem * queue, int n) +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 (int i = 0; i < n; i++) { + 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( int i = 0; i < n; i++ ) + for( auto i = 0; i < n; i++ ) { Particle * p = simulation::particles + queue[i].idx; p->event_calculate_xs_II(); } - int start = simulation::advance_particle_queue_length; - int end = start + n; - int j = 0; - for( int i = start; i < end; i++ ) + 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_; @@ -97,12 +97,12 @@ void process_calculate_xs_events(QueueItem * queue, int n) void process_advance_particle_events() { #pragma omp parallel for schedule(runtime) - for (int i = 0; i < simulation::advance_particle_queue_length; i++) { + 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 ) { - int idx; + 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; @@ -112,7 +112,7 @@ void process_advance_particle_events() } else { - int idx; + int64_t idx; #pragma omp atomic capture idx = simulation::collision_queue_length++; simulation::collision_queue[idx].idx = simulation::advance_particle_queue[i].idx; @@ -127,7 +127,7 @@ void process_advance_particle_events() void process_surface_crossing_events() { #pragma omp parallel for schedule(runtime) - for (int i = 0; i < simulation::surface_crossing_queue_length; i++) { + 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(); @@ -141,7 +141,7 @@ void process_surface_crossing_events() void process_collision_events() { #pragma omp parallel for schedule(runtime) - for (int i = 0; i < simulation::collision_queue_length; i++) { + 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(); @@ -167,13 +167,13 @@ QueueItem* collision_queue; Particle* particles; -int calculate_fuel_xs_queue_length {0}; -int calculate_nonfuel_xs_queue_length {0}; -int advance_particle_queue_length {0}; -int surface_crossing_queue_length {0}; -int collision_queue_length {0}; +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}; -int max_particles_in_flight {100000}; +int64_t max_particles_in_flight {100000}; } // namespace simulation diff --git a/src/simulation.cpp b/src/simulation.cpp index b298e47cda..6fc57f2574 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -99,8 +99,8 @@ void transport_event_based() start = get_time(); - int remaining_work = simulation::work_per_rank; - int source_offset = 0; + int64_t remaining_work = simulation::work_per_rank; + int64_t source_offset = 0; stop = get_time(); time_init += stop - start; @@ -110,16 +110,16 @@ void transport_event_based() start = get_time(); // Figure out work for this subiteration - int n_particles = std::min(remaining_work, simulation::max_particles_in_flight); + int64_t n_particles = std::min(remaining_work, simulation::max_particles_in_flight); #pragma omp parallel for schedule(runtime) - for (int i = 0; i < n_particles; i++) { + 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 (int i = 0; i < n_particles; i++) { + for (auto i = 0; i < n_particles; i++) { dispatch_xs_event(i); } @@ -129,7 +129,7 @@ void transport_event_based() int event_kernel_executions = 0; while (true) { event_kernel_executions++; - int max = std::max({ + int64_t max = std::max({ simulation::calculate_fuel_xs_queue_length, simulation::calculate_nonfuel_xs_queue_length, simulation::advance_particle_queue_length, @@ -171,7 +171,7 @@ void transport_event_based() // Finish particle track output and contribute to global tally variables #pragma omp parallel for schedule(runtime) - for (int i = 0; i < n_particles; i++) { + for (auto i = 0; i < n_particles; i++) { Particle& p = simulation::particles[i]; p.event_death(); } @@ -190,7 +190,6 @@ void transport_event_based() std::cout << "Surface Time: " << time_surf << std::endl; std::cout << "Collision Time: " << time_collision<< std::endl; } - free_event_queues(); } } // namespace openmc @@ -235,8 +234,8 @@ int openmc_simulation_init() // If doing an event-based simulatino, intialize the particle buffer // and event queues #ifdef EVENT_BASED - int event_buffer_length = std::min(simulation::work_per_rank, - simulation::max_particles_in_flight); + int64_t event_buffer_length = std::min(simulation::work_per_rank, + simulation::max_particles_in_flight); init_event_queues(event_buffer_length); #endif