plumed / plumed2

Development version of plumed 2
https://www.plumed.org
GNU Lesser General Public License v3.0
324 stars 269 forks source link

Extensive optimization of grids #1030

Closed GiovanniBussi closed 4 months ago

GiovanniBussi commented 4 months ago

I extensively optimized the Grid code. Specifically:

I want to go back and revise the code before mering. Meanwhile I post the results that I could obtain on my INTEL macbook.

Test 1 - update

The first test is representative of cases where the PACE is relatively low, so that the cost is mostly in adding new Gaussians. Here I get a significant speedup (more than 50%). I see a significant speedup also in using sum_hills on a large file (not shown). I expect this to also help when restarting simulations with many Gaussians. The speedup is mostly in the Update phase, but from the timings it can be seen that also Calculating is faster.

Command:

plumed benchmark --nsteps 10000 --natoms 100

plumed.dat:

d1: DISTANCE ATOMS=1,2
d2: DISTANCE ATOMS=3,4
d3: DISTANCE ATOMS=5,6
c1: CUSTOM ARG=d1 FUNC=sin(x) PERIODIC=NO
c2: CUSTOM ARG=d2 FUNC=sin(x) PERIODIC=NO
c3: CUSTOM ARG=d3 FUNC=sin(x) PERIODIC=NO
METAD ARG=c1,c2,c3 HEIGHT=1.0 GRID_MIN=-1,-1,-1 GRID_MAX=+1,+1,+1 SIGMA=0.1,0.1,0.1 PACE=10

Results:

BENCH:  Kernel: /Users/bussi/plumed2/tmp/reference/lib/libplumedKernel.dylib
PLUMED:                                               Cycles        Total      Average      Minimum      Maximum
PLUMED:                                                    1     4.541843     4.541843     4.541843     4.541843
PLUMED: 1 Prepare dependencies                         10000     0.005873     0.000001     0.000000     0.000055
PLUMED: 2 Sharing data                                 10000     0.007854     0.000001     0.000000     0.000032
PLUMED: 3 Waiting for data                             10000     0.002283     0.000000     0.000000     0.000015
PLUMED: 4 Calculating (forward loop)                   10000     0.035392     0.000004     0.000002     0.000083
PLUMED: 5 Applying (backward loop)                     10000     0.008125     0.000001     0.000000     0.000019
PLUMED: 6 Update                                       10000     4.423286     0.000442     0.000000     0.011253
BENCH:  
BENCH:  Kernel: this
PLUMED:                                               Cycles        Total      Average      Minimum      Maximum
PLUMED:                                                    1     1.973595     1.973595     1.973595     1.973595
PLUMED: 1 Prepare dependencies                         10000     0.006112     0.000001     0.000000     0.000018
PLUMED: 2 Sharing data                                 10000     0.007715     0.000001     0.000000     0.000067
PLUMED: 3 Waiting for data                             10000     0.002298     0.000000     0.000000     0.000016
PLUMED: 4 Calculating (forward loop)                   10000     0.030407     0.000003     0.000002     0.000060
PLUMED: 5 Applying (backward loop)                     10000     0.008156     0.000001     0.000000     0.000027
PLUMED: 6 Update                                       10000     1.865217     0.000187     0.000000     0.007363

Test 2 - calculate

The second test is representative of cases where the PACE is larger so that the cost is mostly in evaluating the potential. Here the speedup is limited but measurable, and is in the Calculating phase.

Command

plumed benchmark --nsteps 100000 --natoms 100

plumed.dat:

d1: DISTANCE ATOMS=1,2
d2: DISTANCE ATOMS=3,4
d3: DISTANCE ATOMS=5,6
c1: CUSTOM ARG=d1 FUNC=sin(x) PERIODIC=NO
c2: CUSTOM ARG=d2 FUNC=sin(x) PERIODIC=NO
c3: CUSTOM ARG=d3 FUNC=sin(x) PERIODIC=NO

METAD ARG=c1,c2,c3 HEIGHT=1.0 GRID_MIN=-1,-1,-1 GRID_MAX=+1,+1,+1 SIGMA=0.1,0.1,0.1 PACE=100000

Results:

BENCH:  Kernel: /Users/bussi/plumed2/tmp/reference/lib/libplumedKernel.dylib
PLUMED:                                               Cycles        Total      Average      Minimum      Maximum
PLUMED:                                                    1     0.697111     0.697111     0.697111     0.697111
PLUMED: 1 Prepare dependencies                        100000     0.038268     0.000000     0.000000     0.000045
PLUMED: 2 Sharing data                                100000     0.057732     0.000001     0.000000     0.000095
PLUMED: 3 Waiting for data                            100000     0.014023     0.000000     0.000000     0.000034
PLUMED: 4 Calculating (forward loop)                  100000     0.258862     0.000003     0.000002     0.000148
PLUMED: 5 Applying (backward loop)                    100000     0.058995     0.000001     0.000000     0.000045
PLUMED: 6 Update                                      100000     0.025503     0.000000     0.000000     0.000064
BENCH:  
BENCH:  Kernel: this
PLUMED:                                               Cycles        Total      Average      Minimum      Maximum
PLUMED:                                                    1     0.642643     0.642643     0.642643     0.642643
PLUMED: 1 Prepare dependencies                        100000     0.040423     0.000000     0.000000     0.000054
PLUMED: 2 Sharing data                                100000     0.054178     0.000001     0.000000     0.000053
PLUMED: 3 Waiting for data                            100000     0.016572     0.000000     0.000000     0.000066
PLUMED: 4 Calculating (forward loop)                  100000     0.214136     0.000002     0.000002     0.000177
PLUMED: 5 Applying (backward loop)                    100000     0.055705     0.000001     0.000000     0.000043
PLUMED: 6 Update                                      100000     0.026816     0.000000     0.000000     0.000047
codecov-commenter commented 4 months ago

Codecov Report

Attention: Patch coverage is 82.70677% with 23 lines in your changes are missing coverage. Please review.

Project coverage is 84.16%. Comparing base (93c5969) to head (fbef9de).

:exclamation: Current head fbef9de differs from pull request most recent head b45b0ae. Consider uploading reports for the commit b45b0ae to get more accurate results

Files Patch % Lines
src/tools/Grid.cpp 80.99% 23 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1030 +/- ## ========================================== - Coverage 84.18% 84.16% -0.03% ========================================== Files 614 614 Lines 56669 56738 +69 ========================================== + Hits 47709 47753 +44 - Misses 8960 8985 +25 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.