Replace Kokkos::single with parallel_scan in wet_dep compute_q_tendencies#515
Draft
Replace Kokkos::single with parallel_scan in wet_dep compute_q_tendencies#515
Conversation
Copilot
AI
changed the title
[WIP] Remove Kokkos::single loop in wet_dep.hpp
Replace Kokkos::single with parallel_scan in wet_dep compute_q_tendencies
Mar 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
compute_q_tendenciesinwet_dep.hppcontained severalKokkos::single(PerTeam)regions that serialized GPU execution across the entire team for each atmospheric column.Key insight: exact parallel formula for precabs recurrence
The core
precabs/precabcrecurrenceprec[k+1] = max(rain[k], prec[k] + net[k])(wherenet = rain - evap) admits a closed-form prefix-scan solution:where
D[j] = rain[j-1] - cumnet[j]andE[j] = cumrain[j-1].This yields a 4-component scan state
(cumnet, cumrain, maxD, E_at_maxD)with an associative join:Changes
Kokkos::singleat lines 1191, 1293 (precabs/precabc recurrence): replaced withKokkos::parallel_scanusing thePrecScanStatefunctor above. Eliminates thebnddandprecabs_base_tmpintermediate workspace arrays and the two subsequent redundantparallel_fors.Kokkos::singleat lines 1535, 1631 (scavabs/scavabc linear recurrences[k+1] = a[k]*s[k] + b[k]): replaced withKokkos::parallel_scanusing affine-map composition(a₂,b₂)∘(a₁,b₁) = (a₂a₁, a₂b₁+b₂), which is associative.Kokkos::singleat lines 1265, 1360, 1569, 1664 (copy_from_prevpropagation): replaced withKokkos::parallel_scanusing aPropState {Real value; int has_value}struct wherejoin= "take right ifhas_value, else take left" — a standard segmented-fill scan.New unit test in
mam4_wet_deposition_unit_tests.cpp: runs both the original serial reference and the new parallel implementation over a representative atmospheric column, asserting element-wise relative error < 1e-8.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.