
forums.silverfrost.com Welcome to the Silverfrost forums

View previous topic :: View next topic 
Author 
Message 
mecej4
Joined: 31 Oct 2006 Posts: 1896

Posted: Sun Jan 07, 2024 6:49 pm Post subject: FTN95 does not process ASSOCIATE construct correctly 


Paul, I do not have much experience using ASSOCIATE, and my expectations regarding what the following test program should do may be unjustified.
Code:  program cubesift
implicit none
integer, parameter :: IMAX = 4
integer :: year, i, bits
integer, parameter :: cubes(IMAX) = [ (i*i*i, i = 1, IMAX) ]
bits = 1
associate (bmask => btest(bits,[(i1, i = 1, IMAX)]))
year = sum(cubes, mask = bmask)
print '(i5, 4x,4L2)',year,bmask
end associate
end program 
FTN95 gives the output
whereas other compilers give
The array "cubes" contains [1^3, 2^3, 3^3, 4^3]. The mask array "bmask" has only the first element set to .T., so "sum" should be applied to just [1^3], yielding 1.
The FTN95compiled code appears to make "bmask" a scalar 'T', which then gets replicated three times in the expression sum(cubes, mask = bmask). As a result, "year" is evaluated as sum([1^3, 2^3, 3^3, 4^3]), i.e., 100. 

Back to top 


PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8011 Location: Salford, UK

Posted: Mon Jan 08, 2024 10:06 am Post subject: 


mecej4
Thank you for the bug report. I have logged this for investigation. 

Back to top 


PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8011 Location: Salford, UK

Posted: Thu Feb 01, 2024 12:22 pm Post subject: 


This failure has now been fixed for the next release of FTN95. 

Back to top 


mecej4
Joined: 31 Oct 2006 Posts: 1896

Posted: Thu Feb 01, 2024 1:57 pm Post subject: 


Thanks.
Here is the program from which the bug reproducer of this thread was created, if you wish to verify that the fix works on it, too.
Code: 
! Given a range of years between 1 and 13^31, list years that may be
! expressed as the sum of cubes of integers with no repetitions allowed/
! Pipe the output of the program through the system SORT utility
program cubem
implicit none
integer, parameter :: YLOW = 2020, YHIGH = 2030
integer, parameter :: IMAX = 12 ! smallest possible I s.t. (I+1)^3 > YHIGH
integer :: year, i, nk, bits
integer, parameter :: cubes(IMAX) = [ (i*i*i, i = 1, IMAX) ]
nk = 0
do bits = 1, ishft (1, IMAX)1
associate (bmask => btest(bits,[(i1, i = 1, IMAX)]))
year = sum(cubes, mask = bmask)
if (year < YLOW .or. year > YHIGH) cycle
nk = nk+1
print '(i6,4x,10i3)',year,pack([(i, i = 1, IMAX)], mask=bmask)
end associate
end do
print '(/,A,i4,A)','Found ',nk,' years that are sums of cubes'
end program 
The expected output:
Code:  2024 2 3 4 5 6 7 8 9
2025 1 2 3 4 5 6 7 8 9
2023 2 5 6 7 11
2024 1 2 5 6 7 11
Found 4 years that are sums of cubes 


Back to top 


PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8011 Location: Salford, UK

Posted: Thu Feb 01, 2024 2:37 pm Post subject: 


mecej4
Thanks. That also works. 

Back to top 




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
