Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up DFT calculations with vector dual numbers #73

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

prehner
Copy link
Contributor

@prehner prehner commented Nov 11, 2022

Implementation

This PR improves the speed of DFT calculations without affecting the convergence at all. Instead, vector dual numbers are used to calculate first and second partial derivatives of the Helmholtz energy. Having functions that are generic over the number of weighted densities in the FunctionalContribution trait makes it not object safe. Therefore, it is instead implemented via a derive macro.

Execution times

This PR replaces one AD method with another one; both produce exact (up to machine precision) derivatives. Therefore, no difference in convergence is to be expected.

Some benchmarks:

model components/segments time old time new
FMT 1 55.3 ms 37.1 ms
PC-SAFT 1 74.7 ms 54.6 ms
PC-SAFT 2 208 ms 124 ms
gc-PC-SAFT 4 23.1 s 7.95 s

Compilation time

The new code generates a lot of additional code. While this is necessary to increase performance, it also slows down the compilation (and increases binary size). As compromise, the optimization is only applied for mixtures with up to 5 (PC-SAFT) or 3 (PeTS) components, and 10 (gc-PC-SAFT) segments.

@prehner prehner added enhancement New feature or request DFT DFT related feature or issue labels Nov 13, 2022
@prehner prehner marked this pull request as draft December 3, 2022 13:27
@prehner
Copy link
Contributor Author

prehner commented Dec 15, 2022

With the lto profile being merged the performance gains change somewhat:

model components/segments main (release) main (lto) new (release) new (lto)
FMT 1 50.6 ms 28.2 ms 34.3 ms 27.9 ms
PC-SAFT 1 68.3 ms 27.6 ms 53.1 ms 30.1 ms
PC-SAFT 2 205 ms 89.9 ms 139 ms 85.5 ms
gc-PC-SAFT 4 4.13 s 2.21 s 1.35 s 0.80 s
compile time 2 min 37 s 8 min 34 s 4 min 41 s 13 min 53 s

compile times are measured after cargo clean.

@prehner prehner added the wontfix This will not be worked on label Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DFT DFT related feature or issue enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant