- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
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?
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks,but now this complicates stuff a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tim
have created module for functions,works perfect.
have created module for functions,works perfect.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page