From f698e9d31ca4b6bb61d65028d291952f87f2d121 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 2 Jul 2015 20:27:09 +0700 Subject: [PATCH] Rename threadprivate global tally variables and add a few comments --- src/eigenvalue.F90 | 16 ++++++++-------- src/geometry.F90 | 2 +- src/global.F90 | 23 +++++++++++++++-------- src/physics.F90 | 4 ++-- src/tracking.F90 | 6 +++--- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/eigenvalue.F90 b/src/eigenvalue.F90 index ceb65f724a..97198d5f42 100644 --- a/src/eigenvalue.F90 +++ b/src/eigenvalue.F90 @@ -175,20 +175,20 @@ contains !$omp parallel !$omp critical global_tallies(K_TRACKLENGTH) % value = & - global_tallies(K_TRACKLENGTH) % value + tally_tracklength + global_tallies(K_TRACKLENGTH) % value + global_tally_tracklength global_tallies(K_COLLISION) % value = & - global_tallies(K_COLLISION) % value + tally_collision + global_tallies(K_COLLISION) % value + global_tally_collision global_tallies(LEAKAGE) % value = & - global_tallies(LEAKAGE) % value + tally_leakage + global_tallies(LEAKAGE) % value + global_tally_leakage global_tallies(K_ABSORPTION) % value = & - global_tallies(K_ABSORPTION) % value + tally_absorption + global_tallies(K_ABSORPTION) % value + global_tally_absorption !$omp end critical ! reset private tallies - tally_tracklength = 0 - tally_collision = 0 - tally_leakage = 0 - tally_absorption = 0 + global_tally_tracklength = 0 + global_tally_collision = 0 + global_tally_leakage = 0 + global_tally_absorption = 0 !$omp end parallel #ifdef _OPENMP diff --git a/src/geometry.F90 b/src/geometry.F90 index faf4cd1d06..8f73314cbf 100644 --- a/src/geometry.F90 +++ b/src/geometry.F90 @@ -320,7 +320,7 @@ contains ! Score to global leakage tally if (tallies_on) then - tally_leakage = tally_leakage + p % wgt + global_tally_leakage = global_tally_leakage + p % wgt end if ! Display message diff --git a/src/global.F90 b/src/global.F90 index 4f57d3006d..ef183e6203 100644 --- a/src/global.F90 +++ b/src/global.F90 @@ -112,16 +112,23 @@ module global ! Global tallies ! 1) collision estimate of k-eff - ! 2) track-length estimate of k-eff - ! 3) leakage fraction + ! 2) absorption estimate of k-eff + ! 3) track-length estimate of k-eff + ! 4) leakage fraction type(TallyResult), allocatable, target :: global_tallies(:) - real(8) :: tally_tracklength = 0 - real(8) :: tally_collision = 0 - real(8) :: tally_leakage = 0 - real(8) :: tally_absorption = 0 -!$omp threadprivate(tally_tracklength, tally_collision, tally_leakage, & -!$omp& tally_absorption) + + ! It is possible to protect accumulate operations on global tallies by using + ! an atomic update. However, when multiple threads accumulate to the same + ! global tally, it can cause a higher cache miss rate due to + ! invalidation. Thus, we use threadprivate variables to accumulate global + ! tallies and then reduce at the end of a generation. + real(8) :: global_tally_collision = ZERO + real(8) :: global_tally_absorption = ZERO + real(8) :: global_tally_tracklength = ZERO + real(8) :: global_tally_leakage = ZERO +!$omp threadprivate(global_tally_collision, global_tally_absorption, & +!$omp& global_tally_tracklength, global_tally_leakage) ! Tally map structure type(TallyMap), allocatable :: tally_maps(:) diff --git a/src/physics.F90 b/src/physics.F90 index ae0a5fdd1b..706ef09548 100644 --- a/src/physics.F90 +++ b/src/physics.F90 @@ -254,7 +254,7 @@ contains ! Score implicit absorption estimate of keff if (run_mode == MODE_EIGENVALUE) then - tally_absorption = tally_absorption + p % absorb_wgt * & + global_tally_absorption = global_tally_absorption + p % absorb_wgt * & micro_xs(i_nuclide) % nu_fission / micro_xs(i_nuclide) % absorption end if else @@ -263,7 +263,7 @@ contains prn() * micro_xs(i_nuclide) % total) then ! Score absorption estimate of keff if (run_mode == MODE_EIGENVALUE) then - tally_absorption = tally_absorption + p % wgt * & + global_tally_absorption = global_tally_absorption + p % wgt * & micro_xs(i_nuclide) % nu_fission / micro_xs(i_nuclide) % absorption end if diff --git a/src/tracking.F90 b/src/tracking.F90 index b40faa314c..e5faeb209d 100644 --- a/src/tracking.F90 +++ b/src/tracking.F90 @@ -112,8 +112,8 @@ contains ! Score track-length estimate of k-eff if (run_mode == MODE_EIGENVALUE) then - tally_tracklength = tally_tracklength + p % wgt * distance * & - material_xs % nu_fission + global_tally_tracklength = global_tally_tracklength + p % wgt * & + distance * material_xs % nu_fission end if if (d_collision > d_boundary) then @@ -140,7 +140,7 @@ contains ! Score collision estimate of keff if (run_mode == MODE_EIGENVALUE) then - tally_collision = tally_collision + p % wgt * & + global_tally_collision = global_tally_collision + p % wgt * & material_xs % nu_fission / material_xs % total end if