TFORM is considered a great tool for manipulating large and symbolic equations. In this thread, I’d like to share my optimization problem, which concerns a very simple operation — equations expansion.
I’ve attached a link to my repository, which contains the scripts and files needed to run TFORM in parallel, expanding each equation independently:
https://github.com/kozapdh/ParallelExpandTFORM
The goal of this post is to achieve the fastest possible TFORM setup for expanding large symbolic equations, where the total number of equations is relatively small.
In the example repository, there are only 19 equations that need to be expanded.
The Bash script parallel_tform_running.sh launches a TFORM process in parallel for each equation file (standardEquation_*.frm).
In other words, each TFORM process handles exactly one equation.
Here is the TFORM script that is run for each equation::
Off Statistics;
CFunction a, d;
Symbol r0, nu, I;
#define inFile "`FORM_DIR'`WKB_SUBDIR'standardEquation_`eqNum'.frm"
#define outFile "`FORM_DIR'`WKB_SUBDIR'expandedEquations_`eqNum'.m"
#include coeffs.frm
#include dvars.frm
#include `inFile'
#ifdef Eq`eqNum'
Local EqExpanded`eqNum' = Eq`eqNum';
.sort
Format mathematica;
Format nospaces, nolines;
#write <`outFile'> "%E==0\n", EqExpanded`eqNum'
#else
#message Warning: Eq`eqNum' not defined in `inFile'
#endif
.end
My question:
What should I change in the concept of expanding symbolic equations in parallel with TFORM to achieve better performance?
For comparison, the equivalent operation in Mathematica can be performed with the following almost-one-liner:
listOfEquations = << "listOfEquations.txt";
ParallelMap[Expand, listOfEquations, Method -> "FinestGrained"];
Here, listOfEquations is a list containing all the symbolic equations to be expanded — the same equations that, in my TFORM setup, are stored separately as standardEquation_*.frm files. listOfEquations.txt is the file that contains those equations in mathematica_list folder on my GitHub.
When executed on my desktop with 8 CPU cores, this Mathematica code completes in about 300 seconds.
For the same set of equations, my TFORM implementation currently takes 505 seconds.
ParallelMap[Expand, equations, DistributedContexts -> None];significantly reduced the execution time to about 126 seconds. Once I get back home—where the higher-order WKB equations are still being processed—I’ll upload some additional details and results to the repository.