cb-geo / mpm

CB-Geo High-Performance Material Point Method
https://www.cb-geo.com/research/mpm
Other
238 stars 82 forks source link

Performance/openmp schedule mutex #677

Closed kks32 closed 4 years ago

kks32 commented 4 years ago

Describe the PR Duplicate of #676 Mutex locks take a significant amount of time in OpenMP parallel versions of the code. This update is to reduce the lock by trying a spinlock and reduce the wait times across threads.

Enable setting the chunk size in OpenMP schedule using

export OMP_SCHEDULE="static, 4"

This allows for a finer control without having to recompile for different chunk sizes when running different problems. If the variable is not set, the code will still run.

Additional context Spinlocks vs mutexes are a computational bottleneck. However, we cannot use std::atomic, so this is a good workaround the lack of std::atomic support for Eigen and Vector containers. The speed is improved by about 4 - 5 % for the 3D hydrostatic column.

OMP Schedule static chunk size Time (s) Speedup
no schedule 742 1
4 725.3 1.023
16 721.5 1.028
128 735.2 1.009
512 736.7 1.007
1000 760 0.976
SpinMutex with Chunk-4 711 1.044
kks32 commented 4 years ago

This is just a duplicate of #676 as I couldn't get the CI to work

ezrayst commented 4 years ago

Alright, thanks @kks32! LGTM!

codecov[bot] commented 4 years ago

Codecov Report

Merging #677 into develop will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #677   +/-   ##
========================================
  Coverage    96.62%   96.62%           
========================================
  Files          122      123    +1     
  Lines        25295    25318   +23     
========================================
+ Hits         24440    24463   +23     
  Misses         855      855           
Impacted Files Coverage Δ
include/node.h 100.00% <ø> (ø)
include/mesh.tcc 83.33% <100.00%> (ø)
include/mutex.h 100.00% <100.00%> (ø)
include/node.tcc 95.98% <100.00%> (+0.18%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b318d94...d8ddb3a. Read the comment docs.