comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Question about using an array as an index
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Question about using an array as an index [message #6486] Wed, 26 June 1996 00:00
Thomas A. McGlynn is currently offline  Thomas A. McGlynn
Messages: 23
Registered: March 1996
Junior Member
David Schwab wrote:
>
> Can anyone explain why these two codes produce different results?
>
> IDL> a=[0,1,1,2,2,2]
> IDL> b=intarr(3)
> IDL> b(a)=b(a)+1
> IDL> print,b
> 1 1 1
> and
>
> IDL> a=[0,1,1,2,2,2]
> IDL> b=intarr(3)
> IDL> for i=0,5 do b(a(i))=b(a(i))+1
> IDL> print,b
> 1 2 3
>
> Thanks!
> --
> Dr. David J. Schwab
> NOAA Great Lakes Environmental Research Laboratory
> 2205 Commonwealth Blvd.
> Ann Arbor, MI 48105
> 313-741-2120
> 313-741-2055 (FAX)

I've been caught by this one myself. Basically when you do the statment
b(a)=b(a)+1
IDL acts as if all of the additions are being carried out in parallel,
not sequentially. I imagine that in cases where you are running on
a vectorizing system the operations are made parallel in fact. Since
the operations are parallel rather than sequential each of the additions
starts with b[a] = 0 so that the result is 1. I'd be interested in
comments as to whether the result is gauranteed to be 1 or if it's possible
that on some implementations it could differ. It would be nice to
get the kind of sequential behavior you're looking for (as an option)
but I imagine this is quite non-trivial and would probably slow down the
calculation to the rate it takes in explicit loops.

Tom McGlynn
tam@silk.gsfc.nasa.gov
[Message index]
 
Read Message
Previous Topic: Somewhat off subject: Fortran for Windows 95?
Next Topic: Question about using an array as an index

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:26:21 PDT 2025

Total time taken to generate the page: 0.00484 seconds