| 1 |
! This gives incorrect results when compiled with |
| 2 |
! the intel and pgf90 compilers |
| 3 |
Program Strange |
| 4 |
|
| 5 |
Implicit None |
| 6 |
|
| 7 |
Type Link |
| 8 |
Integer, Dimension(2) :: Next |
| 9 |
End Type Link |
| 10 |
|
| 11 |
Integer, Parameter :: N = 2 |
| 12 |
Integer, dimension (2, 4) :: results |
| 13 |
Integer :: i, j |
| 14 |
|
| 15 |
Type(Link), Dimension(:,:), Pointer :: Perm |
| 16 |
Integer, Dimension(2) :: Current |
| 17 |
|
| 18 |
Allocate (Perm(N,N)) |
| 19 |
|
| 20 |
! Print*, 'Spanned by indices' |
| 21 |
Do i = 1, N**2 |
| 22 |
Perm(mod(i-1,N)+1, (i-1)/N+1)%Next = (/ Mod(i,N) + 1, Mod(i/N+1,N)+1/) |
| 23 |
! Write(*,100) mod(i-1,N)+1, (i-1)/N+1, Perm(mod(i-1,N)+1, (i-1)/N+1)%Next |
| 24 |
! Expected output: |
| 25 |
! Spanned by indices |
| 26 |
! 1 1---> 2 2 |
| 27 |
! 2 1---> 1 1 |
| 28 |
! 1 2---> 2 1 |
| 29 |
! 2 2---> 1 2 |
| 30 |
End Do |
| 31 |
|
| 32 |
! Print*, 'Spanned as a cycle' |
| 33 |
Current = (/1,1/) |
| 34 |
Do i = 1, n**2 |
| 35 |
results (:, i) = Perm(Current(1), Current(2))%Next |
| 36 |
! Write(*,100) Current, Perm(Current(1), Current(2))%Next |
| 37 |
! Expected output: |
| 38 |
! 1 1---> 2 2 |
| 39 |
! 2 2---> 1 2 |
| 40 |
! 1 2---> 2 1 |
| 41 |
! 2 1---> 1 1 |
| 42 |
Current = Perm(Current(1), Current(2))%Next |
| 43 |
End Do |
| 44 |
|
| 45 |
if (any(results .ne. reshape ((/2,2,1,2,2,1,1,1/), (/2, 4/)))) STOP 1 |
| 46 |
|
| 47 |
! 100 Format( 2I3, '--->', 2I3) |
| 48 |
DeAllocate (Perm) |
| 49 |
|
| 50 |
End Program Strange |