Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add distinct passive tracer background vert diffusivity #6263

Merged
merged 3 commits into from
May 10, 2024

Conversation

maltrud
Copy link
Contributor

@maltrud maltrud commented Feb 26, 2024

Add capability to specify a different background vertical diffusivity for passive tracers than is used for active tracers. Design document is attached. Testing described in the design document with EC30to60E2r2 grid G-case was successful.

designDocumentPassiveTracerDiffusivity.pdf

[NML]
[BFB]

Copy link

github-actions bot commented Feb 26, 2024

PR Preview Action v1.4.7
🚀 Deployed preview to https://E3SM-Project.github.io/E3SM/pr-preview/pr-6263/
on branch gh-pages at 2024-05-09 21:00 UTC

@rljacob
Copy link
Member

rljacob commented Mar 21, 2024

@mark-petersen please review.

@rljacob
Copy link
Member

rljacob commented Apr 12, 2024

@maltrud since Mark is out of the office, can someone else review this?

if (trim(groupItr % memberName) /= 'activeTracers' .and. &
config_cvmix_background_diffusion_passive_enable) then
vertDiffPassiveTopOfCell = vertDiffTopOfCell - &
config_cvmix_background_diffusion + config_cvmix_background_diffusion_passive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maltrud this probably doesn't impact the simulation but this does create a nonzero diffusivity at the surface and bottom of the ocean, which I don't think we want in the code. The change should only be from k=2:maxLevelCell

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this should be in explicit loops over cells as well as k=2:maxLevelCell. Implicit indexing hides everything, and does not include the acc and openmp pragmas. The loop should look like, e.g., line 1553 in mpas_ocn_vmix.F, with all the lengthy pragmas and ifdefs around it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vanroekel and @mark-petersen thanks for finding this. I'll clean it up--array syntax has become second nature to me so going back to loops often doesn't occur to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this look correct to you? it compiled ok and I'll make sure it runs.

#ifdef MPAS_OPENACC
!$acc parallel loop gang vector collapse(3) present(vertDiffPassiveTopOfCell, vertDiffTopOfCell)
#else
!$omp parallel
!$omp do schedule(runtime) private(k, iTracer)
#endif
do iCell = 1, nCellsOwned
do k = 2, maxLevelCell(iCell)
vertDiffPassiveTopOfCell(k,iCell) = vertDiffTopOfCell(k,iCell) - &
config_cvmix_background_diffusion + config_cvmix_background_diffusion_passive
end do
end do
#ifndef MPAS_OPENACC
!$omp end do
!$omp end parallel
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the $acc directive also have maxLevelCell?

also a general question: in the loop @mark-petersen references as an example (thanks for that!) the k loop is 1:nVertLevels, not 1:maxLevelCell(iCell). I realize this is a bit different (we don't want a k=1 value for diffusivity) but why not loop over 1:maxLevelCell?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maltrud you won't be able to collapse these loops with maxLevelCell as a loop limit. For maximum parallelism, you can either use fixed loop (2:nVertLevels) and add a conditional inside (if k < maxLevelCell) or use a mask. Otherwise, you can have just one level of parallelism over cells and leave the loop limit variable. And yes, you'll need maxLevelCell in the present() list. You also need to change collapse to either (2) in the first case or remove it if you only parallelize the cell loop. Finally, you should verify that the arrays in the present() list have all been copied to the device at some point (all mesh related variables like maxLevel are always on device and vertDiffTopOfCell I think has been copied earlier, but don't know if you added VertDiffPassive...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your help, @philipwjones. I think I'll opt for limits of 2:nVertLevels and adding a conditional, though I assume that would affect vectorization. would using 'merge' help for vectorization? eg:

vertDiffPassiveTopOfCell(k,iCell) = merge( vertDiffTopOfCell(k,iCell) -....,0.0_RKIND,k<maxLevelCell(k,iCell))

how can I tell if something is present? I see $acc update host for vertDiffTopOfCell in ocn_vmix_coefs, then $acc update device after the coefficients are calculated. do I need to do something similar for vertDiffPassiveTopOfCell? I did put in $acc update host for vertDiffPassiveTopOfCell but I suspect that isn't correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maltrud it may affect CPU/vector performance but I suspect this loop has a fairly small cost anyway. The merge probably won't be any better - this is a simple enough loop the compiler should figure it out anyway and sometimes the intrinsic is actually worse. I didn't look closely at the data transfers when I wrote that last, but what you have looks correct - this is computed on the device so you just need to update the host which you've done. And you added it to the create/destroy calls in diagnostic_vars so should be fine.

!maltrud debug
do k = 1, maxLevelCell(1)
write(*,*)' DEBUG01: ',k,vertDiffPassiveTopOfCell(k,1)
enddo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing you meant to remove these debug lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vanroekel , yeah, thanks for catching that. will remove.

Copy link
Contributor

@vanroekel vanroekel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look since Mark is out of office. I think it looks good by visual inspection, just a couple of comments.

if (trim(groupItr % memberName) /= 'activeTracers' .and. &
config_cvmix_background_diffusion_passive_enable) then
vertDiffPassiveTopOfCell = vertDiffTopOfCell - &
config_cvmix_background_diffusion + config_cvmix_background_diffusion_passive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For multiple passive tracers this line of code is redundant. It could be placed above the tracer loop, but it is way up there, so for a few wasted flops this more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mark-petersen yes I debated this one in my head a bit, and also decided clarity might might be worth some redundancy. I'll make a comment in the code but leave the logic as-is if that's OK with you.

@mark-petersen
Copy link
Contributor

@maltrud, apologies for the late review. Are there instances where you would like a different background diffusion for different tracer groups, rather than a single flag for all passive tracers? That seems useful to me.

It wouldn't be too hard to make that alteration. You would change the flags config_cvmix_background_diffusion_passive and config_cvmix_background_diffusion_passive_enable to be specified for each tracer group, for example:

src/tracer_groups/Registry_CFC.xml
    <nml_option name="config_CFCTracers_background_diffusion_passive_enable" type="logical" default_value=".false."
          description="flag to enable using a different background vertical diffusion for this tracer group"
          possible_values=".true. or .false."
          />
    <nml_option name="config_CFCTracers_background_diffusion_passive" type="real" default_value="1.0e-5" units="m^2 s^-1"
          description="Background vertical diffusion applied to passive tracer quantities"
          possible_values="Any positive real value."
    />

Then you would grab that flag just before using it:

src/shared/mpas_ocn_vmix.F line 1586

         call mpas_pool_get_config(ocnConfigs, &
                 'config_use_' // groupName // '_background_diffusion_passive_enable', &
                 config_tracerGroup_background_diffusion_passive_enable)
         if (config_tracerGroup_background_diffusion_passive_enable) then

            call mpas_pool_get_config(ocnConfigs, &
                    'config_use_' // groupName // '_background_diffusion_passive', &
                    config_tracerGroup_background_diffusion_passive)

             vertDiffPassiveTopOfCell = vertDiffTopOfCell - &
                         config_cvmix_background_diffusion + config_tracerGroup_background_diffusion_passive

I think that's it, except for adding to the bld namelist scripts. Let me know what you think of that idea. Otherwise, everything looks good.

@maltrud
Copy link
Contributor Author

maltrud commented Apr 25, 2024

@mark-petersen I don't really foresee the need for each passive tracer group to have its own value of background diffusivity.

Copy link
Contributor

@mark-petersen mark-petersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maltrud, if you don't foresee the need for varying diffusivity on a per tracer basis, I'm happy with the changes you made here.

@jonbob
Copy link
Contributor

jonbob commented May 1, 2024

@vanroekel -- can you please check and make sure your concerns have been addressed?

@vanroekel
Copy link
Contributor

@jonbob it doesn't seem so. The responses to the comment look good, but they don't appear to be associated with actual code changes. Maybe I'm missing it?

@jonbob
Copy link
Contributor

jonbob commented May 1, 2024

@vanroekel -- you're absolutely correct. We'll wait for Mat to fix this

@maltrud
Copy link
Contributor Author

maltrud commented May 8, 2024

I just pushed the changes (explicit k-loop from 2:maxLevelCell(iCell)) to my branch. my test run with the changes was bit-for-bit with the case before I made the changes.

jonbob added a commit that referenced this pull request May 9, 2024
…(PR #6263)

Add distinct passive tracer background vert diffusivity

Add capability to specify a different background vertical diffusivity
for passive tracers than is used for active tracers.

[NML]
[BFB]
@jonbob
Copy link
Contributor

jonbob commented May 9, 2024

passes:

  • ERS.ne4pg2_oQU480.WCYCL1850NS.chrysalis_intel
  • SMS_D_Ld3.T62_oQU120.CMPASO-IAF.chrysalis_intel

wth expected NML DIFFs. Merged to next

@jonbob jonbob merged commit a3b6d09 into master May 10, 2024
13 checks passed
@jonbob jonbob deleted the maltrud/ocean/passive-tracer-vert-diffusion branch May 10, 2024 17:28
@jonbob
Copy link
Contributor

jonbob commented May 10, 2024

merged to master and bless requests submitted for all expected NML DIFFs

xylar added a commit to xylar/compass that referenced this pull request Jun 4, 2024
This merge updates the E3SM-Project submodule from [31e0924](https://github.com/E3SM-Project/E3SM/tree/31e0924) to [8939709](https://github.com/E3SM-Project/E3SM/tree/8939709).

This update includes the following MPAS-Ocean and MPAS-Frameworks PRs (check mark indicates bit-for-bit with previous PR in the list):
- [ ]  (ocn) E3SM-Project/E3SM#6263
- [ ]  (ocn) E3SM-Project/E3SM#6310
- [ ]  (fwk) E3SM-Project/E3SM#6427
- [ ]  (ocn) E3SM-Project/E3SM#6397
- [ ]  (ocn) E3SM-Project/E3SM#6306
- [ ]  (ocn) E3SM-Project/E3SM#6454
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants