help on optimization [message #76687] |
Thu, 23 June 2011 02:38 |
stefania
Messages: 1 Registered: June 2011
|
Junior Member |
|
|
Hi all,
I am writing a piece of code that is supposed to provide stacked
differential surface mass density profiles (Sigma(<r)-Sigma(r)). What
I have now it works but is way too slow since I will have to use it to
repeat the stacking ~10^5 times...
What I think can be optimized is the part of code which is doing the
following:
-select particles within a distance
-do the profile by histogramming the particles in radial bins
-sum the mass of the particles in each bin (each particle has a
different mass)
for i=0,nhalos do begin
;Pre-select only particles at a reasonable distance
jj=where((xrand[i]-file_gaspos(0,*))^2 lt 100. and (yrand[i]-
file_gaspos(1,*))^2 lt 100. )
;Distance of particles to the halo
dis=(xrand[i]-file_gaspos(0,jj))*(xrand[i]-file_gaspos(0,jj) )+
(yrand[i]-file_gaspos(1,jj))*(yrand[i]-file_gaspos(1,jj))
dis=sqrt(dis)
;histogram distances within 10Mpc
ind_gas=where(dis lt 10.)
gasmass=file_gasmass[jj[ind_gas]]
hist = histogram(dis[ind_gas],
binsize=bin_mpc,locations=xhist,reverse_indices=ri)
for ll=0,n_elements(xhist)-1 do begin
gasm[ll]=total(file_gasmass[jj[ind_gas[ ri[ ri[ll]:ri[ll
+1]-1 ] ]]])
gasm_cum[ll]=total(file_gasmass[jj[ind_gas[ ri[ ri[0]:ri[ll
+1]-1 ] ]]])
endfor
ymin_r_gas+=(gasm_cum) ; Sigma(<r)
yplot_gas+=(gasm) ; Sigma(r)
endfor
Any help/idea/feedback will be very useful!
Thanks
Stefania
|
|
|