tlestang / heatcompact3d

3D heat equation with 6th order compact schemes
https://tlestang.github.io/heatcompact3d/
GNU General Public License v3.0
0 stars 1 forks source link

`differentiate::reverse` returns empty array with nvfortran 22.5 #10

Closed tlestang closed 1 year ago

tlestang commented 1 year ago

Which causes thomas coefficients arrays upper_diag and lower_diag in diff_nonperiodic to be of size n-2 instead of n. Surprisingly this doesn't lead to a compile time error, nor runtime error. Just a failed unit test.

Reason seems to be that reverse returns an allocatable array. MWE:

program main
  implicit none
  real :: a(4), b(4)
  real, allocatable :: c(:)

  a = [1., 2., 3., 4.]

  b = reverse(a) ! Should be (4 3 2 1)
  c = reverse(a) ! Should be (4 3 2 1)

  write(*,*) 'b is', b ! 0 0 0 0
  write(*,*) 'c is', c ! empty array

contains

  function reverse(x)
    !! Returns input array in reverse order
    !! (1 2 3 4) -> (4 3 2 1)
    real, intent(in) :: x(:)
    real, allocatable :: reverse(:)
    reverse = x(size(x):1:-1)
  end function reverse
end program main
Compilation started at Mon Jan 23 10:45:45

nvfortran test_reverse.f90 && ./a.out 
 b is    0.000000        0.000000        0.000000        0.000000    
 c is

Compilation finished at Mon Jan 23 10:45:46

Workaround is straightforward: there is actually no need for returned array to be allocatable since size(x) is known.

tlestang commented 1 year ago

Closed by 7134a9a