replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Time
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 

Time

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



Joined: 15 Jun 2006
Posts: 46

PostPosted: Mon Nov 19, 2012 4:45 am    Post subject: Time Reply with quote

Hi there,

I have some code that is called millions of times in succession, and naturally I want it to be as fast as possible. However, I have noticed something that is both *cough* interesting but above all very frustrating.

I have a file that contains structures thus:

Module Animal_hdr

Type stColours
Integer*1, Pointer i1Colour(:)
End Type stColours

Type stStripes
Type(stColours), Pointer :: pstStripe(:, :)
EndType stStripes

Type stZebras
Type(stStripes), Pointer :: pstZebra(:, :)
Integer*4 :: iOffsetLargeX, iOffsetLargeY
EndType stZebras

End Module Animal_hdr


Now, the routine that is called millions of times has the following (and more) lines in it:

!! Passed
Type(stZebras), INTENT(INOUT) :: pstZebraP

!! Locals
Type(stStripes), Pointer :: ptrZebraL
Type(stColours), Pointer :: ptrStripeL

ptrZebraL => pstZebraP%pstZebra(iyOffsetL + 1, ixOffsetL + 1)
ptrStripeL => ptrZebraL%pstStripe(iySmallIxL + 1, ixSmallIxL + 1)

and it takes around 124 seconds on my 520M Laptop to exectute 1M times.

However, if I change the above two lines for the single line:

ptrStripeL => pstZebraP%pstZebra(iyOffsetL + 1, ixOffsetL + 1) &
& %pstStripe(iySmallIxL + 1, ixSmallIxL + 1)

then it takes around 10 seconds to execute.

Not only that, if I try the trick in another place of this routine it actually slows things down, and so even though it is a mystery, I can't even follow a rule-of-thumb to get me by right now.

Any help much appreciated.

Marz

PS: I have written a small stand-alone project for the above.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Nov 19, 2012 9:25 am    Post subject: Reply with quote

Use /explist on the command line to look at the assembler code for these statements. Then use /opt to see if you can get better times.
Back to top
View user's profile Send private message AIM Address
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Mon Nov 19, 2012 4:22 pm    Post subject: Reply with quote

Now then, I used /EXPLIST and found the following:

Single-line pointing has 414 lines of code generated for it
Two-line pointing has 114 lines of code generated for it

The first 113 lines match exactly.

For two-line pointing:
1) many TEMP@XX (assume memory usage) are used
2) pointer-checking via __PCHECK is used

None of them are found in the single-line pointing assembly language for the line in question.

I assume then that the massive delays are due to
1) Memory access overhead compared to register usage
2) Pointer checking overhead

I shall attempt to research how to turn off Pointer-checking, assuming it is via !FTN95$OPTIONS(*) and/or compiler options in the IDE.

__intermediate_interrupt@ is called in both, but, as yet, have no idea what it does.

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


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

PostPosted: Mon Nov 19, 2012 4:34 pm    Post subject: Reply with quote

Are you using /CHECK? If so then this is only intended for development and can be switched off for production runs. Alternatively you might switch it off locally.
Back to top
View user's profile Send private message AIM Address
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Mon Nov 19, 2012 4:58 pm    Post subject: Reply with quote

Aha! That'll be the beauty.
I turned off everything apart from /DEBUG and, the two-pointer code ran in less than 1 second :o)

Thanks for that.

Marz


Last edited by MarzAttax on Mon Nov 19, 2012 6:03 pm; edited 1 time in total
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2923
Location: South Pole, Antarctica

PostPosted: Mon Nov 19, 2012 5:39 pm    Post subject: Reply with quote

how about removing the /debug too?
Back to top
View user's profile Send private message
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Mon Nov 19, 2012 6:03 pm    Post subject: Reply with quote

That would mean outputting the timings to a file or timing it with a stopwatch and I'm in no mood to do either :op

As far as I'm concerned my issue has been addressed. I am still surprised that such a simple change to a program can have such a dramatic impact. Slowing down that code by a factor of 12 appeared to be pure insanity at the time :o)

Marz
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2923
Location: South Pole, Antarctica

PostPosted: Mon Nov 19, 2012 6:37 pm    Post subject: Reply with quote

Well, debugging is one of the most powerhungry options, measuring speed with it has no sense.
Back to top
View user's profile Send private message
MarzAttax



Joined: 15 Jun 2006
Posts: 46

PostPosted: Mon Nov 19, 2012 6:50 pm    Post subject: Reply with quote

Hmmm, but I'm not interested in the absolute time that it takes - I am really only interested in the relative timings between the 1-line and the 2-line versions of the code. The only reason I began timing them in the first place was in order to get a measure of what was going on and for helping with the posts here.

Marz
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