vectorising versus loops [message #38146] |
Sun, 22 February 2004 10:16  |
nasalmon
Messages: 33 Registered: August 2003
|
Member |
|
|
Does anyone know what the speed increase factor is in IDL programmes
when going from "do loops" to full vectorisation of arrays? I know all
programmes are different and not every process lends itself to
vectorisation. However, there must be some rule of thumb, ie speed
going as a linear function of the number of array elements times some
factor.
Also, are there any tricks to play if you want to vectorise loops that
have IF statement decision in them, or any general rules for neat
vectorisation of looped programmes?
Many thanks,
Neil
|
|
|
|
|
Re: vectorising versus loops [message #38441 is a reply to message #38146] |
Sun, 07 March 2004 09:24   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
nasalmon@onetel.net.uk (Neil) writes:
...
>
> However, there is one small outstanding problem in the vectorisation,
> and this involves vectorisation of a routine that uses the cross or
> vector product, the IDL routine being CROSSP, generating a vector from
> the cross product of two vectors.
>
> Currently i am forced to use this in a loop, as my vectorising
> attempts (see below) have failed. The loop statement below gives the
> correct result (i being the counter of one of the outer loops):
...
Neil, how about using CROSSPN, a vectorized cross product function for
just such purposes?
Craig
P.S. http://cow.physics.wisc.edu/~craigm/idl/idl.html (under Math)
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
|
Re: vectorising versus loops [message #38725 is a reply to message #38441] |
Fri, 26 March 2004 11:34   |
nasalmon
Messages: 33 Registered: August 2003
|
Member |
|
|
Craig Markwardt <craigmnet@REMOVEcow.physics.wisc.edu> wrote in message news:<ond67ozi1w.fsf@cow.physics.wisc.edu>...
> nasalmon@onetel.net.uk (Neil) writes:
> ...
>>
>> However, there is one small outstanding problem in the vectorisation,
>> and this involves vectorisation of a routine that uses the cross or
>> vector product, the IDL routine being CROSSP, generating a vector from
>> the cross product of two vectors.
>>
>> Currently i am forced to use this in a loop, as my vectorising
>> attempts (see below) have failed. The loop statement below gives the
>> correct result (i being the counter of one of the outer loops):
> ...
>
> Neil, how about using CROSSPN, a vectorized cross product function for
> just such purposes?
>
> Craig
>
> P.S. http://cow.physics.wisc.edu/~craigm/idl/idl.html (under Math)
Well thanks very much for CROSSSP, it worked like a dream, fitted in
and sailed through perfectly.
In the main programme structure there were loops nested 4 deep, so
vectorising the inner most loop, now leaves only 3 nested loops.
Vectorisation used lots of WHERE statements. As the inner loop dealt
with vectors, inner products of these could be conveniently replaced
with matrix multiplications and transpositions.
However, the improvement factor in speed is only between of one and
five, which is small, but certainly worth having. One of the reasons
why it is this low is because there is lots of stuff in the other
loops and sometimes the inner most loop is very short, may be only 3
elements, while some of the outer loops need to munch thousands of
times.
So i was wondering whether there were any other tricks to
vectorisation that i had missed, that i could use to improve speed? I
can imagine that trying to vectorise the second to inner most loop may
be possible. Are there any strategies or special routines that could
be used in the vectorisation of loops higher in a hierarchy of loops?
many thanks,
Neil
|
|
|
Re: vectorising versus loops [message #39036 is a reply to message #38725] |
Mon, 12 April 2004 13:14  |
stimmins
Messages: 2 Registered: April 2004
|
Junior Member |
|
|
Neil:
You have a common problem with your "busy" inner or outer
loops. To save more time you need to move subsets like x = y(0:1000)
and IF statements out of the inner loops because these can really
dominate the time. If you send me your code (and an idea of how to
construct some dummy data) I will make it run faster!
Sidey Timmins (my first name rhymes with Heidi!)
|
|
|