Silverfrost Forums

Welcome to our forums

FTN95: Error with FORALL

11 Sep 2005 7:03 #332

The following program produces incorrect output:

!    [JvO]         2005-09-11          Salford\SM-Err.f95

 PROGRAM comss
 IMPLICIT NONE

 integer :: j
 INTEGER, PARAMETER :: p = 8     ! Number of variables
 real, dimension(p,p) :: h
 CHARACTER(10) :: dd, tt
 CHARACTER(LEN=*), PARAMETER :: fmt1='(A/(8f8.2))', fmt2='(/T3,A,TR4,A)'

 call date_and_time(dd, tt)
 dd(5: ) = '-' // dd(5:6) // '-' // dd(7:8)
 tt(3: ) = ':' // tt(3:4) // ':' // tt(5:6)
 WRITE (*, fmt2) dd, tt

  h  =  2.25 + reshape((/ (real(j)-0.4, j=1,p**2) /), (/p,p/) )

  print fmt1, ' CM [020] H:', H(:,1), (h(j,j),j=1,p)
  FORALL (j = 1:p)      
    h(j, j) = h(j, j) + 1.125   !  Salford: ERROR
  end forall
  print fmt1, ' CM [024] H:', H(:, 1), (h(j,j),j=1,p)

 END PROGRAM comss

! D:\Fortran\Test\Salford>ftn95 /check sm-err /lgo
! [FTN95/Win32 Ver. 4.8.0 Copyright (C) Salford Software Ltd 1993-2005]
!     NO ERRORS  [<COMSS> FTN95/Win32 v4.8.0]
! Creating executable: D:\Fortran\Test\Salford\lgotemp@.exe
! Program entered

!   2005-09-11    15:34:35
!  CM [020] H:
!     2.85    3.85    4.85    5.85    6.85    7.85    8.85    9.85
!     2.85   11.85   20.85   29.85   38.85   47.85   56.85   65.85
!  CM [024] H:
!    66.97    3.85    4.85    5.85    6.85    7.85    8.85    9.85
!    66.97   66.97   66.97   66.97   66.97   66.97   66.97   66.97
! =======
!  Expected output::
!  CM [020] H:
!     2.85    3.85    4.85    5.85    6.85    7.85    8.85    9.85
!     2.85   11.85   20.85   29.85   38.85   47.85   56.85   65.85
!  CM [024] H:
!     3.98    3.85    4.85    5.85    6.85    7.85    8.85    9.85
!     3.98   12.98   21.98   30.98   39.98   48.98   57.98   66.98

[JvO]

11 Sep 2005 11:28 #334

Thanks for the information.

12 Sep 2005 7:26 #336

Another program showing incorrect FORALL (or maybe COUNT ?) I signalled this already in 2004, but not yet repaired.

!    [JvO]         2004-04-28          Count-err.f95
 program count_E
  implicit NONE
  integer :: i, j = 4, t(5, 5) = -1
  logical :: m(5, 5) = .true., x(5,5) = .false.

  m(2:3 ,  : ) = .false.   ;   m(4, 5) = .false.
  print '(5L4)', m  ; print *
  do i = 2, 4
    do j = 2, 4
      t(i,j) = count(m(i-1:i+1, j-1:j+1))
    end do
  end do
  print '(5I4)', t  ; print *
  forall (i=2:4, j=2:4, t(i,j) == 3 .or. t(i,j) == 4 .and. x(i,j) )
     x(i,j) = .true.
  end forall
  print '(5L4)', x  ; print *
  forall (i=2:4, j=2:4 )
    t(i,j) = count(m(i-1:i+1, j-1:j+1))
  end forall
  print '(5I4)', t  ; print *
 end program count_E

!  Salford [2005]: Program entered
!   T   F   F   T   T
!   T   F   F   T   T
!   T   F   F   T   T
!   T   F   F   T   T
!   T   F   F   F   T
!
!  -1  -1  -1  -1  -1
!  -1   3   3   6  -1
!  -1   3   3   6  -1
!  -1   3   2   5  -1
!  -1  -1  -1  -1  -1
!
!   F   F   F   F   F
!   F   T   T   F   F
!   F   T   T   F   F
!   F   T   F   F   F
!   F   F   F   F   F
!
!  -1  -1  -1  -1  -1
!  -1   5   5   5  -1
!  -1   5   5   5  -1
!  -1   5   5   5  -1
!  -1  -1  -1  -1  -1

[JvO]

12 Sep 2005 7:49 #337

Thank you for this.

This happens to be the same bug as your first example in this correspondance. It is a regression at version 4.8 which has now been fixed. The problem could affect may programs that use FORALL. If you encounter further problems with FORALL please go back to version 4.7 and recheck after the release of version 4.9 (coming soon).

There is an outstanding problem with FORALL (logged under your name) relating to a sample program given in the Fortran Standard. In fact this is the only reported bug that is currently outstanding.

With kind regards

Please login to reply.