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

Avoid doing extra TLS lookups in FunctionParser. #13745

Merged
merged 1 commit into from May 19, 2022

Conversation

drwells
Copy link
Member

@drwells drwells commented May 16, 2022

Fixes #13578 to the largest extent possible right now. There may be better thread locking and unlocking strategies but by moving some things around I can evaluate simple expressions about 3x faster.

While we are at it, get rid of the calls to begin_raw() and end_raw() (they are deprecated).

@masterleinad
Copy link
Member

Would you mind explaining some more what changed? I see that you introduced another data structure but which part is actually responsible for reducing the number of calls to lock the mutex?

Comment on lines 267 to 300
* std::is_copy_constructible gives the wrong answer for containers with
* non-copy constructible types (e.g., std::vector<std::unique_ptr<int>>).
* Work around that problem by defining our own explicitly uncopyable
* per-thread data class (instead of, e.g., using std::pair).
*
* We define exactly one per-thread data structure to avoid locking and
* unlocking the TLS data lookup more than once per function call.
*/
mutable Threads::ThreadLocalStorage<std::vector<double>> vars;
struct ParserData
{
ParserData() = default;

ParserData(const ParserData &) = delete;

/**
* Scratch array used to set independent variables (i.e., x, y, and z)
* before each muParser call.
*/
std::vector<double> vars;

/**
* muParser implementations.
*/
std::vector<std::unique_ptr<internal::muParserBase>> parsers;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the exact same class as for the function_parser.h file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I need to move some more functions into mu_parser_internal.h - if its OK with you I would like to do that refactoring in the next PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

include/deal.II/base/function_parser.h Outdated Show resolved Hide resolved
source/base/function_parser.cc Show resolved Hide resolved
source/base/function_parser.cc Show resolved Hide resolved
Copy link
Member

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from Wolfgang's comment, this looks good to me. Thank you for pointing out the relevant changes!

While we are at it, get rid of the calls to begin_raw() and end_raw() (they are
deprecated).
@masterleinad masterleinad merged commit 31b3dae into dealii:master May 19, 2022
@bangerth
Copy link
Member

Thanks for fixing this and to @masterleinad for doing the merge. I'm at the ASPECT hackathon, it's been a busy week.

mkghadban pushed a commit to OpenFCST/dealii that referenced this pull request Sep 8, 2022
Avoid doing extra TLS lookups in FunctionParser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TLS is quite slow
3 participants