Re: Astronomys` Sixth Neighbour Needs Help [message #35876] |
Fri, 25 July 2003 06:23  |
robert.dimeo
Messages: 42 Registered: November 2001
|
Member |
|
|
touser2001@yahoo.com (astronomer) wrote in message news:<c2959ed8.0307240506.1136eacd@posting.google.com>...
> Basically, the program reads a 2-column n-line file (n is number of
> stars in field, the columns are the position of the stars, Right
> Ascencion and Declination which are similar to latitude and
> longitude). My objective is to obtain, for each star, the distance to
> its 6th neighbour. Simply, Right ascencsion is x and Declination is y
> on a xy grid.
>
Hi Bruno,
I tried to streamline your code and eliminate loops using as many
array operations as I could. In IDL this can significantly increase
the speed over using loops. In the code that I wrote below I used a
procedure called WHERETOMULTI.PRO that converts 1-dim indices to 2-dim
indices. You can do a search on this newsgroup for that program.
Alternatively you can wait until IDL 6.0 comes out and use the nifty
ARRAY_INDICES routine.
The following function returns the distance for the 6th nearest
neighbor given x-y coordinates in the order in which the coordinates
are given. So d6[i] is the distance to the 6th nearest neighbor for
the star located at coordinates (x[i],y[i]).
FUNCTION CALCULATE_6TH_NEIGHBOR,x,y
; Calculate all of the distances
n = n_elements(x)
u = 1+bytarr(n)
dx = u#x-x#u
dy = u#y-y#u
d = sqrt(dx^2+dy^2)
dsort = sort(d)
wheretomulti,d, dsort, col, row
; Now get the sixth neighbor
d6 = fltarr(n)
for i = 0L,n-1 do begin
index = where(col eq i)
d6[i] = d[col[index[6]],row[index[6]]]
endfor
return,d6
END
On my 1.7 GHz PC with 1 GB of ram I processed 1000 x-y pairs in 15.9
seconds. I should mention that when I tried to process 10000 x-y
pairs my machine was unable to allocate enough memory to create the
arrays. So this may not have solved your problem but it might lead
you in the right direction for how to remove loops to gain speed.
Hope this helps.
Rob
|
|
|
Re: Astronomys` Sixth Neighbour Needs Help [message #35965 is a reply to message #35876] |
Fri, 25 July 2003 14:32  |
touser2001
Messages: 8 Registered: July 2003
|
Junior Member |
|
|
AMAZING!!!!
I am extremely amazed and impressed at the increase in processing
speed that the changes made!!!!!!
I was not expecting such a change! Amazing how inefficient my program
was. Where was all the time going to? I mean, how come the for loops
made the program so slow whereas now...
I can`t thank you enough!
I managed to run a 3800 star file in under 11 minutes whereas before
it took over 24 hours. Now I am running a 9300 star file!
For the larger file I am using a dual processor computer with 1 Gb and
with 2400GHz each processor. The program sucks 99.8% of the CPU but
it is running.
I am also very surprised at how much memory is allocated to the IDL
processes. What I mean is that the whole computer would slow down
immensely, giving priority to IDL. Strange.
This is indeed a good introduction to this newsgroup! and to IDL.
Thanks Rob!
|
|
|