Threading: cpu topology, worker lanes and parallel for #3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "threading"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Base:
master@e63b7dd(rebased after #2 merged). Three primitives, no caller context — they know CPUs, queues and loops, nothing about which thread is the foreground thread.pause()to drain on the calling thread. An optional thread-start hook runs once per lane so a caller can pin or name it.a75fdc610etob03e478afdb03e478afdtodf3dcbe5b1Threading: a library module for thread placement, worker lanes and parallel forto Threading: cpu topology, worker lanes and parallel for@ -0,0 +1,43 @@#pragma oncer u sure there is no implementation of that in the latest c++ standard?
@ -0,0 +1,21 @@#pragma oncer u sure there is no implementation of that in the latest c++ standard?
also what configurations does that interface support
can i pin n threads to i hardware thread and k threads to j hardrare thread?
that is the limit?
also name it thread pinning
@ -0,0 +1,219 @@#pragma oncer u sure there is no implementation of that in the latest c++ standard?
df3dcbe5b1to40a3535393Answers, and the code changed accordingly (
15b18a8instead of the placement commit; still three commits).Is there a standard implementation?
std::executionstandardises schedulers, not affinity.std::thread::native_handle()is the only escape hatch, sosched_setaffinity/SetThreadAffinityMaskstay in our hands.pause()/drain.std::for_each(std::execution::par, ...)exists since C++17. It gives no control over the thread count, no thread-start hook (so no pinning) and no guarantee about who takes part. That is whatParallelForadds. Say the word if you would rather drop it and use the standard algorithms.What configurations does pinning support? Any mapping, one thread at a time:
pinCallingThread(cpus)sets the affinity of the calling thread to an arbitrary cpu set. So "n threads on cpu group i, k on group j" is expressible — each thread pins itself (or is pinned from outside via its thread-start hook). What the interface does not have is a declarative n-to-m configuration;siblingGroups()only tells you which cpus share a physical core.Renamed to
ThreadPinning, and theLayout/layoutForsplit ("pinned group vs the rest") is gone — that was caller policy, not a primitive. What is left isallowedCpus(),siblingGroups(),pinCallingThread(), with a test that pins two threads to two different groups.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.