parallel programming 2 -...

38
Stanford, Nov 07 Copyright © 2007, Intel Corporation Parallel Programming 2.0 Parallel Programming 2.0 Wei Li Wei Li Senior Principal Engineer Senior Principal Engineer Director, Emerging Products Lab Director, Emerging Products Lab Santa Clara, California Santa Clara, California USA USA

Upload: others

Post on 14-Mar-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

Stanford, Nov 07Copyright © 2007, Intel Corporation

Parallel Programming 2.0Parallel Programming 2.0

Wei LiWei LiSenior Principal EngineerSenior Principal Engineer

Director, Emerging Products LabDirector, Emerging Products Lab

Santa Clara, CaliforniaSanta Clara, CaliforniaUSAUSA

Page 2: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

2Copyright © 2008, Intel Corporation

QuizQuiz

How old is Intel? How old is Intel?

–– 10 years10 years

–– 20 years20 years

–– 30 years30 years

–– 40 years40 years

Please look for the Celebration Ball at the Intel booth to win Please look for the Celebration Ball at the Intel booth to win

a prize!a prize!

Page 3: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

3Copyright © 2008, Intel Corporation

AgendaAgenda

Why Parallel Programming 2.0? Why Parallel Programming 2.0?

A Case StudyA Case Study

Intel Software ProductsIntel Software Products

Page 4: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

4Copyright © 2008, Intel Corporation

Historical Driving ForceHistorical Driving Force

1

10

100

1000

10000

100000

1970 1980 1990 2000 2010 20201

10

100

1000

10000

100000

1970 1980 1990 2000 2010 2020

Increased PerformanceIncreased Performancevia Increased Frequencyvia Increased Frequency

FrequencyFrequency(MHz)(MHz)

2005200565nm65nm

1B+ Transistors1B+ Transistors

1946194620 Numbers20 Numbers

in Main Memoryin Main Memory

19711971I4004 ProcessorI4004 Processor2300 Transistors2300 Transistors

2007200745nm45nm

2009200932nm32nm

Page 5: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

5Copyright © 2008, Intel Corporation

The ChallengeThe Challenge

Unsustainable Power GrowthUnsustainable Power Growth

Power LimitationsPower Limitations

0

5

10

15

20

25

30

0 2 4 6 8Scalar Performance

Pow

er power = perf ^ 1.74

Pentium M

i486 Pentium

Pentium Pro

Pentium 4 (Wmt)

Pentium 4 (Psc)

Power growing faster than performance

Power and performance normalized to i486

Page 6: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

6Copyright © 2008, Intel Corporation

MULTIMULTI--CORE MOTIVATIONCORE MOTIVATION

OverOver--clockedclocked(+20%)(+20%)

1.00x1.00x

Relative singleRelative single--core frequency and core frequency and VccVcc

1.73x1.73x

1.13x1.13x

DesignDesignFrequencyFrequency

PowerPower

PerformancePerformance

DualDual--corecore((--20%)20%)

1.02x1.02x

1.73x1.73x

DualDual--CoreCore

0.51x0.51x

0.87x0.87x

UnderUnder--clockedclocked((--20%)20%)

Page 7: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

7Copyright © 2008, Intel Corporation

Approaching 100% of processorsare parallel processors

Page 8: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

8Copyright © 2008, Intel Corporation

MultiMulti--core is performance delivered core is performance delivered in a new way.in a new way.

Our job is to make sure the Our job is to make sure the software industry makes the most software industry makes the most of that performance.of that performance.

Page 9: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

9Copyright © 2008, Intel Corporation

The Burden on SoftwareThe Burden on SoftwarePe

rfor

man

ce

GHz Era

Time

Application Performance

Platform Potential

Page 10: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

10Copyright © 2008, Intel Corporation

Perf

orm

ance

GHz Era

Time

Multi-core Era

Application Performance

Platform PotentialGrowing Gap

The Burden on SoftwareThe Burden on Software

Page 11: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

11Copyright © 2008, Intel Corporation

VirtualContainerVMM:

Parallelism at many levelsParallelism at many levels

OS OS OS

OperatingSystem:

App App App

Application: Thread Thread Thread

Thread: CodeFragment

CodeSegment

CodeFragment

Page 12: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

12Copyright © 2008, Intel Corporation

Parallel Programming 1.0Parallel Programming 1.0HPC applications for peak performanceHPC applications for peak performanceManual, lots of hand tuning by expertsManual, lots of hand tuning by experts

–– Difficult, often not possible without specific toolsDifficult, often not possible without specific tools–– Does not scale, need to reDoes not scale, need to re--do for each appdo for each app

Goals for Parallel Programming 2.0Goals for Parallel Programming 2.0Mainstream applications, not peak performanceMainstream applications, not peak performanceHigh productivity programmingHigh productivity programming

–– Raise the level of programming abstraction Raise the level of programming abstraction –– easy to learn easy to learn and parallelizeand parallelize

–– Make tools easy to use Make tools easy to use –– Ph.D. not requiredPh.D. not required–– Bring parallelism to mainstream programming Bring parallelism to mainstream programming ––

undergraduateundergraduate--levellevel

Page 13: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

13Copyright © 2008, Intel Corporation

AgendaAgenda

Why Parallel Programming 2.0?Why Parallel Programming 2.0?

A Case StudyA Case Study

Intel Software ProductsIntel Software Products

Page 14: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

14Copyright © 2008, Intel Corporation

Example: Threading the Example: Threading the CompilerCompiler

Compiler {

Read options

For Each lineparseupdate Tables

End

For Each FunctionOptimize_func()

End}

Global_opts {

For Each BlockFor Each InstIf( )End

End

}Generate_obj {Generate_memFor Each BlockFor Each Instencodewrite

EndEnd

}

Optimize_func {Count loops

Global_optsTranslateLocal_optsAllocate_regsGenerate_obj

}

main.c control.c opt_gen.c

Page 15: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

15Copyright © 2008, Intel Corporation

ParallelizationParallelization

Compiler {

Read options

For Each lineparseupdate Tables

End//parallelFor Each FunctionOptimize_func()

End}

Global_opts {

For Each BlockFor Each InstIf( )End

End

}Generate_obj {Generate_memFor Each BlockFor Each Instencodewrite

EndEnd

}

Optimize_func {Count loops

Global_optsTranslateLocal_optsAllocate_regsGenerate_obj

}

Page 16: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

16Copyright © 2008, Intel Corporation

Global VariablesGlobal Variables

Compiler {threshold=falseRead options

For Each lineparseupdate Tables

End//parallelFor Each FunctionOptimize_func()

End}

Global_opts {if !threshold{For Each BlockFor Each InstIf( )End

End}

}Generate_obj {Generate_memFor Each BlockFor Each Instencodewrite

EndEnd

}

Optimize_func {Count loopsif(loops>100)threshold=TrueGlobal_optsTranslateLocal_optsAllocate_regsGenerate_obj

}

Page 17: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

17Copyright © 2008, Intel Corporation

CharacteristicsCharacteristics

Parallelizable code spread across ~100 Parallelizable code spread across ~100 modules and ~100 thousand lines of code modules and ~100 thousand lines of code Global variablesGlobal variables––3787 global symbols!! 3787 global symbols!! ––Large number of global variables written in loop Large number of global variables written in loop

Serial portionSerial portion––asmasm and object generationand object generation

Page 18: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

18Copyright © 2008, Intel Corporation

Dealing with Dealing with GlobalsGlobals

Identify Identify globalsglobals without cross iteration without cross iteration dependencedependence––Only read in loopOnly read in loop––PrivatizablePrivatizable

Identify Identify globalsglobals with cross iteration with cross iteration dependencedependence––Reduction for counters, timers, statisticsReduction for counters, timers, statistics

GlobalsGlobals requiring synchronizationrequiring synchronization––I/OI/O

Page 19: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

19Copyright © 2008, Intel Corporation

