question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build flag to force enable/disable OpenMP

See original GitHub issue

It would be nice to have a build flag in setup.py to control whether OpenMP is used or not. There are a few cases where users might want to control this.

Currently on macOS if the system GCC is picked up, it tries to enable OpenMP, which doesn’t necessarily work. Also the current build assumes that OpenMP is not supported when using Clang on macOS, but this depends on whether Apple Clang is used or some other Clang build, which does support OpenMP.

When GCC is used, then GOMP is in use, which has been shown to be not fork safe. So users may decide that they would rather not build with OpenMP support when using this compiler or when they know they plan to fork.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:34 (34 by maintainers)

github_iconTop GitHub Comments

1reaction
NicolasHugcommented, Mar 31, 2019

It’s not just omp_get_num_threads, it’s all the functions in openmp.pxd, because who knows what we might need in the future? Here’s that file:

cdef extern from "<omp.h>":
    ctypedef struct omp_lock_t:
        pass
    ctypedef struct omp_nest_lock_t:
        pass

    ctypedef enum omp_sched_t:
        omp_sched_static = 1,
        omp_sched_dynamic = 2,
        omp_sched_guided = 3,
        omp_sched_auto = 4

    extern void omp_set_num_threads(int) nogil
    extern int omp_get_num_threads() nogil
    extern int omp_get_max_threads() nogil
    extern int omp_get_thread_num() nogil
    extern int omp_get_num_procs() nogil

    extern int omp_in_parallel() nogil

    extern void omp_set_dynamic(int) nogil
    extern int omp_get_dynamic() nogil

    extern void omp_set_nested(int) nogil
    extern int omp_get_nested() nogil

    extern void omp_init_lock(omp_lock_t *) nogil
    extern void omp_destroy_lock(omp_lock_t *) nogil
    extern void omp_set_lock(omp_lock_t *) nogil
    extern void omp_unset_lock(omp_lock_t *) nogil
    extern int omp_test_lock(omp_lock_t *) nogil

    extern void omp_init_nest_lock(omp_nest_lock_t *) nogil
    extern void omp_destroy_nest_lock(omp_nest_lock_t *) nogil
    extern void omp_set_nest_lock(omp_nest_lock_t *) nogil
    extern void omp_unset_nest_lock(omp_nest_lock_t *) nogil
    extern int omp_test_nest_lock(omp_nest_lock_t *) nogil

    extern double omp_get_wtime() nogil
    extern double omp_get_wtick() nogil

    void omp_set_schedule(omp_sched_t, int) nogil
    void omp_get_schedule(omp_sched_t *, int *) nogil
    int omp_get_thread_limit() nogil
    void omp_set_max_active_levels(int) nogil
    int omp_get_max_active_levels() nogil
    int omp_get_level() nogil
    int omp_get_ancestor_thread_num(int) nogil
    int omp_get_team_size(int) nogil
    int omp_get_active_level() nogil

Possible?

Probably

Worthwhile?

I really don’t think we want to go down that road. What if there’s a routine in openmp.pxd that we cannot mock properly? We would have to provide both parallel and sequential implementations.

I might be wrong but it seems to me that the only ones who would benefit from this are mac users who:

  1. need to build sklearn. We can probably assume these are potential contributors, because if the need is just to use the latest version, then we have nightly builds now
  2. don’t want to set flags
  3. don’t want to install openmp via brew

So basically we are missing on potential contributors using macos that don’t want to do 2. and 3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turn off OpenMP - c++ - Stack Overflow
You can use the environment variable: set OMP_NUM_THREADS=1. Actually, it will not turn OpenMP off. It will force OpenMP to create only one ......
Read more >
C H A P T E R 5 - Compiling for OpenMP
To enable explicit parallelization with OpenMP directives, compile your program with the cc, CC, or f95 option flag -xopenmp. This flag can take...
Read more >
Optimize Options (Using the GNU Compiler Collection (GCC))
Otherwise -Og enables all -O1 optimization flags except for those that may ... If you want to force the compiler to check if...
Read more >
2.4 Building with make - Quantum Espresso
To install the QUANTUM ESPRESSO source package using make, ... configure –enable-openmp. ... make.inc, compilation rules and flags (used by Makefile).
Read more >
A “Hands-on” Introduction to OpenMP*
◇Help us improve … tell us how you would make this ... Disable dynamic adjustment of the ... Flush forces data to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found