Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bartosz Milewski. Cilk (MIT, Cilk Arts, Intel Cilk+) Parallel Haskell Microsoft UMS Threads (User-Mode Scheduling) (Only 64-bit and Server) Microsoft.

Similar presentations


Presentation on theme: "Bartosz Milewski. Cilk (MIT, Cilk Arts, Intel Cilk+) Parallel Haskell Microsoft UMS Threads (User-Mode Scheduling) (Only 64-bit and Server) Microsoft."— Presentation transcript:

1 Bartosz Milewski

2 Cilk (MIT, Cilk Arts, Intel Cilk+) Parallel Haskell Microsoft UMS Threads (User-Mode Scheduling) (Only 64-bit and Server) Microsoft PPL (Parallel Patterns Library) Intel TBB (Threading Building Blocks) JVM/.NET-based languages and libraries

3 Programmer: What can be run in parallel Identify tasks System: What will be run in parallel Assign tasks to threads/processors System: Load balancing, work stealing System: Dealing with blocked tasks Take them off thread, reuse thread Create new UMS thread

4 Core 1 Core 2 Core 3 Core 4 Task 1 Task 5 Task 2 Task 3 Task 4 Task 6 OversubscribedIdle

5 Core 1 Core 2 Core 3 Core 4 Task 1 Task 5 Task 2 Task 3 Task 4 Task 6 Busy

6 Core 1 Core 2 Core 3 Core 4 Task 2 Task 4 Busy Idle

7 Abstraction level Threads: low Tasks: high Resource usage Threads: heavy-weight Tasks: lightweight Problem solving Threads: improve latency Tasks: improve throughput Level of parallelism Threads: large grain Tasks: fine grain

8

9 void thFun(std::promise & prms) { std::string str("Hello from future!"); prms.set_value(str); } void test() { std::promise prms; std::future ftr = prms.get_future(); std::thread th(&thFun, std::ref(prms)); std::cout << "Hello from main!\n"; std::string str = ftr.get(); th.join(); std::cout << str << std::endl; }

10 std::string taskFun() { std::string str("Hello from task!"); return str; } void test() { std::future ftr = std::async(&taskFun); std::cout << "Hello from main!\n"; std::string str = ftr.get(); std::cout << str << std::endl; }

11 (30.6.8) The template function async provides a mechanism to launch a function potentially in a new thread and provides the result of the function in a future object with which it shares a shared state. Launch Policies launch::async launch::deferred launch::any (default) Deferred tasks execute in the context of the forcing thread What if the future is not forced?

12 Global, file-static, class-static, function-static Each thread initializes them separately Each thread destroys them at the end Tasks with launch::async thread_locals must be destroyed Before future::get (or future::wait) returns, or Before future is destructed without forcing Tasks with launch::deferred thread_locals follow the lifetime of the forcing thread

13 thread_local “as if” task_local At task completion, destroy thread_locals Starting a new task on an old thread: re-initialize all thread_locals Problems Library/runtime hooks for thread_local management TlsAlloc DLL_THREAD_ATTACH/DETACH calls to DllMain

14 Take a blocked task off a thread Detect blocked tasks Save task state, including thread_locals Restore a taks to a thread Detect unblocked tasks Restore task state, including thread_locals Problems Mutexes are thread-aware Potential for spurious deadlocks (not really)

15 C++ tasks are ill-fitted for task-based parallelism When designing a task-parallel library, consider thread_local vs task-local mutex (im-)mobility See description of Lockable in the Standard Blocking tasks

16 Blog: http://blog.corensic.com/2011/10/10/async- tasks-in-c11-not-quite-there-yet/ http://blog.corensic.com/2011/10/10/async- tasks-in-c11-not-quite-there-yet/ C++11 tutorial: http://www.corensic.com/Learn/Resources/Co ncurrencyTutorialPartFive.aspx http://www.corensic.com/Learn/Resources/Co ncurrencyTutorialPartFive.aspx Proposals: http://www.open- std.org/jtc1/sc22/wg21/docs/papers/2009/n288 0.html http://www.open- std.org/jtc1/sc22/wg21/docs/papers/2009/n288 0.html http://www.open- std.org/jtc1/sc22/wg21/docs/papers/2010/n303 8.html http://www.open- std.org/jtc1/sc22/wg21/docs/papers/2010/n303 8.html


Download ppt "Bartosz Milewski. Cilk (MIT, Cilk Arts, Intel Cilk+) Parallel Haskell Microsoft UMS Threads (User-Mode Scheduling) (Only 64-bit and Server) Microsoft."

Similar presentations


Ads by Google