AgendaAgenda

Why Parallel Programming 2.0?Why Parallel Programming 2.0?

A Case StudyA Case Study

Intel Software ProductsIntel Software Products

Page 20: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

20Copyright © 2008, Intel Corporation

Software @ IntelSoftware @ Intel

Ensure Intel Architecture is the platform Ensure Intel Architecture is the platform of choice by:of choice by:

–– Software ecosystem coSoftware ecosystem co--development & development & enabling enabling

–– Leadership developer productsLeadership developer products–– Development of Intel platform software & Development of Intel platform software &

servicesservices

Page 21: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

21Copyright © 2008, Intel Corporation

Intel SW sitesIntel SW sites

Israel / Western Europe

Koln, GermanyMunich, GermanyUlm, GermanyHaifa, IsraelStockholm, SwedenSwindon, UK

Winnersh, UK

WesternUnited States

ArizonaFolsom, CASanta Clara, CA Southern CAColoradoNew MexicoOregonUtahWashington

Eastern / Midwestern United States

IllinoisMassachusettsNew HampshireTexasVirginia

South AmericaArgentina

MoscowNizhniy NovgorodNovosibirskSarovSt. Petersburg

BeijingHong KongShanghaiShenzhenXi’An

Asia

Sydney, AustraliaBangalore, IndiaMumbai, IndiaJapan

Our global presencehelps us keep a pulse ondeveloping markets andemerging technologies

Page 22: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

22Copyright © 2008, Intel Corporation

Development Across EnvironmentsDevelopment Across Environments

Mobile Tools

Digital HomeTools

Cluster Tools

Threading Tools

Performance Libraries

VTune™Analyzers

Compilers

Page 23: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

23Copyright © 2008, Intel Corporation

Parallelization MethodologyParallelization Methodology

Design

Code

Debug

Tune

Page 24: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

24Copyright © 2008, Intel Corporation

Introduce Threads

• Compilers• Built-in

optimization• OpenMP

• Libraries• Media• Math Processing• Threading• XML

Confidence/Correctness

• Intel® Thread Checker• Find deadlocks

and race conditions

Architectural Analysis

• VTune™ Analyzer• Find the code

that can benefit from threading

• Find hotspots that limit performance

Optimize / Tune

• VTune Analyzer• Tune for

performance and scalability

• Intel® Thread Profiler• Visualize

efficiency of threaded code

Development with Intel® Tools

Page 25: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

25Copyright © 2008, Intel Corporation

Unstructured Windows Threads: Unstructured Windows Threads: too low leveltoo low level

#include <#include <iostreamiostream>>#include <#include <windows.hwindows.h>>using namespace std;using namespace std;const const intint numThreadsnumThreads = 4;= 4;

DWORD WINAPI DWORD WINAPI HelloFuncHelloFunc (LPVOID (LPVOID argarg)){ {

coutcout << << ““Hello ThreadHello Thread\\nn””; ; return 0;return 0;

}}main ()main (){{

HANDLE HANDLE hThread[numThreadshThread[numThreads];];

for (for (intint i = 0; i < i = 0; i < numThreadsnumThreads; i++); i++)hThread[ihThread[i] = ] =

CreateThreadCreateThread (NULL, 0, (NULL, 0, HelloFuncHelloFunc, NULL, 0, NULL );, NULL, 0, NULL );

WaitForMultipleObjectsWaitForMultipleObjects ((numThreadsnumThreads, , hThreadhThread, TRUE, INFINITE);, TRUE, INFINITE);}}

Page 26: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

26Copyright © 2008, Intel Corporation

Example: OpenMP Matrix Multiply

Each row can be computed independently

B

A C

#pragma omp parallel for shared(C) private(i,j)

for (i = 0; i < M; i++)

for (j = 0; j < N; j++)

C[i][j] = 0.0;

#pragma omp parallel for shared(A,B,C) private(i,j,k)

for (i = 0; i < M; i++)

for (k = 0; k < L; k++)

for (j = 0; j < N; j++)

C[i][j] +=

A[i][k] * B[k][j];

Page 27: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

27Copyright © 2008, Intel Corporation

IntelIntel®® Threading Threading Building BlocksBuilding BlocksExtend C++ for parallelismExtend C++ for parallelism

FeaturesFeatures–– A C++ runtime library that uses A C++ runtime library that uses

familiar task patterns, not threadsfamiliar task patterns, not threads–– A high level abstraction requiring less A high level abstraction requiring less

code for threading without sacrificing code for threading without sacrificing performanceperformance

–– Appropriately scales to the number of Appropriately scales to the number of cores availablecores available

–– The thread library API is portable The thread library API is portable across Linux, Windows, or Mac OS across Linux, Windows, or Mac OS platformsplatforms

–– Works with all C++ compilers (i.e. Works with all C++ compilers (i.e. Microsoft, GNU and Intel)Microsoft, GNU and Intel)

WhatWhat’’s News New–– Open source version available at Open source version available at

www.threadingbuildingblocks.orgwww.threadingbuildingblocks.org–– Auto_partitionerAuto_partitioner for better parallel for better parallel

algorithmsalgorithms–– Microsoft Vista* supportMicrosoft Vista* support–– Full, native 64 bit support for Mac OS Full, native 64 bit support for Mac OS

X*X*

Page 28: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

28Copyright © 2008, Intel Corporation

coming soon… Intel® Parallel StudioHelps programmers throughout the

development cycle

Design Code Debug Tune

Software products that help solve the greatest parallelism challenges developers face

Page 29: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

29Copyright © 2008, Intel Corporation

Intel® Parallel AdvisorAdvisor is a new category of development productAdvisor helps understand where to add parallelism to existing source code. – How to implement threads and provide suggestions areas– Spotlights where parallelism can be added– Helps make better design decisions

– Shows consequences of decisions – identifies conflicts– Suggest ways to resolve conflicts

Microsoft* Visual Studio* IntegrationBeta mid-2009, product late 2009

Insight into where applications benefit most from parallelism

Page 30: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

30Copyright © 2008, Intel Corporation

Intel® Parallel Composer

Simplifies threading for improved developer productivity– “Think Parallel” and code it without low-level thread management

Enables Microsoft* Visual Studio* developers to add parallelism to applications

Beta Q4 2008, product mid-2009

Speeds software development incorporating parallelism with aC/C++ compiler and comprehensive threaded libraries

• Intel® Threading Building Blocks• Support for lambda functions• Pre-threaded domain-specific libraries• Parallel debugging functionality• Data parallel arrays• Simple concurrency functions• OpenMP* 3.0• Auto-vectorization, auto-parallelization• Innovative “Parallel Lint” helps detect

parallel errors at compile time• Microsoft* Visual Studio* Integration

• Spawn/par• Parallel debug plug-in.• Intel® Integrated

Performance Primitives (Intel® IPP)

• Interoperate with all other Intel tools

• Parallel valarray• Interoperate

with Microsofttools

Page 31: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

31Copyright © 2008, Intel Corporation

Intel® Parallel Inspector

Inspector sets a “must use” standard for shipping stable and reliable threaded applications – a proactive “bug finder.”Does not require that application uses a single particular model of parallelism to get safety.Unlike traditional debuggers, Inspector detects hard-to-find threading errors in multi-threaded C/C++ Windows applications. – Root-cause analysis for crash-causing defects such as data races and deadlocks– Automatically monitoring the runtime behavior of the code to ensure application

reliability– Critical for nondeterministic (the execution sequence can

change from run to run) errors that are difficult toreproduce

– Based on Intel® Thread Checker technology, plus more!

Microsoft* Visual Studio* IntegrationBeta by January 2009, product mid-2009

Proactive “bug finder”; flexible tool to add reliabilityregardless of parallelism models used

Page 32: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

32Copyright © 2008, Intel Corporation

Intel® Parallel Amplifier

