doc:user:advanced:parallel
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| doc:user:advanced:parallel [2015/10/28 15:01] – joris | doc:user:advanced:parallel [2025/11/25 08:23] (current) – [Read the details] boman | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| - | ===== Quand utiliser le parallélisme? | + | 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). |
| - | Metafor | + | ===== Run Metafor |
| - | Pour voir si votre test peut bénéficier du parallèle, il est utile d'aller jeter un oeil sur le fichier \\ '' | + | To enable parallelism, you should prescribe the number of threads by adding a '' |
| + | Metafor -k 4 | ||
| + | starts Metafor with 4 threads. | ||
| - | Voila ce que ca donne par exemple: | + | 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 click OK. | ||
| - | ^ ^ | + | Doucle-click on the new icon and check that 4 threads are enabled: |
| - | |'' | + | {{:doc:user: |
| - | |'' | + | |
| - | |'' | + | |
| - | |'' | + | |
| - | |'' | + | |
| - | |'' | + | |
| - | |'' | + | |
| - | |'' | + | |
| - | Chaque colonne est un compteur du temps CPU. Regardons le compteur OpenMP (dernière colonne). On voit ici que le solveur (ligne "'' | + | ===== Change your python file ===== |
| - | Dans ce cas précis, c'est pas terrible mais si votre test est plus gros et que votre temps solveur avoisine les 90% du temps CPU total, ca peut valoir le coup de continuer à lire cette page... | ||
| + | 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 '' | ||
| + | |||
| + | 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: | ||
| + | |||
| + | \************************************************** | ||
| + | | ||
| + | Structural vectors will be computed in parallel. | ||
| + | However, some combinations of elements/ | ||
| + | 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. | ||
| - | ===== Principe général ===== | + | 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. |
| - | <note important> | ||
| - | ]] </ | ||
| - | Il s'agit de parallélisation [[http:// | + | ===== Read CPU times ===== |
| - | Dans Metafor, les objets statiques '' | + | During the calculation, CPU times are displayed at the beginning of each time step: for example: |
| - | OpenMP.status() | + | |
| - | Blas.status() | + | |
| - | ceci est fait au démarrage de Metafor à titre informatif. | + | |
| - | On peut aussi changer le nombre de threads utilisés par OpenMP en écrivant directement dans le jeu de données: | + | \*** STEP 9: t= 0.000149616 - dt= 4.3125e-05 - CPU= 1m24.97s/41.54s |
| - | OpenMP.setNumThreads(n) | + | |
| - | Blas.setNumThreads(n) | + | |
| - | où '' | + | |
| - | ===== Exécution dans un Metafor.exe ===== | + | |
| - | Les commandes précédentes s' | + | The first time is the "CPU time" |
| - | Metafor.exe -j 2 -run montest | + | |
| - | qui lance '' | + | |
| - | Par défaut, sans ce flag, le nombre de threads est __toujours initialisé à 1__ par '' | + | Thus, if you want to compare 2 simulations, keep track of the wall-clock time (the smallest time displayed, also named '' |
| - | Pourquoi? Simplement parce que les valeurs par défaut MKL et OpenMP ne sont pas identiques! Par exemple, sur une machine avec 4 coeurs hyperthreadés, | + | [TSC-CPU] |
| + | [TSC-REA] | ||
| + | [TSC-KER] | ||
| - | ===== Exécution sous python externe ===== | + | 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". |
| - | Metafor peut également être lancé à l'aide d'un '' | + | ===== Read the details ===== |
| - | Dans ce cas particulier mais relativement courant, on est dans un environnement externe a priori inconnu (éventuellement même dans un autre programme qui possède une interface python!!). Aucune initialisation n'est donc effectuée pour ne pas interférer avec l' | + | |
| - | set OMP_NUM_THREADS=n | + | |
| - | set MKL_NUM_THREADS=n | + | |
| - | set MKL_DYNAMIC=0 | + | |
| - | python montest2.py | + | |
| - | lance '' | + | |
| - | Par défaut, on a donc le comportement qui peut sembler " | + | The time spent in each part of the code is summarized in '' |
| - | ===== En résumé ===== | + | 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): |
| - | * Le nombre de threads utilisé par défaut pour '' | + | ^ ^user ^real ^kernel^ |
| - | * Le nombre de threads est fixé par l' | + | |GEN_EXT_FORC_TXTYTZ |3.78125 |0.15 |0.109375| |
| - | * Sous python (et la batterie notamment), le nombre de threads n'est pas initialisé. Il peut être fixé | + | |GEN_INTER_FORC_TXTYTZ |2.9375 |0.572 |0.0625| |
| - | * soit via les variables d' | + | |Metafor |47.1562 |12.983 |3.35938| |
| - | * soit directement dans le jeu de données \\ ('' | + | |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| | ||
| - | <note tip>Il serait possible d' | ||
| - | --- // | ||
doc/user/advanced/parallel.1446040915.txt.gz · Last modified: (external edit)
