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 

Problem with Compiler Option /Optimise ?

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





PostPosted: Thu Sep 13, 2007 4:40 pm    Post subject: Problem with Compiler Option /Optimise ? Reply with quote

Dear All,

I have noticed a difference between the two compiler options
/Checkmate and /Optimise. Please see the following little
program with neads the input file TestData.
When compiled with /Checkmate the result is "Correct",
when compiled with /Optimise the result is "False".
The program uses the do-loop index outside the do-loop
(which should be allowed), the better solution is commented out.

Program:
Winapp

Program Test43
Implicit None

! Integer :: i, k, nUnit
Integer :: i, nUnit

nUnit = 16
Open ( Unit = nUnit , File = 'TestData' )

Do i = 1, 999
! k = i
Read ( nUnit, *, end = 100 )
End Do

100 Continue

! If ( (k-1) .eq. 3 ) Then
If ( (i-1) .eq. 3 ) Then
Write (*,*) ' "Correct" Result'
Close ( Unit = nUnit )
stop
End If

Write (*,*) ' "False" Result'
Close ( Unit = nUnit )

End Program Test43

TestData (simply 3 lines in the data file):
1
2
3

Bat file to run the program:

del comp.lis
del *.obj
del *.exe

ftn95 Test43.f95 /Optimise /link >> comp.lis
Test43.exe

Does the program violate any rules? At least, the option /Checkmate
does not indicate an error.

Best regards,
Klaus
Back to top
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Fri Sep 14, 2007 12:01 am    Post subject: Reply with quote

Klaus,

I always thought that a do-loop index should never be used outside the do-loop, although I may be wrong.

regards
John
Back to top
View user's profile Send private message Visit poster's website
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Fri Sep 14, 2007 4:39 am    Post subject: Reply with quote

Using the value of I outside the do loop is valid and often very useful, as you have done, to see where the loop stoped.

Why not simply print out the value of i when you exit the loop.

There may be something wrong with reading nothing, especially free format reads. I don't know, but /opt may differ from /check in this respect.

I'd read a variable or at least a character string.
I also prefer the more general "iostat=ierr" style of error trapping

character string*1

Read ( nUnit, fmt='(a)', iostat=ierr ) string
if (ierr /= 0) exit

John
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Sep 14, 2007 10:59 am    Post subject: Reply with quote

There is a bug in FTN95 here. You should be able to use the do loop index in this context.

The problem only occurs when using /opt on the command line and almost any change to the code (e.g. printing the value of i immediately after 100 continue) fixes the problem.

We will aim to fix the bug for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
KL
Guest





PostPosted: Fri Sep 14, 2007 11:18 am    Post subject: Problems with /Optimise ? Reply with quote

Paul,

thank you very much. I had noticed that this error does not occur, when I modify the code sligtely. So this is certainly a minor problem (but it took some time to find it out when I had more or less finished a program development and changed the compiler option to /Optimise).

Best regards,

Klaus
Back to top
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