-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
probvec: Use guvectorize with target='parallel' #253
Conversation
I'm not opposed to using guvectorize at any point in the library, but I don't love this particular change. The reason is that if I was using these tools within a larger algorithm, I would almost certainly want to parallelize a different section of my code. Having this routine always run in parallel might make that difficult. |
@spencerlyon2 We shouldn't accept this PR if it can interfere anything more important; But can you elaborate on your point? Do you have in mind any case where you may use this particular routine within a larger algorithm? |
Hi @oyamad and @spencerlyon2. Where are we up to with this PR? Should we add the |
I thought about it more. I vote that we accept this. It would be great it numba allowed us to use |
We could possibly do: def probvec(m, k, random_state=None, parallel=True):
...
if parallel:
_probvec_parallel(r, x)
else:
_probvec_cpu(r, x)
def _probvec(r, out):
...
_probvec_parallel =
guvectorize(['(f8[:], f8[:])'], '(n), (k)', nopython=True, target='parallel')(_probvec)
_probvec_cpu =
guvectorize(['(f8[:], f8[:])'], '(n), (k)', nopython=True, target='cpu')(_probvec) |
@spencerlyon2 Are you still concerned with:
We can implement options through a wrapper (as per @oyamad solution) or make |
I think the proposed solution sounds great. Let's go with that!
|
@oyamad please let me know if you are happy with this update then we can merge this into the master branch. Thanks. |
@mmcky Thanks, please do merge. (I added some docstring and tests.) |
Thanks @oyamad! Merging now. |
This is to modify
probvec
to useguvectorize
withtarget='parallel'
.(
probvec
is mainly used to generate samples ofMarkovChain
orDiscreteDP
.)guvectorize
simplifies the logic slightly; we don't need to explicitly write the outer loop.sort()
in a jitted loop with nopython mode, the bottleneck of the currentprobvec
.target='parallel'
this version is faster than the current version onmaster
for cases with large size, whereas it seems slower with small size (probably due to overhead).Timing on a machine with 4 cores:
master
:This version:
This is the first case in quantecon where
guvectorize
is used; we might discuss its pros and cons here.