0

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.

5
  • 1
    Unless you are going to do it a huge number of times does the difference between 5 minutes using Mathematica and 9 minutes using TFORM really matter? You might want to monitor some of the CPU performance counters to see where the slower one is getting stuck but TBH it is only really worth optimising code for an order of magnitude gain in speed (or to make the calculation possible at all). Path of least resistance is use Mathematica for this task. Commented Nov 9 at 10:23
  • @MartinBrown I agree, though AFAIK Mathematica is not free ;) Commented Nov 9 at 10:50
  • I should have mentioned that the attached list of equations to be expanded is only an example and represents a relatively small portion of the calculations I’ve been performing while solving Schrödinger-type differential equations using the WKB method. For larger equations, the difference in computation time is not a matter of minutes, but rather hours or even days. My intention was to share an arbitrarily chosen set of equations that can be expanded and tested by anyone interested in the topic. I can also share a larger set of equations if you wish. Commented Nov 9 at 11:31
  • Have you tried only running a maximum of 4, 8, 10, 12 equations at a time on TFORM? If you try to run too many things at once the various processes will be fighting each other for memory bandwidth which on symbolic algebra expansions can be in very high demand. Once you go past a certain load point adding another demanding task running in parallel actually slows things down. Worth finding where that point is. Commented Nov 9 at 15:58
  • You mean, for example, running four equations within a single TFORM process? I’ve actually tried executing all available equations in one TFORM process using 8 cores, but unfortunately, the runtime was around 1000 seconds. However, I have an update! Running the same computations in Mathematica using: 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. Commented Nov 10 at 17:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.