Problem
I have an expression that calculates the coefficients of a 2x2 matrix which depend on other three independent expressions, i.e,
$K_{l l^\prime} = ( k_{l l^\prime}^{(1)} + k_{l l^\prime}^{(2)} + k_{l l^\prime}^{(3)} )$
Each $k$ depends on parameters $x_0$ and $\beta$. In Mathematica I have defined the following functions:
k1[x0_, beta_]:= NIntegrate[(*huge expression*)]
k2[x0_, beta_]:= NIntegrate[(*huge expression*)]
k3[x0_, beta_]:= x*NIntegrate[(*huge expression*)]
Here $x$ is a symbolic value, so essentially $k_1$ and $k_2$ are purely numeric and $k_3$ is symbolic.
To evaluate the result I have defined
K[x0_beta_]:= k1[x0,beta]+k2[x0,beta]+k3[x0,beta]
I would like to paralelize the evaluation of $K$, that is, calculate each $k$ in a different kernel (processor) to speed up the calculation, then join and sum the terms.
My research in the Wolfram documentation pages led me to believe that I should use the
ParallelSubmit[]
function but I am unsure on how to exactly initialize and distribute the task to the kernels, then join the computations.
If it helps, I am using Mathematica 11.0.
Contextualizing
To give a bit more of context, I'm trying to reproduce the graphs (more specifically figure 5) in this paper https://arxiv.org/pdf/1304.0582.pdf
For that I must compute equations (77)-(79) with the help of equations (42) and (44)-(47). The functions $f(y)$ and $g(y)$ are given in equations (14) and (15).
In my Mathematica program, $g(y)$ is a numeric solution to (15) and is represented by a interpolating function.
k1
,k2
,k3
? Do they involve symbolic computation? If not, are they compilable? Submitting the tasks to different kernels in the way you discribed it need not be a good idea at all since summing up results from different kernels involves communication that may spoil all the speedup. There are at least two other parallelization techniques accessible from within Mathematica: vectorization and the one thatCompile
provides. $\endgroup$Total@Parallelize@{k1[x0,beta], k2[x0,beta], k3[x0,beta]}
, but as Henrik points out, whether it will be efficient depends on whatk1
etc. do. There's alsoParallelSum[k[x0, beta], {k, {k0, k1, k2}}]
. $\endgroup$