42 views
Skip to first unread message

yunbo wang

unread,
Jul 5, 2012, 11:30:47 AM7/5/12
to sciki...@googlegroups.com, Jason Furtney
Hi Jason,

Here is one example of my code. 

import skfmm
import numpy as np
N = 100
dL = 0.1

function = np.ones((N,N))
function[1,1] = -1.0

velocity = np.ones((N,N))
velocity[80, 80] = 0.000001

values2 = skfmm.distance(function, dx=dL) - skfmm.travel_time(function, dx=dL, speed=velocity)

I want to compare the difference between two arrival functions. That difference would be around [80, 80]. It's 
sought over the same grid over and over. 

How to avoid the malloc/free operation in this case?

Thank you.

Best,
Yunbo

On Jul 5, 2012, at 8:31 AM, Jason Furtney wrote:

Dear Yunbo,

Thanks for your email and for your interest in scikit-fmm. Could you
send me an example of what you are running that is too slow? I will
double check that there is no problems with-in scikit-fmm.

You could also try lsmlib which can also solve the Eikonal equation
and may be faster. Daniel Wheeler has developed a cython wrapper for
lsmlib.

I would be interested in a performance comparison between the lsmlib
and scikit-fmm to see how we can improve scikit-fmm.

There are some schemes to speed up FMM calculations particularly if
you only need the solution in a narrow band around the initial
interface. Also, there are several malloc/free operations invoked when
the scikit-fmm c++ code is started. We may be able to avoid these if
the solution is sought on the same grid over-and-over.

Thanks again,
Jason

Jason Furtney

unread,
Jul 5, 2012, 12:54:18 PM7/5/12
to sciki...@googlegroups.com
Dear Yunbo,

Thanks for your example. scikit-fmm supports masked arrays so maybe
you want to do something like this:

import skfmm
import numpy as np
import pylab as pl
N = 100
dL = 0.1
function = np.ones((N,N))
function[1,1] = -1.0
mask = np.zeros_like(function, dtype=bool)
mask[80,80]=True
function2 = np.ma.MaskedArray(function, mask)
delta = skfmm.distance(function, dL) - skfmm.distance(function2, dL)
pl.matshow(delta)
pl.colorbar()
pl.show()

I ran both this version and your original code and the calls to
skfmm.distance() seem to take about 0.02 seconds or less. I used the
%time and %timeit magic in ipython to measure the run time. The total
time from starting python on the command line, importing all the
modules, running the code and exiting back to the shell is still less
that 0.1s. Am I misunderstanding something?

It is possible to write numpy expressions which look simple but invoke
costly allocation and copy operations.

Let me know if you still have questions or problems,
Jason
> --
> You received this message because you are subscribed to the Google Groups
> "scikit-fmm" group.
> To post to this group, send email to sciki...@googlegroups.com.
> To unsubscribe from this group, send email to
> scikit-fmm+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/scikit-fmm?hl=en.

yunbo wang

unread,
Jul 5, 2012, 8:44:08 PM7/5/12
to sciki...@googlegroups.com
Thank you for you explanation, Jason. Using masks did save around 0.02s. 

My simulation runs longer since I'm using a 400 by 400 mesh. Actually I'm solving two Eikonal Equations on the same phi, but with two different speed functions. 

Afterwards, I tried lsmlib and didn't quite get the result I want. Maybe I'm using it wrongly, if not, it seems lsmlib is focusing on the narrow band around the zero level set. But I need the information of the overall domain. Lsmlib runs twice faster and scikit gives me reliable results on the region away from zero level set.  

Best,

Yunbo
Reply all
Reply to author
Forward
0 new messages