I would like to create a large rank-4 tensor by using both Table and ParallelTable.
What is actually constructed is given below: $\mathcal{L}_{m_1,m_2,V_1,V_2}=i\left(\xi^*_2(m_1,v_1)-\xi^*_2(m_2,v_2)\right)V_d(m_1,v_1)V_d(v_2,m_2)$
where the function $\xi_2(m,v;V)=i\frac{\beta_2^2}{2\beta_1^2}\left[1-\left(e^{\frac{E_{v}-E_m-V/2}{kT}}+1\right)^{-1}\right]\sqrt{4\beta^2_1-(E_{v}-E_m-V/2)^2}$
and matrix elements $V_d(m,v)=\langle m|v\rangle=e^{-\lambda^2/2\Omega^2}\sum_{i=0}^{\nu}\sum_{j=0}^{m}\delta_{m-j,\nu-i}(-1)^j\left(\frac{\lambda}{\Omega}\right)^{i+j}\frac{1}{i!j!}\sqrt{\frac{m!\nu!}{(m-j)!(v-i)!}}$
But I don't know why ParallelTable didn't give any improvement on the performance.
Clear["Global`*"]
Ns = 41; (*number of basis*)
Nb = 7;
V = 1.84;
\[Lambda] = 0.3;
\[CapitalOmega] = 0.5;
\[Epsilon]0 = 0.5;
\[Beta]1 = 1; \[Beta]2 = 0.05; kT = 0.0259/300*10; (*10K*)
(*Franck-Condon factors*)
FK = E^(-[Lambda]^2/(2 [CapitalOmega]^2)) Table[!(
*UnderoverscriptBox[([Sum]), (i = 0), ([Nu])](
*UnderoverscriptBox[([Sum]), (j =
0), (m)]((KroneckerDelta[m - j, [Nu] - i]))
*SuperscriptBox[(((-1))), (j)]
*SuperscriptBox[((
*FractionBox[([Lambda]), ([CapitalOmega])])), (i + j)]
*FractionBox[(1.), ((i!) (j!))]
*SqrtBox[
FractionBox[((m!) ([Nu]!)), ((((m - j))!) ((([Nu] -
i))!))]])), {m, 0, Ns - 1}, {[Nu], 0, Ns - 1}];
(Eigenenergies of oscillator)
Em = Table[[CapitalOmega] (m + 1/2), {m, 0, Ns - 1}];
(Eigenenergies of shifted oscillator)
E[Nu] = Table[[CapitalOmega] ([Nu] + 1/
2) + [Epsilon]0 - [Lambda]^2/[CapitalOmega], {[Nu], 0,
Ns - 1}];
(Define elementary functions)
cf = Compile[{{x, Real}},
If[x < -300., 1., If[x > 300., 0., 1./(1. + Exp[x])]],
CompilationTarget -> "C", RuntimeAttributes -> {Listable},
Parallelization -> True, RuntimeOptions -> "Speed"];
c[CapitalGamma]0 =
Compile[{{E, _Real}, {qV, _Real}, {[Beta]1, _Real}, {[Beta]2,
_Real}}, If[
Abs[E - qV/2.] <=
2 [Beta]1, [Beta]2^2/[Beta]1^2 Sqrt[
4 [Beta]1^2 - (E - qV/2.)^2], 0.], CompilationTarget -> "C",
RuntimeAttributes -> {Listable}, Parallelization -> True,
RuntimeOptions -> "Speed"];
[Xi]2L[E, V_] :=
I/2 (1 - cf[(E - V/2)/kT]) c[CapitalGamma]0[E,
V, [Beta]1, [Beta]2];
[Xi]2Lmv =
Table[[Xi]2L[E[Nu][[v + 1]] - Em[[m + 1]], V], {m, 0, Ns - 1}, {v,
0, Ns - 1}];
Table[ (Conjugate[[Xi]2Lmv[[m1,
V1]]] - [Xi]2Lmv[[m2, V2]]) (FK[[m1, V1]] FK[[m2, V2]])
, {m1, 1, Ns}, {V1, 1, Ns}, {m2, 1, Ns}, {V2, 1,
Ns}]; // AbsoluteTiming
ParallelTable[ (Conjugate[[Xi]2Lmv[[m1,
V1]]] - [Xi]2Lmv[[m2, V2]]) (FK[[m1, V1]] FK[[m2, V2]])
, {m1, 1, Ns}, {V1, 1, Ns}, {m2, 1, Ns}, {V2, 1,
Ns}]; // AbsoluteTiming

ParallelTablework effectively in this case? – Bob Lin Aug 23 '21 at 12:19