Re: a behemoth bubble sort [message #81874 is a reply to message #81855] |
Wed, 31 October 2012 00:47  |
Yngvar Larsen
Messages: 134 Registered: January 2010
|
Senior Member |
|
|
On Monday, 29 October 2012 22:24:07 UTC+1, fisch...@gmail.com wrote:
> Unfortunately, the bubble sort I've employed in this code needs to run
> through 20 billion+ data points for the program to complete, which is of
> course impossible.
Are you really running the code below on a cube with 20 billion points?
> My current codes is as follows:
[...]
> ;giant for-loop that looks at each individual voxel at each velocity
> ;step and places the velocity at that voxel into the new cube's v-dimension.
> for v = min,max-1 do begin ; v = velocity step
>
> for x = 0,xsize-1 do begin
> for y = 0,ysize-1 do begin
> for z =0,zsize-1 do begin
> if (nifs(x,y,z) eq v) then begin ;if voxel has vth velocity step
> flux(x,y,v-min) = v ;places v at the vth plane of flux cube
> endif
> endfor
> endfor
> endfor
>
> endfor
You can do this with only the outermost loop:
for v = min,max-1 do begin
ind = where(nifs eq v, count)
if (count gt 0) then begin
i3d = array_indices(nifs, ind)
flux[i3d[0,*], i3d[1,*], i3d[2,*]-min] = v
endif
endfor
If your datacube is really 20 billion points, you should really divide this into subcubes. This is left as an exercise for the reader :)
--
Yngvar
|
|
|