I’m working with FORM/TFORM to automatically expand a large set of symbolic equations. My goal is to make the expansion process run in parallel on multiple CPU cores using TFORM.
Here’s a simplified version of my current script:
Off Statistics;
CFunction a, d;
Symbol r0, nu, I;
#include coeffs.frm
#include dvars.frm
#include equations.frm
#include numOfEquations.frm
Format mathematica;
Format nospaces, nolines;
#do i = 1, `numOfEquations'
#ifdef Eq`i'
Local EqExpanded`i' = Eq`i';
.sort
#write <expandedEquations.m> "%E==0,", EqExpanded`i'
#endif
#enddo
.end
In this setup, each equation Eq is expanded and written to a file one by one.
I understand that .sort triggers the actual computation and that TFORM distributes terms among workers, but since .sort appears inside the loop, each iteration seems to be processed sequentially.
I tried also placing .sort outside the loop hoping the procedure .sort distribute equations among workers to expand them in parallel but it is not working:
Off Statistics;
CFunction a, d;
Symbol r0, nu, I;
#include coeffs.frm
#include dvars.frm
#include equations.frm
#include numOfEquations.frm
Format mathematica;
Format nospaces, nolines;
#do i = 1, `numOfEquations'
#ifdef Eq`i'
Local EqExpanded`i' = Eq`i';
#endif
#enddo
.sort
#do i = 1, `numOfEquations'
#ifdef Eq`i'
#write <expandedEquations.m> "%E==0,", EqExpanded`i'
#endif
#enddo
.end
What I would like to achieve is:
- Read all equations from file,
- Expand them in parallel across multiple cores,
- Then write each expanded equation to the output file.
My question is: How should I structure the FORM/TFORM code, so that the expansion of multiple equations happens in parallel?
Should I group equations before calling .sort, or is there a more efficient TFORM pattern for this type of task?