1 / 25

Parallel Programming Done Right with OTL and PPL

Parallel Programming Done Right with OTL and PPL. Primo ž Gabrijelčič. About me. Pascal programmer since 1984 (HiSoft pascal on ZX Spectrum) First contact with Borland: Turbo Pascal 3 (on CP/M) Programming highly responsive 24/7 applications since 1997

wmichaelson
Download Presentation

Parallel Programming Done Right with OTL and PPL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Parallel Programming Done Right with OTL and PPL Primož Gabrijelčič

  2. About me • Pascal programmer since 1984 (HiSoft pascal on ZX Spectrum) • First contact with Borland: Turbo Pascal 3 (on CP/M) • Programming highly responsive 24/7 applications since 1997 • Writer: The Delphi Magazine, Blaise Pascal, Monitor (Slovenia) • Blogger: http://thedelphigeek.com • Contact me: http://primoz.gabrijelcic.org

  3. Multithreading

  4. Multithreading is hard “New programmers are drawn to multithreading like moths to flame, with similar results.” - Danny Thorpe

  5. Solution • Extract all hard parts into a boilerplate code. • Test it. Test again. Test repeatedly. • Reuse as much as possible. • Test again. Don’t stop testing. – or – • Use existing library. • Continue testing.

  6. When to do it? • Unblocking GUI • Long calculations • Synchronous APIs • File system • (Serial) communication • Speeding up the computation • Faster calculation • More/less appropriate tasks (algorithms) • Serving more than one client at once

  7. Patterns

  8. Adapt algorithm to the pattern • Don‘t write the code for your algorithm • Decompose the algorithm into patterns • Use those patterns in the code • When everything fails, go low-level • Tasks first, threads last

  9. Frameworks • PPL • Parallel Programming Library • XE7+, all platforms, RTL license • patterns: For, Future, Join • OTL • OmniThreadLibrary • 2009+ (patterns), 2007+ (tasks), Windows (VCL/console/service) only, OpenBSD license • patterns: Async[/Await], Background worker, For, Fork/Join, Future, Join, Map, Parallel task, Pipeline • http://www.omnithreadlibrary.com/

  10. Dish of the day • Async/Await • Fire asynchronous tasks • Future • Execute long calculation in background • For • Use all of available CPUs when processing large data • Map • Converting data in parallel • TimedTask • Just like TTimer, but running in a thread

  11. Async/Await

  12. Future

  13. For

  14. Map

  15. TimedTask

  16. Other OmniThreadLibrarypatterns

  17. ForEach

  18. ParallelTask

  19. Join

  20. Pipeline

  21. Fork/Join

  22. Get more information • http://www.omnithreadlibrary.com/tutorials.htm • “Parallel Programming with OmniThreadLibrary” • https://leanpub.com/omnithreadlibrary • http://otl.17slon.com/book

  23. Keep in mind

  24. Important Facts We Learned Today • Don’t write boilerplate code – use patterns • Be careful when accessing shared data • Never access the GUI from a background thread!

  25. Q & A

More Related