14
EMBARCADERO TECHNOLOGIES Parallel For Loops with the PPL Jim McKeeth Lead World Wide Developer Evangelist / Engineer [email protected] @JimMcKeeth Tuesday, the 3 rd February, 2015 Download a free trial – NOW! hOp://embt.co/trialdownloads

Parallel For Loops with the Parallel Programming Library

Embed Size (px)

Citation preview

Page 1: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  EMBARCADERO  TECHNOLOGIES  

Parallel  For  Loops  with  the  PPL  Jim  McKeeth  Lead  World  Wide  Developer  Evangelist  /  Engineer  [email protected]  @JimMcKeeth  

Tuesday,  the  3rd  February,  2015  Download  a  free  trial  –  NOW!  hOp://embt.co/trialdownloads    

Page 2: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

How  Skill  Sprints  Work.  -­‐  Agenda  

•  READY  –  Tips  tricks  &  short  URLS    

 •  SET  –  20  minutes,  1  topic  

  •  GO  –  Demo  and  discussion  –  Live  Q&A  

 

Download  a  free  trial  –  NOW!  hOp://embt.co/trialdownloads    

Page 3: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

This  Skill  Sprint  Works  with  .  .  .  

•  Windows  •  Mac  OS  X  •  Android  •  iOS  •  RAD  Studio  •  Appmethod  •  Object  Pascal  •  C++  

•  RAD  Studio  XE7  DocWiki  –  hOp://embt.co/latestdocwiki  

hOp://docwiki.embarcadero.com/RADStudio/en/    

•  Appmethod  September  2014  DocWiki  –  hOp://embt.co/AppmethodTopics  

hOp://docwiki.appmethod.com/appmethod/topics/en/  •  Appmethod  supports  the  FireMonkey  

framework  on  all  4  pla]orms  while  RAD  Studio,  Delphi  and  C++Builder  also  support  VCL  on  Windows.  Contact  sales  with  any  quesaons!  

Page 4: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

Parallel  For  Loops  with  the  PPL  

•  Quickly  and  easily  supercharge  your  code  with  Parallel  For  Loops  

•  Part  of  the  new  Parallel  Programming  Library  •  Works  with  C++  and  Object  Pascal  on  all  pla]orms  •  Take  advantage  of  processor  architectures  like  hyper-­‐threading  and  mulaple  cores  present  in  most  mobile  devices,  desktops  and  laptops  

Page 5: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

Parallel  For  Loops  with  the  PPL  

•  Uses  System.Threading  unit  •  Like  a  normal  For  loop,  but  spread  across  thread  pool  •  Each  iteraaon  is  a  TTask  in  the  thread  pool  •  Order  of  iteraaons  is  undetermined  •  Pool  opamizes  for  CPU  architecture  •  Stride  allows  for  control  of  iteraaon  grouping  

Page 6: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

Parallel  For  Loop  Syntax  

TParallel.For(Stride,  Min,  Max,  procedure  (Idx:  Integer)  begin      if  IsPrime(Idx)  then        begin          TInterlocked.Increment  (Tot);          TThread.Queue(TThread.CurrentThread,  procedure            begin              Memo1.Lines.Add(Idx.ToString);          end);      end;  end);  

You  can  use  Queue  and  Synchronize  from  a  Parallel  For,  but  it  reduces  the  performance.  

Page 7: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

Parallel  For  Loop  Syntax  //  .  .  .  TParallel::For(NULL,  Min,  Max,  MyIteratorEvent);  //  .  .  .      void  __fastcall  TFormThreading::MyIteratorEvent(TObject  *Sender,  int  AIndex)  {  

 if(IsPrime(AIndex)){      TInterlocked::Increment(Tot);    };  

}  

Page 8: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

DEMONSTRATION  Parallel  For  Loops  with  the  Parallel  Programming  Library  

Page 9: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

Parallel  For  Loops  with  the  PPL  

•  Uses  System.Threading  unit  •  Quickly  and  easily  supercharge  your  code  with  Parallel  For  Loops  

•  Each  iteraaon  must  be  independent  of  order  •  Reduce  runame  on  mulaprocessor  systems  

Page 10: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

Parallel  For  Resources  

•  Samples  –  C:\Users\Public\Documents\Embarcadero\Studio\15.0\Samples\Object  Pascal\RTL\Parallel  Library  –  C:\Users\Public\Documents\Embarcadero\Studio\15.0\Samples\CPP\RTL\Parallel  Library  

•  DocWiki  Tutorials  –  hOp://docwiki.embarcadero.com/RADStudio/XE7/en/

Using_TParallel.For_from_the_Parallel_Programming_Library    

•  Blog  Posts  –  CodeRage  9  Video  hOp://dannywind.nl/delphi/coderage9/    –  Stephen  Ball’s  series  hOp://delphiaball.co.uk/tag/parallel-­‐programming/    –  Malcolm  Groves’  series  hOp://www.malcolmgroves.com/blog/?cat=109    –  Examples,  links  and  more:  hIp://delphi.org/?p=1886  (Including  the  C++  Lambda  links)  

Special  offers:  hOp://embarcadero.com/radoffer/    

Page 11: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

Next  Time….  

•  FireDAC:  Cached  Updates  and  Auto-­‐inc  Fields  •  Defer  posang  updates  to  a  database  •  Post  mulaple  updates  in  a  single  batch  •  Thursday  the  5th  of  February  

–  6AM  San  Francisco  /  9AM  New  York  /  2PM  London  /  3PM  Milan  –  11AM  San  Francisco  /  2PM  New  York  /  7PM  London  /  8PM  Milan  –  5PM  San  Francisco  /  Fri  9AM  Tokyo  /  Fri  10AM  Sydney  

Sign-­‐up:  hOp://www.embarcadero.com/landing-­‐pages/skill-­‐sprints    

Page 12: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

Next  Time….  

•  Deep  Dive  into  Futures  and  the  PPL  •  Create  more  responsive  apps  •  Futures  calculate  values  asynchronously  •  Tuesday  the  10th  of  February  

–  6AM  San  Francisco  /  9AM  New  York  /  2PM  London  /  3PM  Milan  –  11AM  San  Francisco  /  2PM  New  York  /  7PM  London  /  8PM  Milan  –  5PM  San  Francisco  /  Wed  9AM  Tokyo  /  Wed  10AM  Sydney  

Special  offers:  hOp://embarcadero.com/radoffer/    

Page 13: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  

RAD  Studio  XE7  Special  Offers  

More  details  hOp://www.embarcadero.com/radoffer  

Save  45%  when  upgrading  from  any  previous  version  

 When  you  purchase  the  

upgrade  with  1  year  Support  and  Maintenance!  

Build  a  Mobile  Pla]orm  for  the  Enterprise  

 With  Enterprise  ediCon  or  higher.  

Powerful  Tools  to  Boost  Your  Coding  (Worth  Over  $700)  

•  New  Object  Pascal  Handbook  by  Marco  Cantu    

•  Castalia  for  Delphi  2014.11  •  VCL  and  FireMonkey  Premium  Styles  

•  Mida  Converter  Basic  

Page 14: Parallel For Loops with the Parallel Programming Library

EMBARCADERO  TECHNOLOGIES  EMBARCADERO  TECHNOLOGIES  

Q  &  A    @EmbarcaderoTech  

Special  offers:  hOp://embarcadero.com/radoffer/