Re: help on optimization [message #76683] |
Thu, 23 June 2011 08:19 |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
I would approach this by:
1. Calculate the radius r.
2. Sort by radius.
3. Use TOTAL(/CUMULATIVE) to get the cumulative mass profile at each particle, in sorted radius order.
4. Use VALUE_LOCATE to find where in the radial-sorted-list-of-particles the endpoints of the bins are.
5. Subtract the cumulative total values at each bin edge to get the total mass in each bin, which you can compare directly to the cumulative mass to that point from the cumulative total.
-Jeremy.
|
|
|
Re: help on optimization [message #76684 is a reply to message #76683] |
Thu, 23 June 2011 05:47  |
Wout De Nolf
Messages: 194 Registered: October 2008
|
Senior Member |
|
|
On Thu, 23 Jun 2011 14:44:06 +0200, Wox <spam@nomail.com> wrote:
> xgaspos=file_gaspos[0,*]
> ygaspos=file_gaspos[1,*]
>
> for i=0,nhalos do begin
> ;Distance of particles to the halo
> dis2=(xrand[i]-xgaspos)^2+(yrand[i]-ygaspos)^2
>
> ;histogram distances within 10Mpc
> hist =histogram(dis2[ind_gas],binsize=bin_mpc,$
> max=10000,reverse_indices=ri)
>
> gasmass=file_gasmass[ind_gas]
> for ll=0,n_elements(hist)-1 do $
> if ri[ll] eq ri[ll+1] then gasm[ll]=0 $
> else gasm[ll]=total(gasmass[ ri[ ri[ll]:ri[ll+1]-1 ] ])
>
> ymin_r_gas+=total(gasm,/cumul,/pres) ; Sigma(<r)
> yplot_gas+=gasm ; Sigma(r)
> endfor
This should be removed of course:
gasmass=file_gasmass[ind_gas]
|
|
|
Re: help on optimization [message #76685 is a reply to message #76684] |
Thu, 23 June 2011 05:44  |
Wout De Nolf
Messages: 194 Registered: October 2008
|
Senior Member |
|
|
On Thu, 23 Jun 2011 02:38:00 -0700 (PDT), stefania
<stefania.giodini@gmail.com> wrote:
> Any help/idea/feedback will be very useful!
1. I don't think the preselection speeds things up, so skip it.
2. Avoid using WHERE by specifying a MAX in histogram (use 100^ to
avoid SQRT).
3. Remove some redundancy in total / cumulative total.
xgaspos=file_gaspos[0,*]
ygaspos=file_gaspos[1,*]
for i=0,nhalos do begin
;Distance of particles to the halo
dis2=(xrand[i]-xgaspos)^2+(yrand[i]-ygaspos)^2
;histogram distances within 10Mpc
hist =histogram(dis2[ind_gas],binsize=bin_mpc,$
max=10000,reverse_indices=ri)
gasmass=file_gasmass[ind_gas]
for ll=0,n_elements(hist)-1 do $
if ri[ll] eq ri[ll+1] then gasm[ll]=0 $
else gasm[ll]=total(gasmass[ ri[ ri[ll]:ri[ll+1]-1 ] ])
ymin_r_gas+=total(gasm,/cumul,/pres) ; Sigma(<r)
yplot_gas+=gasm ; Sigma(r)
endfor
4. You can think of calculating "dis" outside the loop but it depends
on how many columns file_gaspos has (memory issues). Assume xrand en
yrand are row vectors:
dis=sqrt((rebin(xrand,nhalos,np,/sample)-rebin(file_gaspos[0 ,*],nhalos,np,/sample))^2+$
(rebin(yrand,nhalos,np,/sample)-rebin(file_gaspos[1,*],nhalo s,np,/sample))^2)
You can also devide nhalos in smaller chunks. However you still need
to do the histogram and mass summation for each column separatly.
|
|
|