Multiprocessing & The.Net Parallel Extensions Guy Ben Haim Senior Application Engineer Intel...
-
Upload
marianna-rodrick -
Category
Documents
-
view
227 -
download
0
Transcript of Multiprocessing & The.Net Parallel Extensions Guy Ben Haim Senior Application Engineer Intel...
Multiprocessing & The .Net Parallel Extensions
Guy Ben HaimSenior Application
Engineer
www.intel.com/software/
Asaf ShellySenior Consultant
Pacific [email protected]
www.AsyncOp.com
Session Objectives and Agenda• Multicore• Parallel Software• .Net Parallel Extensions• Q&A• Summary
What is Multicore
Pentium
Pentium
Pentium
Pentium
Pentium Processor
Dual Core
Quad Core
Moore’s Law – GHz to MulticorePerformance
2006
Intel MC Assistance•Threading•Multi-tasking•Training •Tools
Performance ThroughPerformance ThroughMulti-CoreMulti-Core
Performance ThroughPerformance Throughfrequencyfrequency
-+
Intel Processor Advancement
Multiple execution cores ramping across Intel platforms
Why Multi Core?
Power
Performance
2 GHz
100%
CPU that is 20% Faster
Power
Performance
2.4 GHz 2 GHz
174%
100%
113%100%
CPU that is 20% Slower
Power
Performance
1.6 GHz
100%
2 GHz
50%
87%
2.4 GHz
174%
100%
113%
Multi Core: Energy Efficient Performance
Power
Performance
1.6 GHz
100%
2 GHz
100%
174%
2.4 GHz
174%
100%
113%
174%
What does it mean Multi What does it mean Multi Cores?Cores?
PerformancePerformance
Start Thinking Parallel
• Software Today• Instructions – Assembly – Making it workInstructions – Assembly – Making it work
• Thinking like a CPUThinking like a CPU
• Functions – C, Pascal, Basic – Faster CodeFunctions – C, Pascal, Basic – Faster Code• Procedural ThinkingProcedural Thinking
• Objects – C++, Java, C#, Delphi, VB – Manage Objects – C++, Java, C#, Delphi, VB – Manage CodeCode• OOD, OOP – Thinking in objectsOOD, OOP – Thinking in objects
• Tasks - ? – Optimize RuntimeTasks - ? – Optimize Runtime• Thinking Parallel
Situation Today
• Experts, Freelance Specialists, Skilled Groups
• API is not intuitive• Hard to understand execution flow• Problematic Design Patterns• Little awareness of tools• Hidden Problems• Hard to test and debug
Understanding Parallel Computing• Resources• Ownership• Global data / Shared data• Collisions and Race Conditions
• Task Design• Conjunction Points
Task Oriented Design
Modify
Write
Open
Modify
Scan ScanScanScan ScanScan
Simple For
for ( int y = 0; y < bmp.Height; y++ ){ for ( int x = 0; x < bmp.Width; x++ ) { Pixels[ x, y ] = bmp.GetPixel( x, y );
}}
Parallel For
Parallel.For( 0, bmp.Height, y =>{ for ( int x = 0; x < bmp.Width; x++ ) { Pixels[ x, y ] = bmp.GetPixel( x, y );
}});
.Net Parallel Extensions - Performance
Parallel Class
• Parallel.For• Parallel.Do• Parallel.ForEach• Inplace code / Function• Object Type
Parallel Do
Parallel Quick Sort:
void QuicksortParallel( , , ){ int pivot = Partition(arr, left, right); Parallel.Do( () => QuicksortParallel(arr, left, pivot - 1), () => QuicksortParallel(arr, pivot + 1,
right));}
PLINQ
.Net Parallel Extensions – PLINQ
Task Parallel Library
• Parallel For, Do, ForEach• PLINQ• Tasks over Threads• Tasks over Cores• TaskManager• Conjunction Points
.Net Parallel Extensions – Tasks Parallel Library
.Net Parallel Extensions – RayTracer
Tips
• Shared are Globals• Parallel Loops are not loops• Define data as Loop internal• Race Conditions are still here• Don’t use Locks!!• Don’t use MUTEXs
Threading Tools
Intel® Thread Checker•Used to create correct multi-threaded code
Intel® Thread Profiler•Used to analyze performance
Intel Software Solutions Group :
http://www.intel.com/software
Data Race example• Serial program
• What is value of A_SUM:
A_Sum = 4 R
S1: x = 1.0; y = 2.0 ; A1 = 0;S2: A1 = x * y;S3: A_SUM = 2 * A1;
x
y A1
Data Race example (Cont.)• Initiate x = 1.0; y = 2.0 ; A1 = 0;
Thread1A1 = x * y
Thread2A_SUM = 2 * A1
• What is value of x if:• Thread1 runs before Thread2?• Thread2 runs before Thread1?
Execution order is not guaranteed
x
y
A_Sum = 4
A_Sum = 0
A1
Intel® Thread Checker Diagnostics
Source Code Viewer
Performance Profile
0
1
2
3
1 2 3 4 Threads
Sp
eed
up
Possible causes for this scalability profile:1. Insufficient parallel work2. Load imbalance3. Synchronization overhead4. Memory bandwidth limitations
Finding Serial and Parallel Time
Load Imbalance
Multi Threading should be Multi Threading should be managed managed Programming should consider load imbalanceProgramming should consider load imbalance
Load Imbalance• Unequal work loads lead to idle threads and
wasted time
Busy
Idle
Time
Thread 0
Thread 1
Thread 2
Thread 3
Start threads
Join thread
s
Synchronization
Programming should consider Synchronizations issuesProgramming should consider Synchronizations issues
Synchronization
• By definition, synchronization serializes execution• Lock contention means more idle time for threads
Busy Idle In Critical
Thread 0
Thread 1
Thread 2
Thread 3
Time
Real example : Before fix
Serial Parallel
Switching Overhead
Real example: After fix
Serial Parallel
2 X Speed Up
Summary
Parallelize or Perish !
Do we really want Parallel Code?Do users even care?
2005 2007 2008 2010
Change In Mindset
Everything is stopped. Waiting for the Everything is stopped. Waiting for the photographerphotographer
Everyone is working independentlyEveryone is working independently
Change In Mindset
Developers are writing functionsDevelopers are writing functions
Developers are managing tasksDevelopers are managing tasks
Change In Mindset
Doing things the way we always haveDoing things the way we always have
Things are going to be differentThings are going to be different
Keep yourself in the loop
• Public event by Pacific Software
• Register to the User Group
• Asynchronous Operations Web Site has all the online resources that you need... and morehttp://www.AsyncOp.com
• Register to my five day course titled Multiprocessing Traps and Pitfalls
• Use our poster to let people know that you know
Resources
• Download the Microsoft .Net Parallel Extensionshttp://www.microsoft.com/downloads/details.aspx?FamilyID=e848dc1d-5be3-4941-8705-024bc7f180ba&displaylang=en
• Asynchronous Operations Web Site http://www.AsyncOp.com
• Intel’s Multicorehttp://www.intel.com/multi-core
• Pacificsoft Training and Consultinghttp://www.Pacificsoft.com
• Microsoft Forum for Parallel Computinghttp://forums.microsoft.com/MSDN/default.aspx?ForumGroupID=551&SiteID=1
Make a difference
• Let us know what you think
• Feedback for the .Net Parallel Extensions Dev team
• Video blog about parallel computing
• Fill the feedback form …
משוב למלא !כדאיאיך ממלאים?
בעקבות מייל שישלח בסיום כל יום,•, HP במתחם Business Centerב-•בעמדות האינטרנט במלונות הילטון ודן•
Liveמילאת משוב - מגיעה לך חולצת It!
מילאת משוב בשלושת ימי הכנס?
כרטיס טיסה יש לך הזדמנות לזכות ב,BTCמתנת סוכנות לתאילנד
מתנת סמסונג, מכשיר בלאק ג'ק מתנת ניופאן,HTCמכשיר
ועוד...DataSafeמתנת מדיה סנטר
© 2007 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only.MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.