Skip to content

Threading and thread safety documentation #1690

Closed

Description

@TiborGY

The documentation of multithreading/thread safety capabilities are currently incomplete.

Case in point, I want to build a Fortran library that makes some BLAS/LAPACK calls, then use this library in a C++ program, that uses C++11 parallelism to call a subrutine from said Fortran library in parallel. If I want the BLAS/LAPACK operations to run single threaded, do I still need to set USE_OPENMP = 1 and NUM_PARALLEL = N, or is it irrelevant if I set USE_THREAD = 0?
What if I wanted to use OpenMP in my C++ code, instead of C++11 parallelism?

So a decision tree of possible use cases or a flowchart would be nice to help choose the proper values for USE_THREAD USE_OPENMP NUM_THREADS NUM_PARALLEL and when to use FCOMMON_OPT = -frecursive

IMO, the number of threading related build time variables, and their relationships to each other are getting more and more numerous, without proper documentation.

Activity

  1. changed the title [-]Thread safety documentation[/-] [+]Threading and thread safety documentation[/+] on Jul 19, 2018
  2. martin-frbg commented on Jul 19, 2018

    @martin-frbg
    Collaborator

    No need to dramatize this, the only recent addition is NUM_PARALLEL which is more of an experimental workaround to allow several instances of OpenBLAS, invoked from different parts of an OpenMP main program, to coexist without trashing thread memory. So you want to set/change this only if you build with USE_OPENMP=1, if at all. When you build with USE_THREAD=0 for a single-threaded OpenBLAS, there is no need to set USE_OPENMP=1 - in fact you will get a warning message from Makefile.system if you try. (It may still be necessary to set NUM_THREADS to a number greater than 1 in some cases just to ensure OpenBLAS allocates a sufficiently sized memory buffer internally).
    When you want to use OpenMP in your C++ code and want a parallel OpenBLAS, it is mandatory to build OpenBLAS with USE_OPENMP=1 to avoid locking conflicts.
    FCOMMON_OPT=-frecursive is a workaround for a thread safety problem inherited from netlib LAPACK, see http://icl.cs.utk.edu/lapack-forum/viewtopic.php?t=1930, so you would normally want to enable this in multithreaded builds.

  3. TiborGY commented on Jul 20, 2018

    @TiborGY
    ContributorAuthor

    OK, thanks for the clarification. I am probably going to expand the wiki with these threading recommendations.
    I have two more questions though:

    • Is there a performance difference between using a single threaded build, and a parallel build set to 1 thread at runtime?
    • (might be a silly question) If the calling program uses OpenMP and parallel OpenBLAS, but all calls into OpenBLAS are outside the parallel region, is it necessary to set USE_OPENMP=1 at build time?
  4. martin-frbg commented on Jul 21, 2018

    @martin-frbg
    Collaborator

    There should be no performance difference with 0.3.1, earlier versions would have some additional overhead from thread memory initialization on startup. About your other question I am not sure, but probably it is safer to build with USE_OPENMP=1 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions