Developer Skill Sprints - Week 3 - Fast Code Faster with Parallel Programming Library

Posted by on in Programming

This blog post contains the notes for week 3 of the developer skill sprint focusing on the Parallel Programming Library

 

Modernizing Your VCL Apps

 

Live sessions every Tuesday
November 4 - December 23, 2014
6AM San Francisco / 9AM New York / 2PM London / 3PM Milan
11AM San Francisco / 2PM New York / 7PM London / 8PM Milan
5PM San Francisco / Wed 10AM Tokyo / Wed 12PM Sydney

The next round of Developer Skill Sprints are here! Join us for this 8-part series on modernizing your VCL apps from start to finish. We'll explore how to update your app's look and feel, utilize multiple processor cores in your app, scale your solution, and extend your apps to wearables and gadgets.


 

Notes

Week 3 - Fast Code Faster with Parallel Programming Library

All Skill Sprint Replays
embt.co/vcl-skill-sprint-youtube


Project Files

Parallel Prime Number C++
Parallel Prime Number Object Pascal
Integer Task C++ & Integer Task Object Pascal


Parallel Programming Library (PPL) Related Links and Videos

CodeRage 9 Snippet - Consuming Object Pascal Code in C++ using Lambdas

embt.co/delphi-anon-methods
One of my favorite C++ track talks at this year's recent CodeRage 9 conference was Bruneau Babet's excellent "Consuming Object Pascal code from C++" session. There were also many other great C++ talks at this year's CodeRage, but this one was really something special. I've extracted a video from a part of Bruneau's talk where he shows how to use C++11 lambdas where an Delphi developer would use Object Pascal Anonymous Methods. In particular, Lambdas can come in very handy to simplify the use of the new Parallel Programming Library (PPL), which is new in C++Builder XE7. Eariler in the CodeRage 9 schedule, I did a C++ track session, "Parallel Programming Library: Create Responsive Apps", showing C++ developers how to use the new PPL. Bruneau took what I demoed to the next level using Lambdas.  I know you will enjoy watching the video snippet and then watching the complete replay for Bruneau's session.

Zip file containing Bruneau's slides and demos can be found at

http://community.embarcadero.com/index.php/en/component/remository/func-download/276/chk,82eb8c95630505b8db7ec6e5a53445b6/no_html,1/

Parallel Programming Library: Create Responsive Object Pascal Apps

embt.co/ppl-op-apps

Create responsive applications that respond immediately to any user request using tasks, futures and parallel loops. Avoid long waits and unresponsive apps with the techniques introduced in this session.


Parallel Programming Library - Architecture (Object Pascal)

embt.co/ppl-op

Allen Bauer, Embarcadero Chief Scientist, will discuss parallel programming along with the architecture and implementations of the new Parallel Programming Library that is included in Delphi XE7, C++Builder XE7, RAD Studio XE7 and Appmethod September 2014.

Parallel Programming Library - Create Responsive C++ Apps

embt.co/ppl-cpp-apps

Create responsive applications that respond immediately to any user request using the new Parallel Programming Library. Avoid long waits and unresponsive apps with the techniques introduced in this session.

Parallel Programming Library - Architecture (C++)

embt.co/ppl-cpp

Allen Bauer, Embarcadero Chief Scientist, will discuss parallel programming along with the architecture and implementations of the new Parallel Programming Library that is included in Delphi XE7, C++Builder XE7, RAD Studio XE7 and Appmethod September 2014.

Parallel Programming Library @Stephen Balls Technical Blog

embt.co/ppl-sball

Using TTask from the Parallel Programming Library

docwiki.embarcadero.com/RADStudio/XE7/en/Using_TTask_from_the_Parallel_Programming_Library

Q/A

Does this mean that the VCL is now thread-safe?
No it does not. The same rules for synchronizing updates for storage and VCL apply if you want to do updates in separate threads.

Does the Parallelized For Loop automatically dispatch the IteratorEvents to all available cores?
Yes - the library will pass to the operating system to use as many cores as are available cores.

Can you control the number of threads/cores to use?
you can create a custom threadpool if you want. otherwise the PPL is self tuning for threads/cores.

Can you use the parallel for with a dataset? How does it allow each thread to be pn a different recordin the dataset?
Yes you can.

Can we use TList on the parallel loop?yes - as long as the diffferent tasks/loops only work on one item.

Is there a way to list all the running TTask threads and to kill any of them?
TTAsk and ITask have several methods and fields you can use.  Start, Cancel, WaitForAny, WaitForAll. See this DocWiki Article for code examples.

Using the TThread object we could apply parralel processing. When we used integers in the Main Process the system took advantage of all processors. But when the main method was using STRINGS the system did not take advantage of the processors.
PPL is built on top of Threads.  Watch Allen Bauer's recent CodeRage 9 session for more architecture info: embt.co/ppl-op

Can you have distinct variables in each thread, e.g. a sub-total for each thread of a loop which does not need synchronising, and that can be subsequently added into a single total?
Yes - you can have local variables in your Tasks, loops, etc - Bruneau Babet shows this in his C++ sesison - consuming Object Pascal in C++ - my recent blog has link to his code: embt.co/delphi-anon-methods

Is the Tot variable global? it is used in the button click event and the iterator event also?
Its a public member of the TForm class.

If I have a list of objects and I need to find one would using the parallel speed that up or would it need to sync to get the object out of the list ?
Use TStopWatch to do timings of your different threads/loops/tasks

Is there a free or community version of Delphi XE7?
30 day free trial version.

 



About
Gold User, Rank: 8, Points: 399
Brian Alexakis is a Product Marketing Manager at Embarcadero Technologies. He is focused on leveraging the connected world of technology to build new experiences for the Internet of Things.

Comments

  • Brian Alexakis
    Brian Alexakis Thursday, 16 April 2015

    Hi Roar, the HTML links have malformed URLs. I'm fixing it now. Thank you for your comment.

  • Roar G1760
    Roar G1760 Thursday, 16 April 2015

    Seems that several of the links above are dead: 404...

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: