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

Adjusted loop-bounds in module_bl_gwdo.F to prevent illegal index operation. #924

Open
cponder opened this issue Aug 26, 2021 · 0 comments

Comments

@cponder
Copy link

cponder commented Aug 26, 2021

We were seeing a segfault in the module_bl_gwdo.F code when we compiled it with OpenACC directives to run on the GPU.
Likely because the GPU was enforcing array-boundaries more aggressively than the original CPU compilation would.
The problem showed up here in the transition from MPAS-A 6.x to 7.x where the loop-boundary changed but the indexing did not:

569  do k = kts+1,kpblmax-1                               |  do k = kpblmin,kpblmax                                  539
570    do i = its,ite                                          do i = its,ite                                        540
571      if (k .lt. kbl(i)) then                                 if (k .lt. kbl(i)) then                             541
572        rdelks = (prsl(i,k)-prsl(i,k+1)) * delks1(i)            rdelks    = (prsl(i,k)-prsl(i,k+1)) * delks1(i)   542
573        bnv2(i,1) = bnv2(i,1) + bnv2(i,k) * rdelks              bnv2(i,1) = bnv2(i,1) + bnv2(i,k) * rdelks        543
574        usqj(i,1) = usqj(i,1) + usqj(i,k) * rdelks              usqj(i,1) = usqj(i,1) + usqj(i,k) * rdelks        544
575      endif                                                   endif                                               545
576    enddo                                                   enddo                                                 546
577  enddo                                                   enddo      

MIchael Duda recommended this fix

133    if(present(p_top) .and. present(znu) .and. present(znw)) then
134       do k = kts,kte
135         if (znu(k).gt.0.6) kpblmax = k + 1
136       enddo
137    else
138       kpblmax = kte                                           |       kpblmax = kte-1
139    endif

which we applied to the develop-openacc branch (pull-request #922), and intend to merge into the develop branch to be in the 8.0 release.
You may want to merge this separately into the 7.x branch in order for the code to be more correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants