How to use cached_function and parallel together
I have a function f(a,b,c)
which I'd like to save the output values of, so I'm currently using the @cached_function
decorator to do so:
@cached_function
def f(a,b,c):
m = g(a+b)
n = h(c)
out = (expensive calculation involving m and m)
return m+n
@cached_function
def g(d):
out = (expensive calculation involving d)
return out
@cached_function
def h(c):
out = (expensive calculation involving c)
return out
I would now like to calculate the values of this function for a number of triples (a,b,c) = (a1,b1,c1), (a2,b2,c2), ..., (aN,bN,cN)
, and since there are many such triples I'd like to calculate them in parallel. From some Googling it seems that I should use the @parallel
decorator, but
- How do I use the parallel decorator to calculate values of a function which has more than one input parameter?
- Is it possible for the calculations of these individual values of
f
to share memory somehow? The calculation of my functionf
depends on other expensive functionsg
andh
and thus I have also used the@cached_function
decorator on them; it would be preferable forg
andh
to not be run on the same input if multiple processes are used to perform the calculation off
.