Metafor

ULiege - Aerospace & Mechanical Engineering

User Tools

Site Tools


doc:user:advanced:parallel

Parallel computing

Metafor can be run in parallel on several cores of your computer, but this is not done automatically. By default Metafor uses a single core for the calculation (and another one for the visualisation when it is enabled).

Run Metafor with several threads

To enable parallelism, you should prescribe the number of threads by adding a -k flag to the command line: for example:

Metafor -k 4

starts Metafor with 4 threads.

If you use the graphical user interface and you want to double click on the icon, you can duplicate the shortcut on the desktop (click on it, then CTRL-C, CTRL-V to make a copy). Rename it to “Run Parallel Metafor”. Then right-click on the icon and go to properties. Add -k 4 to the end of the “target” line: Then click OK.

Doucle-click on the new icon and check that 4 threads are enabled:

Change your python file

In order to take advantage of parallel loops, you must do 2 things:

  • you must use a parallel linear solver
  • you must explicitly enable parallel loops in your python file

Use a parallel linear solver

The default linear solver is a basic sequential solver. Change the linear solver used to solve each linear system at each iteration with:

solman = metafor.getSolverManager()
solver = DSSolver()
solman.setSolver(solver)

Activate parallel loops

Add these lines anywhere in your python file after the line from wrap import *:

StrVectorBase.useTBB()
StrMatrixBase.useTBB()
ContactInteraction.useTBB()

The first line enable the parallel assembly of vectors. The second line does the same for matrices. The third line activates parallel contact management.

These 3 lines will display 3 blocks of messages such as this one:

\**************************************************
 WARNING: StrVectorBase::useTBB(true):            
  Structural vectors will be computed in parallel.
  However, some combinations of elements/algorithms
  are NOT thread safe yet!
  => Erroneous results / program crash may occur!.
\**************************************************

This is the normal behaviour. Some parts of Metafor are not thread-safe yet. However, if you are using classical commands, algorithms and methods of Metafor, enabling parallelism is totally safe.

Anyway you must keep in mind that parallel calculations are not performed in the same order each time you run the problem. It means that parallel results are not reproductible. You can obtain slightly different results when running Metafor twice on the same test. This is a common behaviour in parallel solvers.

Read CPU times

During the calculation, CPU times are displayed at the beginning of each time step: for example:

\*** STEP 9: t= 0.000149616 - dt= 4.3125e-05 - CPU= 1m24.97s/41.54s

The first time is the “CPU time”. This is the sum of the calculation times spent in each core of your CPU. This timer runs much faster than the “wall-clock time”, which is the second time displayed.

Thus, if you want to compare 2 simulations, keep track of the wall-clock time (the smallest time displayed, also named Real CPU time) which is the real time spent running the calculation.

[TSC-CPU]                           User CPU Time : 47.1562
[TSC-REA]                           Real CPU Time : 12.979
[TSC-KER]                         Kernel CPU Time : 3.35938

The third time (kernel) is the CPU time spent by parallel management routines and other system calls. This time is included in the “Real CPU time”.

Read the details

The time spent in each part of the code is summarized in timers.txt. You will find this file in the workspace of your test at the end of the calculation.

If you are interested in analysing the efficiency of your model, you can have a look at its contents (it is a table similar to this one):

user real kernel
GEN_EXT_FORC_TXTYTZ 3.78125 0.15 0.109375
GEN_INTER_FORC_TXTYTZ 2.9375 0.572 0.0625
Metafor 47.1562 12.983 3.35938
ObjectiveFunction 0 0 0
ValuesManager 0.96875 0.594 0.109375
buildK_TXTYTZ 12.5156 1.737 0.78125
contactDetection 7.6875 1.888 0.296875
prepro 0.390625 0.731 0.328125
saveFacs 0.21875 0.17 0.015625
solveK_TXTYTZ 12.5469 1.883 0.796875
steps 0.75 0.675 0.046875
doc/user/advanced/parallel.txt · Last modified: by boman

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki