xACT PARALLELIZATION.

Loading package

LaunchKernels[12]

To avoid automatic passing of data we disable distribution of contexts

$DistributedContexts=None

<<xAct`xTensor`
ParallelNeeds["xAct`xTensor`"]

Define a manifold in the main kernel.

DefManifold[M,4,{α,β,γ,δ,η,λ,μ,ν,ρ,τ,χ,ω,ξ,ζ}]

ManifoldQ[M]

It is not yet a manifold in the other kernels, so we define it there too.

ParallelEvaluate[ManifoldQ[M],Kernels[]]

ParallelEvaluate[DefManifold[M,4,{α,β,γ,δ,η,λ,μ,ν,ρ,τ,χ,ω,ξ,ζ}],Kernels[]]

ParallelEvaluate[ManifoldQ[M],Kernels[]]

The same thing with B and metricg

DefTensor[B[μ],M]

ParallelEvaluate[DefTensor[B[μ],M],Kernels[]]

DefMetric[1,metricg[-μ,-ν],CD,PrintAs->"g"]

ParallelEvaluate[DefMetric[1,metricg[-μ,-ν],CD,PrintAs->"g"],Kernels[]]

We define a scalar l on all the subkernels

DefTensor[l[],M]

ParallelEvaluate[DefTensor[l[],M],Kernels[]]

We defined a function which parallelize the sorting of covariant derivatives and try it on 4 derivatives symmetrized

ParallelSort[InputExp_] := Module[{},Return[ParallelMap[SortCovDs[#]&,List@@(InputExp//Expand)]]]

Sym4=Symmetrize[CD[-ν]@CD[-ρ]@CD[-μ]@CD[-τ]@CD[-λ]@l[]]//Simplification;

Then we compare the time required to sort the derivatives with and without parallelization

Timing[SortCovDs[Sym4];]
AbsoluteTiming[SortCovDs[Sym4];]

Timing[(Plus@@ParallelSort[Sym4]);]
AbsoluteTiming[(Plus@@ParallelSort[Sym4]);]

With 12 cores the calculation takes around 1/5 (absolute 1/4), which is still good. However most of time is spent on simplification, as in can be seen below

Timing[SortCovDs[Sym4]//Simplification//ScreenDollarIndices;]

Timing[(Plus@@ParallelSort[Sym4])//Simplification//ScreenDollarIndices;]

We need then to parallelize the simplification

ParallelSimplification[InputExp_,N_]:=Module[{},ParallelMap[Simplification[Plus@@#]&,Partition[Quiet[AppendTo[List@@(InputExp//Expand),0]],N]]]

Length[ParallelSort[Sym4]]

We can then parallelize the simplification dividing the list in 12 sublists parallelized and then resummed

Timing[(Plus@@ParallelSimplification[Plus@ParallelSort[Sym4],Length[Kernels[]]])//Simplification;]

We can try parallelizing ToCanonical and after a simplify

ParallelToCanonical[InputExp_,N_]:=Module[{},ParallelMap[ToCanonical[Plus@@#]&,Partition[Quiet[AppendTo[List@@(InputExp//Expand),0]],N]]]

Timing[(Plus@@ParallelToCanonical[Plus@ParallelSort[Sym4],Length[Kernels[]]])//ToCanonical//Simplify;]