Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

error #7119

milenko1976
Beginner
1,013 Views
pch1.f90(17): error #7119: Any function referenced in a forall-body-stmt must have the PURE attribute explicitly declared
My code:
program pch1

implicit none
integer :: k,n_data
real :: double_sum
real,dimension(6) :: col_sum
real,dimension(6,4) :: Rdist

n_data=4
open(10,file='rd.dat',status='old')

do k=1,n_data
read(10, *) Rdist(:,k)
end do

forall(k=1:n_data)
col_sum(k) = 1.0/double_sum(Rdist(:,k))
end forall

end

Pure Function double_sum(A)
real, intent(in) :: A(:)
real :: double_sum
real(kind(1d0)) :: total
integer :: i
total = 0d0
do i=1, size(A)
total = A(i) + total
end do
double_sum = total
end function double_sum

I do not get it,atribut must be explicitly declared?
0 Kudos
4 Replies
TimP
Honored Contributor III
1,013 Views
For example, you could turn this into Fortran by putting
contains
pure function double_sum(....
...

end

and getting rid of the first conflicting declaration of double_sum.

Forall, having been introduced in f95, takes on the requirement for an f90 style explicit interface (contains, interface block, module function).

0 Kudos
mecej4
Honored Contributor III
1,013 Views
The compilation unit in Fortran is the module or subprogram, not a source file. When the compiler is processing the FORALL construct in the main program, all it knows from the declaration that you showed it is that double_sum is of type REAL. The attribute 'pure' is seen later, after the main program has been compiled.

This rule applies in general. If you have

program xx
..
x = func(y)
..
end
logical function func(yy)
..
return
end

you will see the same type of error, since func is of type REAL by default rules in the main program.
0 Kudos
milenko1976
Beginner
1,013 Views
Thanks,but now this complicates stuff a lot.
0 Kudos
milenko1976
Beginner
1,013 Views
Tim
have created module for functions,works perfect.
0 Kudos
Reply