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

bug: passing array section in subroutine #6324

Open
gxyd opened this issue Feb 15, 2025 · 4 comments
Open

bug: passing array section in subroutine #6324

gxyd opened this issue Feb 15, 2025 · 4 comments
Labels
POT3D Issues or pull requests related to compiling `predsci/POT3D`

Comments

@gxyd
Copy link
Contributor

gxyd commented Feb 15, 2025

Minimal Reproducible Example

For the below fortran program extracted from the POT3D repository:

module global_dims
      implicit none
      integer, parameter :: nt_g=5
      integer :: ntm1_g=4
      integer, parameter :: np_g=7
      integer :: npm1_g=6
end module

program POT3D
      use global_dims
      implicit none
      call set_flux
end program pot3d

subroutine set_flux
      use global_dims
      implicit none
      real, dimension(:,:), allocatable :: br0_g
      allocate (br0_g(nt_g,np_g))
      call readbr (br0_g)
end subroutine

subroutine readbr (br0_g)
      use global_dims
      implicit none
      real, dimension(nt_g,np_g) :: br0_g
      real :: sum0
      call intrp2d (nt_g-2,np_g-2, br0_g(2:ntm1_g,2:npm1_g))
      sum0=sum(br0_g(2,2:npm1_g))
      print *, "sum0: ", sum0
end subroutine

subroutine intrp2d (nx,ny,f)
      implicit none
      integer :: nx,ny
      real, dimension(nx,ny) :: f
      f = 2.43214264512062073e-01
      return
end subroutine

the output printed by LFortran is:

> lfortran --version
LFortran version: 0.45.0-322-g5631279ff
Platform: macOS ARM
LLVM: 19.1.7
Default target: arm64-apple-darwin23.6.0

> lfortran test.f90
sum0:     7.29642808e-01

> gfortran test.f90 -o test.o && ./test.o
 sum0:    1.21607137

I checked also for ifx compiler as well, the output produced is the same as that for GFortran compiler: https://godbolt.org/z/bEhPYnjch

@gxyd gxyd added the POT3D Issues or pull requests related to compiling `predsci/POT3D` label Feb 15, 2025
@gxyd gxyd changed the title passing array section in subroutine bug: passing array section in subroutine Feb 15, 2025
@gxyd gxyd mentioned this issue Feb 15, 2025
25 tasks
@gxyd
Copy link
Contributor Author

gxyd commented Feb 15, 2025

If we modify the snippet above (i.e. #6324 (comment)) by using the below diff:

diff --git a/test.f90 b/test.f90
index f71fa6c00..9459cff97 100644
--- a/test.f90
+++ b/test.f90
@@ -25,7 +25,11 @@ subroutine readbr (br0_g)
       implicit none
       real, dimension(nt_g,np_g) :: br0_g
       real :: sum0
-      call intrp2d (nt_g-2,np_g-2, br0_g(2:ntm1_g,2:npm1_g))
+      real, dimension(:, :), allocatable :: f
+      allocate(f(ntm1_g - 1, npm1_g-1))
+      f = br0_g(2:ntm1_g, 2:npm1_g)
+      call intrp2d (nt_g-2,np_g-2, f)
+      br0_g(2:ntm1_g, 2:npm1_g) = f
       sum0=sum(br0_g(2,2:npm1_g))
       print *, "sum0: ", sum0
 end subroutine

we get a correct print with LFortran.

@YBansal95
Copy link
Contributor

I'd like to work on this issue. Could you please elaborate a bit about what needs to be done?

@certik
Copy link
Contributor

certik commented Feb 16, 2025

Isn't this the same issue as #6214?

@gxyd
Copy link
Contributor Author

gxyd commented Feb 16, 2025

Isn't this the same issue as #6214?

Yes, I think so. I hadn't seen that issue until I opened this one, we can keep this issue open until we close that issue and then we can test this one also to see if the MRE reported here also works or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
POT3D Issues or pull requests related to compiling `predsci/POT3D`
Projects
None yet
Development

No branches or pull requests

3 participants