easy parallel computing in perl5 for multi-core cpusin perl5 for multi-core cpus darko obradovic my...
TRANSCRIPT
![Page 1: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/1.jpg)
Easy Parallel Computingin Perl5
for Multi-Core CPUs
Darko Obradovic
![Page 2: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/2.jpg)
My history:15 years of
linear programmingin Perl5
![Page 3: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/3.jpg)
April 2007:First dual-core CPU
![Page 4: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/4.jpg)
October 2012:Xeon E5
(4x3,2GHz, 4x3MB Cache, 8 logical cores)+ 64GB of RAM
![Page 5: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/5.jpg)
since then:linear programming
= bad conscience
![Page 6: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/6.jpg)
August 2018:32-core CPU?
![Page 7: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/7.jpg)
… finally made me thinkingabout parallel programming
![Page 8: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/8.jpg)
A search for "parallel"on CPAN returns 727 resultsmodules for different purposes
![Page 9: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/9.jpg)
parallel
async
distributed
master/slave
![Page 10: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/10.jpg)
parallelsimultaneous calculation
usually splits calculations todifferent processes
typically uses forking
Parallel::ForkManager
![Page 11: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/11.jpg)
asyncnon-blocking execution
usually to overcome I/O latencyand for event-driven programming
typically uses callbacks
LWP::Parallel
![Page 12: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/12.jpg)
master/slaveparallel server implementation
usually to handle many requests,event-driven dispatching
typically uses workers/preforking
Parallel::PreforkParallel::ScoreBoard
![Page 13: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/13.jpg)
distributedsimultaneous distributed calculation
distributes larger chunks of workto different machines
typically uses MapReduce
Parallel::MapReduce
![Page 14: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/14.jpg)
parallelsimultaneous calculation
usually splits calculations todifferent processes
typically uses forking
Parallel::ForkManager
![Page 15: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/15.jpg)
processes vs threads
![Page 16: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/16.jpg)
processprogram + data + resources
can be forked= clone of the process
very robustno shared address space
![Page 17: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/17.jpg)
UNIX thread"lightweight" process
shared address space & resources→ more efficient, more fragile
create, join, yield, ...
perl threadno shared address space
![Page 18: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/18.jpg)
so how to start in Perl5?
TIMTOWTDI
![Page 19: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/19.jpg)
subs::parallelParallel::Loops
Parallel::Simple::DynamicParallel::ForkManager
Parallel::SimpleParallel::Iterator
Parallel::parallel_mapParallel::Runner
Parallel::QueueWorkerParallel::QueueParallel::Jobs
Parallel::Forker
Proc::ParallelParallel::DataPipeParallel::Workers
Job::ManagerParallel::SubForkParallel::SubArrayParallel::MapReduceParallel::SupervisorProc::ParallelLoop
Parallel::Fork::BossWorkerParallel::ForkControlParallel::ThreadContext
CPAN modules suitable forsimultaneous calculation
on Multi-Core CPUs
![Page 20: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/20.jpg)
laziness...we want to keep it simple!
no process/thread managementor synchronization
“get it parallelized in a minute!”
![Page 21: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/21.jpg)
Parallel::Simple
demo example
![Page 22: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/22.jpg)
Parallel::Simple
● no return values
● changes in memory are lost
→ only parts not changing state
● makes sense with 2+ cores
![Page 23: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/23.jpg)
Parallel::parallel_map
demo example
![Page 24: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/24.jpg)
Parallel::parallel_map
● only maps without side-effects
● efficiently with N forks
→ from %ENV or /proc/cpuinfo
● merges return values
![Page 25: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/25.jpg)
subs::parallel
demo example
![Page 26: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/26.jpg)
subs::parallel
● one fork per sub call
● waits when return values are used
● based on Perl threads
● seems to have issues
![Page 27: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/27.jpg)
on my Xeon:4 processes = speedup 3
![Page 28: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/28.jpg)
what about logical cores?(Intel's HyperThreading)
![Page 29: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/29.jpg)
the problem:CPU pipelining
![Page 30: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/30.jpg)
![Page 31: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/31.jpg)
the issue:pipeline is partly empty
![Page 32: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/32.jpg)
Intel PIII:11 pipeline stages
Intel P4:20 pipeline stages
![Page 33: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/33.jpg)
the solution:share a physical pipelinefor two logical threads
![Page 34: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/34.jpg)
on my Xeon:4 processes = speedup 38 processes = speedup 4
![Page 35: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/35.jpg)
… so parallelizing is very simplein Perl5 for some problems
![Page 36: Easy Parallel Computing in Perl5 for Multi-Core CPUsin Perl5 for Multi-Core CPUs Darko Obradovic My history: 15 years of linear programming in Perl5 April 2007: First dual-core CPU](https://reader033.vdocuments.net/reader033/viewer/2022042911/5f4474b1e720be5e345137fb/html5/thumbnails/36.jpg)
… so use it and enjoythe extra free time ;-)