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 

FTN95 computes wrong size of array

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



Joined: 31 Oct 2006
Posts: 1692

PostPosted: Sat Mar 26, 2022 12:54 pm    Post subject: FTN95 computes wrong size of array Reply with quote

The following is a modified version of a very compact code to print out prime integers, by Arjen Markus, author of the book Modern Fortran in Practice, Cambridge, 2012 ( https://www.cambridge.org/core/books/modern-fortran-in-practice/BC5BD23B2E478B4D457C5D6265BA9363 ). The special feature of the program is the use of the PACK intrinsic to do most of the work of sifting through candidate prime numbers. The program works correctly with NAG, Intel and Gfortran, and uses the "allocate on assignment" feature of Fortran 200X.

FTN95 calculates the wrong size (2490 instead of 563) for the array multiples. As a consequence, the (over)allocated array has nearly 2000 elements undefined, which leads to program errors and aborts in the subsequent portions of the program.

Code:
program prime_sieve

    implicit none

    integer, parameter :: N = 1000, rtN = 31
    integer, parameter :: candidates(N/2) = [2,(i, i=3,N-1,2)]
    integer, allocatable :: multiples(:)
    integer, allocatable :: primes(:)
    integer            :: i, j

    multiples = [(( i*j, i=j,N/j,2), j=3,rtN,2)]  ! FTN95 signals Ref. to Undef. Var.
    print *,'size(multiples array) = ',size(multiples) ! expected: 563

    primes = pack( candidates, [(all(candidates(i) /= multiples), &
       i = 1,size(candidates))] )
    print '(A,I5,A,I5)','Found',size(primes),' primes <= ',N

end program prime_sieve
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Sat Mar 26, 2022 4:14 pm    Post subject: Reply with quote

mecej4

Thank you for the bug report which I have logged for investigation.
Back to top
View user's profile Send private message AIM Address
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