Amplifier makes it simple to quickly find multi-core performance bottlenecks, for everyone – not just “experts”– Provides quick access to scaling information for faster and improved

decision-making– No need to know the processor architecture or assembly code– Takes away the guesswork by accurately measuring programs

performance behavior– Designed with significant user input – Intel application engineers,

customers, and Whatif.intel.com community (PTU)– Makes Intel® Thread Profiler and

Intel® VTune Performance Analyzer technologymuch more accessible

Microsoft* Visual Studio* IntegrationBeta by January 2009, product mid-2009

Find unexpected serialization which limits scaling,to optimize performance to use all processor cores.

Page 33: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

33Copyright © 2008, Intel Corporation33

Enabling the Next GenerationEnabling the Next Generation

Working with professors for teachingWorking with professors for teaching

Needed in all undergraduateprogramming courses.

2006: 40 universities2007: 407 universities2008: 822 universities and growing

Over 65K students used material from this programalready in 2008.

intel.com/software/college

We asked:How can we share our

expertise (training) for

professionals, and help

educators?

Page 34: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

34Copyright © 2008, Intel Corporation

W h a t I f . i n t e l . c o mAccess innovations… in the formative stages

Explore future processor instructions sets• Intel® Software Development Emulator added AUGUST ‘08

Explore how to CODE for parallelism• Intel® Concurrent Collections for C/C++ added mid-2008• Intel® C++ Parallelism Exploration Compiler, Prototype Edition

• Intel® Cluster OpenMP* for Intel® Compilers• Intel® C++ STM Compiler, Prototype Edition 2.0

New analysis tools• Intel® Platform Modeling with Machine Learning RECENT +• Intel® Performance Tuning Utility 3.1 MOST POPULAR• Intel® Integrated Debugger for Java*/JNI Environments

New libraries• Intel® Adaptive Spike-Based Solver RECENT ADD• Intel® Summary Statistics Library• Intel® Decimal Floating-Point Math Library RECENT ADD• Intel® Location Technologies Software Development Kit 1.0

New web technologies• Intel® Mash Maker: Mashups for the Masses GRADUATE

Page 35: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

35Copyright © 2008, Intel Corporation

STM Compiler on STM Compiler on whatif.intel.comwhatif.intel.com

Page 36: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

36Copyright © 2008, Intel Corporation

Alice transfer $20 from A to Bbegin_xactionA = A – 20B = B + 20end_xaction

Alice transfer $20 from A to BLocks ALocks BA = A – 20B = B + 20Unlocks AUnlocks B

Transactional MemoryTransactional Memory

A $100

B $200

C $200

LockLock

LockLock

LockLock

LockLock

LockLock

LockLock

A $100

B $200

C $200

Programmer manually ensures no race

System automatically ensures no race

Page 37: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

37Copyright © 2008, Intel Corporation

A C++ Example using the prototypeA C++ Example using the prototype

int s = 0;

class B

{ public:

__declspec(tm_callable)

virtual void inc(){

s = s + 1;}

};

class C : public B

{ public:

__declspec(tm_callable)

void inc(){

s = s + 1;}

};

int main(){ B *x, *y;

#pragma omp parallel sections num_threads(2)

{__tm_atomic {

x = new B();x->inc();

}

#pragma omp section__tm_atomic {

y = new C();y->inc();

}}

}

Page 38: Parallel Programming 2 - 2008.secrus.org2008.secrus.org/en/etc/secr2008_wei_li_parallel_programming__2.pdf · – Bring parallelism to mainstream programming ... Read options For

38Copyright © 2008, Intel Corporation

SummarySummaryProgramming is not Programming is not ““EASYEASY””–– Neither is parallel programmingNeither is parallel programming

There isnThere isn’’t one magic solution for Parallel t one magic solution for Parallel Programming 2.0Programming 2.0–– Methodology: design, code, debug, tuneMethodology: design, code, debug, tune

The right The right tools such as the Intel products will help tools such as the Intel products will help make parallel programming EASIER.make parallel programming EASIER.