Problem
Currently, the mat_mul operation to compute material stiffness for both struct and ustruct is contained inside an inner loop over each element's nodes. The mat_mul operation can be safely hoisted ouside the inner loop, resulting in a ~10% speedup timestep for a 500k element simulation.
This occurs around line 750 in sv_struct.cpp:
for (int b = 0; b < eNoN; b++) {
for (int a = 0; a < eNoN; a++) {
// Geometric stiffness
NxSNx = Nx(0,a)*S(0,0)*Nx(0,b) + Nx(1,a)*S(1,0)*Nx(0,b) +
Nx(2,a)*S(2,0)*Nx(0,b) + Nx(0,a)*S(0,1)*Nx(1,b) +
Nx(1,a)*S(1,1)*Nx(1,b) + Nx(2,a)*S(2,1)*Nx(1,b) +
Nx(0,a)*S(0,2)*Nx(2,b) + Nx(1,a)*S(1,2)*Nx(2,b) +
Nx(2,a)*S(2,2)*Nx(2,b);
T1 = amd*N(a)*N(b) + afu*NxSNx;
// Material Stiffness (Bt*D*B)
mat_mul(Dm, Bm.rslice(b), DBm);
A similar pattern occurs around line 1410 in ustruct.cpp:
for (int b = 0; b < eNoNw; b++) {
for (int a = 0; a < eNoNw; a++) {
NxSNx = Nwx(0,a)*Siso(0,0)*Nwx(0,b)
+ Nwx(0,a)*Siso(0,1)*Nwx(1,b) + Nwx(0,a)*Siso(0,2)*Nwx(2,b)
+ Nwx(1,a)*Siso(1,0)*Nwx(0,b) + Nwx(1,a)*Siso(1,1)*Nwx(1,b)
+ Nwx(1,a)*Siso(1,2)*Nwx(2,b) + Nwx(2,a)*Siso(2,0)*Nwx(0,b)
+ Nwx(2,a)*Siso(2,1)*Nwx(1,b) + Nwx(2,a)*Siso(2,2)*Nwx(2,b);
auto DBm = mat_mul(Dm, Bm.rslice(b));
Solution
The two mat_mul operations should occur once in the outer loop rather than being repeated for each node. I implemented this change in this branch and confirmed byte-identical results on the relevant test cases.
I profiled a 500k-element struct simulation before and after the change and found a 10% speedup per time step. Similar improvements should be seen in ustruct simulations.
Additional context
No response
Code of Conduct
Problem
Currently, the mat_mul operation to compute material stiffness for both struct and ustruct is contained inside an inner loop over each element's nodes. The mat_mul operation can be safely hoisted ouside the inner loop, resulting in a ~10% speedup timestep for a 500k element simulation.
This occurs around line 750 in sv_struct.cpp:
A similar pattern occurs around line 1410 in ustruct.cpp:
Solution
The two mat_mul operations should occur once in the outer loop rather than being repeated for each node. I implemented this change in this branch and confirmed byte-identical results on the relevant test cases.
I profiled a 500k-element struct simulation before and after the change and found a 10% speedup per time step. Similar improvements should be seen in ustruct simulations.
Additional context
No response
Code of Conduct