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

Thread safety of the Fortran and C++ wrappers. #9

Open
JacekHoleczek opened this issue Jan 9, 2020 · 1 comment
Open

Thread safety of the Fortran and C++ wrappers. #9

JacekHoleczek opened this issue Jan 9, 2020 · 1 comment

Comments

@JacekHoleczek
Copy link

JacekHoleczek commented Jan 9, 2020

I played with the current QCDLoop git master (2.0.4 as of 2020.01.07 20:27 UTC), making sure that I have "-DENABLE_FORTRAN_WRAPPER=ON".

While trying the "examples/fortran_test.f", I get a runtime warning saying that the Fortran "wrapper is not thread-safe".

Could you, please, be more specific why?

According to the GNU Fortran Compiler "Thread-safety of the runtime library" docs chapter, there should be no big problems (well, one might want to add "-frecursive" when compiling Fortran code).

At the same time, there appears also another runtime message saying that one should "consider developing object-oriented code", which seems to suggest that the provided C++ wrapper is thread-safe.

However, in this case I would expect that all C / C++ source code files are compiled and linked (i.e. object files, shared libraries and executables) with use of the gcc / g++ "-pthread" flag (at least on Linux). This does not seem to be the case (i.e. you do not use this flag at all).

The https://arxiv.org/pdf/1605.03181.pdf paper says (on page 9):

The native c++ interface of the QCDLoop library is thread-safe only when the caching algorithms are switched off. It is particularly important to highlight that the fortran wrapper is not thread-safe by construction.

Could you, please, be more specific how do you achieve the thread safety of the C++ wrapper (and then why the Fortran wrapper, which is also written in C, is not thread-safe)?

@scarrazza
Copy link
Owner

Thanks for opening this discussion.

The code in C++ uses internal states, so concurrent calls can be achieved by using techniques like:

  • creating a single class instance per thread
  • using openmp with critical regions
    However, we do not have any lock/mutex statements in the code, that's why we say that the fortran interface (which is based on a unique class instance) is not thread-safe or friendly.

I believe the compiler flags you are referring are suitable for particular implementations where you delegate the class allocation to external threads, but they do not control the internals states of this library. However, this may require some extra investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants