replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Array constructor issue
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Array constructor issue

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Kenneth_Smith



Joined: 18 May 2012
Posts: 801
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Thu Jan 23, 2025 12:58 am    Post subject: Array constructor issue Reply with quote

Paul,

One for you to look at as I think the following code demonstrates a bug with FTN95.

Perhaps I should temper my present enthusiasum for eliminating do loops!

Code:
program p
implicit none
integer, parameter :: n = 1000
real*8 :: x(n), random_y(n), mean_y(n)
integer :: i

! Generate random data, a sample count in x, and running mean_y
call random_number(random_y)
x = [(i, i = 1, n)]

!do i = 1, n
!  mean_y(i) = sum(random_y(1:i))/x(i)
!end do

! When the do loop above is replaced by the following "equivalent code" which
! makes use of an array constructor FTN 9.06 returns the running mean values
! as all zero.
! FTN 9.03 also fails with this code. 
! Checkmate reports Error 112 Reference to undefined variable.
! All variables on the RHS have previously been assigned values.

mean_y = [(sum(random_y(1:i)) / x(i), i = 1, n)]

do i = 1, n
  print*, i, mean_y(i)
end do

end program p
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Thu Jan 23, 2025 1:50 am    Post subject: Reply with quote

Ken,

I am using Version 9.05 /64 /debug and get an access violation error on the array constructor.

I also tried the following with the same outcome.
sum_y = [ ( sum(random_y(1:i) ), i = 1, n) ]

Both work with Gfortran

A DO loop would be much quicker !

I should update to Ver 9.06 and see the result.
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 801
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Thu Jan 23, 2025 12:19 pm    Post subject: Reply with quote

John,

Thanks for confirming that there is a FTN95 issue with this

Yes, you are correct, for large n the repeated calculation of sum( random_y( 1:i ) ) will be crippling in the array constructor.

This would indeed be much faster:

Code:
acc = 0.d0
do i = 1, n, 1
  acc = acc + random_y(i)
  mean_y(i) = acc / x(i)
end do
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8182
Location: Salford, UK

PostPosted: Thu Jan 23, 2025 12:47 pm    Post subject: Reply with quote

Ken

It looks like this approach has defeated FTN95. I have made a note to investigate.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8182
Location: Salford, UK

PostPosted: Wed May 07, 2025 11:25 am    Post subject: Reply with quote

This failure has now been fixed for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 801
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Thu May 08, 2025 9:59 am    Post subject: Reply with quote

Paul,

Thanks for this and other recent fixes.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group