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

Pinning affects an external OpenMP library #94

Closed
PetrKryslUCSD opened this issue May 7, 2024 · 7 comments
Closed

Pinning affects an external OpenMP library #94

PetrKryslUCSD opened this issue May 7, 2024 · 7 comments

Comments

@PetrKryslUCSD
Copy link

TLDR: An external OpenMP-equipped C++ library shows no parallel speedup when thread pinning is used. Disabling pinning fixed the issue.

https://discourse.julialang.org/t/openmp-in-a-shared-library-opened-in-julia/113880/9

@carstenbauer
Copy link
Owner

Are you perhaps oversubscribing CPU cores? That is, are Julia threads and the external OpenMP threads maybe running on the same set of CPU cores? This would explain why it works better without thread pinning, because the OS scheduler then has the flexibility to avoid this (as much as possible).

If that's the case you should either avoid thread pinning (as you did) or pin the OpenMP threads as well (e.g. through environment variables) - to different cores, of course.

Otherwise, pinthreads shouldn't effect any OpenMP threads: Julia threads aren't even OpenMP threads, they are pthreads.

@PetrKryslUCSD
Copy link
Author

I do not think the cpu cores are oversubscribed. When the library is called, only a single thread is running.

@carstenbauer
Copy link
Owner

carstenbauer commented May 7, 2024

I don't understand, I thought you have multiple threads? Why would pinning or not pinning make a big/any difference if there is only a single thread running?

In any case, pinthreads doesn't change anything about other OpenMP threads. Hence, AFAICS, this isn't a bug in ThreadPinning.jl.

(Also, you neither provide much information nor a MWE, which makes this hard/impossible to figure out.)

@carstenbauer carstenbauer closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2024
@PetrKryslUCSD
Copy link
Author

PetrKryslUCSD commented May 7, 2024

The issue was intended as a heads up. I'm working on a minimal working example.

The application runs with multiple threads. However at the point where the library gets called, only a single thread is running. The issue is real: enabling or disabling pin threading affects the performance of the external library.

@carstenbauer
Copy link
Owner

The issue is real: enabling or disabling pin threading affects the performance of the external library.

To be clear, I'm not arguing that your performance issue isn't real. I'm saying that it (almost certainly) isn't a bug in ThreadPinning.jl.

Of course, feel free to continue the discussion in the Discourse thread. However, much more information will be needed, like:

  • When you call into the library from - IIUC - a single Julia thread, how many OpenMP threads are active?
  • Where are the OpenMP threads running? Have you pinned them? If so, how?
  • Which system are you running on? Laptop? Cluster? Which CPU?
  • Is data passed between Julia and the library? If so, is the data, perhaps, local to the Julia thread but far away from the OpenMP thread(s)?
  • ...

@PetrKryslUCSD
Copy link
Author

PetrKryslUCSD commented May 9, 2024

Here is the minimal working example (https://www.dropbox.com/scl/fi/3dezt0lp10pdflcq9479z/mwe_eclgraphcolor.tgz?rlkey=14w67j59xz3uk3fczergzhhmu&dl=0).

Here is a sample output:


pkrysl@horntail:~/mwe_eclgraphcolor$ . ./run_mwe.sh
================================================================================
With 1 thread
================================================================================
  Activating project at `~/mwe_eclgraphcolor`
[ Info: Loading ThreadPinning
   Resolving package versions...
  No Changes to `~/mwe_eclgraphcolor/Project.toml`
  No Changes to `~/mwe_eclgraphcolor/Manifest.toml`
    Updating git-repo `https://github.com/PetrKryslUCSD/ECLGraphColor.jl.git`
   Resolving package versions...
  No Changes to `~/mwe_eclgraphcolor/Project.toml`
  No Changes to `~/mwe_eclgraphcolor/Manifest.toml`
    Building ECLGraphColor → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/28351fdf0c4c6de0974f0f560c914d6bfd9411dc/build.log`
  0.560385 seconds
  Activating project at `~/mwe_eclgraphcolor`
[ Info: NO ThreadPinning
    Updating git-repo `https://github.com/PetrKryslUCSD/ECLGraphColor.jl.git`
   Resolving package versions...
  No Changes to `~/mwe_eclgraphcolor/Project.toml`
  No Changes to `~/mwe_eclgraphcolor/Manifest.toml`
    Building ECLGraphColor → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/28351fdf0c4c6de0974f0f560c914d6bfd9411dc/build.log`
  0.498791 seconds
================================================================================
With 2 threads
================================================================================
  Activating project at `~/mwe_eclgraphcolor`
[ Info: Loading ThreadPinning
   Resolving package versions...
  No Changes to `~/mwe_eclgraphcolor/Project.toml`
  No Changes to `~/mwe_eclgraphcolor/Manifest.toml`
    Updating git-repo `https://github.com/PetrKryslUCSD/ECLGraphColor.jl.git`
   Resolving package versions...
  No Changes to `~/mwe_eclgraphcolor/Project.toml`
  No Changes to `~/mwe_eclgraphcolor/Manifest.toml`
    Building ECLGraphColor → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/28351fdf0c4c6de0974f0f560c914d6bfd9411dc/build.log`
  0.564154 seconds
  Activating project at `~/mwe_eclgraphcolor`
[ Info: NO ThreadPinning
    Updating git-repo `https://github.com/PetrKryslUCSD/ECLGraphColor.jl.git`
   Resolving package versions...
  No Changes to `~/mwe_eclgraphcolor/Project.toml`
  No Changes to `~/mwe_eclgraphcolor/Manifest.toml`
    Building ECLGraphColor → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/28351fdf0c4c6de0974f0f560c914d6bfd9411dc/build.log`
  0.280195 seconds
================================================================================
With 4 threads
================================================================================
  Activating project at `~/mwe_eclgraphcolor`
[ Info: Loading ThreadPinning
   Resolving package versions...
  No Changes to `~/mwe_eclgraphcolor/Project.toml`
  No Changes to `~/mwe_eclgraphcolor/Manifest.toml`
    Updating git-repo `https://github.com/PetrKryslUCSD/ECLGraphColor.jl.git`
   Resolving package versions...
  No Changes to `~/mwe_eclgraphcolor/Project.toml`
  No Changes to `~/mwe_eclgraphcolor/Manifest.toml`
    Building ECLGraphColor → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/28351fdf0c4c6de0974f0f560c914d6bfd9411dc/build.log`
  0.595618 seconds
  Activating project at `~/mwe_eclgraphcolor`
[ Info: NO ThreadPinning
    Updating git-repo `https://github.com/PetrKryslUCSD/ECLGraphColor.jl.git`
   Resolving package versions...
  No Changes to `~/mwe_eclgraphcolor/Project.toml`
  No Changes to `~/mwe_eclgraphcolor/Manifest.toml`
    Building ECLGraphColor → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/28351fdf0c4c6de0974f0f560c914d6bfd9411dc/build.log`
  0.155279 seconds
pkrysl@horntail:~/mwe_eclgraphcolor$

Two Julia files are provided: one adds, uses ThreadPinning (mwe_w.jl). This one does not get any speed up on the graph calculation.

The other one does (mwe_wo.jl).

@PetrKryslUCSD
Copy link
Author

@carstenbauer Carsten, I am not saying that it is a bug in ThreadPinning. It would be interesting to find out why thread pinning affects OpenMP threads, though. Wouldn't you agree?

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