《并行程序设计导论》-第一章课件_第1页
《并行程序设计导论》-第一章课件_第2页
《并行程序设计导论》-第一章课件_第3页
《并行程序设计导论》-第一章课件_第4页
《并行程序设计导论》-第一章课件_第5页
已阅读5页,还剩81页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Copyright©2010,ElsevierInc.AllrightsReservedChapter1WhyParallelComputing?AnIntroductiontoParallelProgrammingPeterPachecoCopyright©2010,ElsevierIncCopyright©2010,ElsevierInc.AllrightsReservedRoadmapWhyweneedever-increasingperformance.Whywe’rebuildingparallelsystems.Whyweneedtowriteparallelprograms.Howdowewriteparallelprograms?Whatwe’llbedoing.Concurrent,parallel,distributed!#ChapterSubtitleCopyright©2010,ElsevierIncChangingtimesCopyright©2010,ElsevierInc.AllrightsReservedFrom1986–2002,microprocessorswerespeedinglikearocket,increasinginperformanceanaverageof50%peryear.

Sincethen,it’sdroppedtoabout20%increaseperyear.ChangingtimesCopyright©2010AnintelligentsolutionCopyright©2010,ElsevierInc.AllrightsReservedInsteadofdesigningandbuildingfastermicroprocessors,putmultipleprocessorsonasingleintegratedcircuit.

AnintelligentsolutionCopyrigNowit’suptotheprogrammersAddingmoreprocessorsdoesn’thelpmuchifprogrammersaren’tawareofthem……ordon’tknowhowtousethem.

Serialprogramsdon’tbenefitfromthisapproach(inmostcases).Copyright©2010,ElsevierInc.AllrightsReservedNowit’suptotheprogrammersWhyweneedever-increasingperformanceComputationalpowerisincreasing,butsoareourcomputationproblemsandneeds.Problemsweneverdreamedofhavebeensolvedbecauseofpastincreases,suchasdecodingthehumangenome.Morecomplexproblemsarestillwaitingtobesolved.Copyright©2010,ElsevierInc.AllrightsReservedWhyweneedever-increasingpeClimatemodelingCopyright©2010,ElsevierInc.AllrightsReservedClimatemodelingCopyright©20ProteinfoldingCopyright©2010,ElsevierInc.AllrightsReservedProteinfoldingCopyright©201DrugdiscoveryCopyright©2010,ElsevierInc.AllrightsReservedDrugdiscoveryCopyright©2010EnergyresearchCopyright©2010,ElsevierInc.AllrightsReservedEnergyresearchCopyright©201DataanalysisCopyright©2010,ElsevierInc.AllrightsReservedDataanalysisCopyright©2010,Whywe’rebuildingparallelsystemsUptonow,performanceincreaseshavebeenattributabletoincreasingdensityoftransistors.

Butthereare

inherent

problems.Copyright©2010,ElsevierInc.AllrightsReservedWhywe’rebuildingparallelsyAlittlephysicslessonSmallertransistors=fasterprocessors.Fasterprocessors=increasedpowerconsumption.Increasedpowerconsumption=increasedheat.Increasedheat=unreliableprocessors.Copyright©2010,ElsevierInc.AllrightsReservedAlittlephysicslessonSmallerSolutionMoveawayfromsingle-coresystemstomulticoreprocessors.“core”=centralprocessingunit(CPU)

Copyright©2010,ElsevierInc.AllrightsReservedIntroducingparallelism!!!SolutionMoveawayfromsingleWhyweneedtowriteparallelprogramsRunningmultipleinstancesofaserialprogramoftenisn’tveryuseful.Thinkofrunningmultipleinstancesofyourfavoritegame.Whatyoureallywantisfor

ittorunfaster.Copyright©2010,ElsevierInc.AllrightsReservedWhyweneedtowriteparallelApproachestotheserialproblemRewriteserialprogramssothatthey’reparallel.

Writetranslationprogramsthatautomaticallyconvertserialprogramsintoparallelprograms.Thisisverydifficulttodo.Successhasbeenlimited.Copyright©2010,ElsevierInc.AllrightsReservedApproachestotheserialproblMoreproblemsSomecodingconstructscanberecognizedbyanautomaticprogramgenerator,andconvertedtoaparallelconstruct.However,it’slikelythattheresultwillbeaveryinefficientprogram.Sometimesthebestparallelsolutionistostepbackanddeviseanentirelynewalgorithm.Copyright©2010,ElsevierInc.AllrightsReservedMoreproblemsSomecodingconstExampleComputenvaluesandaddthemtogether.Serialsolution:Copyright©2010,ElsevierInc.AllrightsReservedExampleComputenvaluesandadExample(cont.)Wehavepcores,pmuchsmallerthann.Eachcoreperformsapartialsumofapproximatelyn/pvalues.Copyright©2010,ElsevierInc.AllrightsReservedEachcoreusesit’sownprivatevariablesandexecutesthisblockofcode

independentlyoftheothercores.Example(cont.)WehavepcoresExample(cont.)Aftereachcorecompletesexecutionofthecode,isaprivatevariablemy_sumcontainsthesumofthevaluescomputedbyitscallstoCompute_next_value.Ex.,8cores,n=24,thenthecallstoCompute_next_valuereturn:Copyright©2010,ElsevierInc.AllrightsReserved1,4,3,9,2,8,5,1,1,5,2,7,2,5,0,4,1,8,6,5,1,2,3,9Example(cont.)AftereachcoreExample(cont.)Onceallthecoresaredonecomputingtheirprivatemy_sum,theyformaglobalsumbysendingresultstoadesignated“master”corewhichaddsthefinalresult.Copyright©2010,ElsevierInc.AllrightsReservedExample(cont.)OnceallthecoExample(cont.)Copyright©2010,ElsevierInc.AllrightsReservedExample(cont.)Copyright©201Example(cont.)Copyright©2010,ElsevierInc.AllrightsReservedCore01234567my_sum8197157131214Globalsum8+19+7+15+7+13+12+14=95Core01234567my_sum95197157131214Example(cont.)Copyright©201Copyright©2010,ElsevierInc.AllrightsReservedButwait!There’samuchbetterway

tocomputetheglobalsum.Copyright©2010,ElsevierIncBetterparallelalgorithmDon’tmakethemastercoredoallthework.Shareitamongtheothercores.Pairthecoressothatcore0addsitsresultwithcore1’sresult.Core2addsitsresultwithcore3’sresult,etc.Workwithoddandevennumberedpairsofcores.Copyright©2010,ElsevierInc.AllrightsReservedBetterparallelalgorithmDon’tBetterparallelalgorithm(cont.)Repeattheprocessnowwithonlytheevenlyrankedcores.Core0addsresultfromcore2.Core4addstheresultfromcore6,etc.Nowcoresdivisibleby4repeattheprocess,andsoforth,untilcore0hasthefinalresult.Copyright©2010,ElsevierInc.AllrightsReservedBetterparallelalgorithm(conMultiplecoresformingaglobalsumCopyright©2010,ElsevierInc.AllrightsReservedMultiplecoresformingaglobaAnalysisInthefirstexample,themastercoreperforms7receivesand7additions.Inthesecondexample,themastercoreperforms3receivesand3additions.Theimprovementismorethanafactorof2!Copyright©2010,ElsevierInc.AllrightsReservedAnalysisInthefirstexample,Analysis(cont.)Thedifferenceismoredramaticwithalargernumberofcores.Ifwehave1000cores:Thefirstexamplewouldrequirethemastertoperform999receivesand999additions.Thesecondexamplewouldonlyrequire10receivesand10additions.

That’sanimprovementofalmostafactorof100!Copyright©2010,ElsevierInc.AllrightsReservedAnalysis(cont.)ThedifferenceHowdowewriteparallelprograms?TaskparallelismPartitionvarioustaskscarriedoutsolvingtheproblemamongthecores.

DataparallelismPartitionthedatausedinsolvingtheproblemamongthecores.Eachcorecarriesoutsimilaroperationsonit’spartofthedata.Copyright©2010,ElsevierInc.AllrightsReservedHowdowewriteparallelprogrProfessorPCopyright©2010,ElsevierInc.AllrightsReserved15questions300examsProfessorPCopyright©2010,EProfessorP’sgradingassistantsCopyright©2010,ElsevierInc.AllrightsReservedTA#1TA#2TA#3ProfessorP’sgradingassistanDivisionofwork–

dataparallelismCopyright©2010,ElsevierInc.AllrightsReservedTA#1TA#2TA#3100exams100exams100examsDivisionofwork–

dataparalDivisionofwork–

taskparallelismCopyright©2010,ElsevierInc.AllrightsReservedTA#1TA#2TA#3Questions1-5Questions6-10Questions11-15Divisionofwork–

taskparalDivisionofwork–

dataparallelismCopyright©2010,ElsevierInc.AllrightsReservedDivisionofwork–

dataparalDivisionofwork–

taskparallelismCopyright©2010,ElsevierInc.AllrightsReservedTasksReceivingAdditionDivisionofwork–

taskparalCoordinationCoresusuallyneedtocoordinatetheirwork.Communication–oneormorecoressendtheircurrentpartialsumstoanothercore.Loadbalancing–sharetheworkevenlyamongthecoressothatoneisnotheavilyloaded.Synchronization–becauseeachcoreworksatitsownpace,makesurecoresdonotgettoofaraheadoftherest.Copyright©2010,ElsevierInc.AllrightsReservedCoordinationCoresusuallyneedWhatwe’llbedoingLearningtowriteprogramsthatareexplicitlyparallel.UsingtheClanguage.UsingthreedifferentextensionstoC.Message-PassingInterface(MPI)PosixThreads(Pthreads)OpenMPCopyright©2010,ElsevierInc.AllrightsReservedWhatwe’llbedoingLearningtoTypeofparallelsystemsShared-memoryThecorescanshareaccesstothecomputer’smemory.Coordinatethecoresbyhavingthemexamineandupdatesharedmemorylocations.Distributed-memoryEachcorehasitsown,privatememory.Thecoresmustcommunicateexplicitlybysendingmessagesacrossanetwork.Copyright©2010,ElsevierInc.AllrightsReservedTypeofparallelsystemsSharedTypeofparallelsystemsCopyright©2010,ElsevierInc.AllrightsReservedShared-memoryDistributed-memoryTypeofparallelsystemsCopyriTerminologyConcurrentcomputing–aprogramisoneinwhichmultipletaskscanbeinprogressatanyinstant.Parallelcomputing–aprogramisoneinwhichmultipletaskscooperatecloselytosolveaproblemDistributedcomputing–aprogrammayneedtocooperatewithotherprogramstosolveaproblem.Copyright©2010,ElsevierInc.AllrightsReservedTerminologyConcurrentcomputiConcludingRemarks(1)Thelawsofphysicshavebroughtustothedoorstepofmulticoretechnology.Serialprogramstypicallydon’tbenefitfrommultiplecores.Automaticparallelprogramgenerationfromserialprogramcodeisn’tthemostefficientapproachtogethighperformancefrommulticorecomputers.Copyright©2010,ElsevierInc.AllrightsReservedConcludingRemarks(1)ThelawsConcludingRemarks(2)Learningtowriteparallelprogramsinvolveslearninghowtocoordinatethecores.Parallelprogramsareusuallyverycomplexandtherefore,requiresoundprogramtechniquesanddevelopment.Copyright©2010,ElsevierInc.AllrightsReservedConcludingRemarks(2)LearningCopyright©2010,ElsevierInc.AllrightsReservedChapter1WhyParallelComputing?AnIntroductiontoParallelProgrammingPeterPachecoCopyright©2010,ElsevierIncCopyright©2010,ElsevierInc.AllrightsReservedRoadmapWhyweneedever-increasingperformance.Whywe’rebuildingparallelsystems.Whyweneedtowriteparallelprograms.Howdowewriteparallelprograms?Whatwe’llbedoing.Concurrent,parallel,distributed!#ChapterSubtitleCopyright©2010,ElsevierIncChangingtimesCopyright©2010,ElsevierInc.AllrightsReservedFrom1986–2002,microprocessorswerespeedinglikearocket,increasinginperformanceanaverageof50%peryear.

Sincethen,it’sdroppedtoabout20%increaseperyear.ChangingtimesCopyright©2010AnintelligentsolutionCopyright©2010,ElsevierInc.AllrightsReservedInsteadofdesigningandbuildingfastermicroprocessors,putmultipleprocessorsonasingleintegratedcircuit.

AnintelligentsolutionCopyrigNowit’suptotheprogrammersAddingmoreprocessorsdoesn’thelpmuchifprogrammersaren’tawareofthem……ordon’tknowhowtousethem.

Serialprogramsdon’tbenefitfromthisapproach(inmostcases).Copyright©2010,ElsevierInc.AllrightsReservedNowit’suptotheprogrammersWhyweneedever-increasingperformanceComputationalpowerisincreasing,butsoareourcomputationproblemsandneeds.Problemsweneverdreamedofhavebeensolvedbecauseofpastincreases,suchasdecodingthehumangenome.Morecomplexproblemsarestillwaitingtobesolved.Copyright©2010,ElsevierInc.AllrightsReservedWhyweneedever-increasingpeClimatemodelingCopyright©2010,ElsevierInc.AllrightsReservedClimatemodelingCopyright©20ProteinfoldingCopyright©2010,ElsevierInc.AllrightsReservedProteinfoldingCopyright©201DrugdiscoveryCopyright©2010,ElsevierInc.AllrightsReservedDrugdiscoveryCopyright©2010EnergyresearchCopyright©2010,ElsevierInc.AllrightsReservedEnergyresearchCopyright©201DataanalysisCopyright©2010,ElsevierInc.AllrightsReservedDataanalysisCopyright©2010,Whywe’rebuildingparallelsystemsUptonow,performanceincreaseshavebeenattributabletoincreasingdensityoftransistors.

Butthereare

inherent

problems.Copyright©2010,ElsevierInc.AllrightsReservedWhywe’rebuildingparallelsyAlittlephysicslessonSmallertransistors=fasterprocessors.Fasterprocessors=increasedpowerconsumption.Increasedpowerconsumption=increasedheat.Increasedheat=unreliableprocessors.Copyright©2010,ElsevierInc.AllrightsReservedAlittlephysicslessonSmallerSolutionMoveawayfromsingle-coresystemstomulticoreprocessors.“core”=centralprocessingunit(CPU)

Copyright©2010,ElsevierInc.AllrightsReservedIntroducingparallelism!!!SolutionMoveawayfromsingleWhyweneedtowriteparallelprogramsRunningmultipleinstancesofaserialprogramoftenisn’tveryuseful.Thinkofrunningmultipleinstancesofyourfavoritegame.Whatyoureallywantisfor

ittorunfaster.Copyright©2010,ElsevierInc.AllrightsReservedWhyweneedtowriteparallelApproachestotheserialproblemRewriteserialprogramssothatthey’reparallel.

Writetranslationprogramsthatautomaticallyconvertserialprogramsintoparallelprograms.Thisisverydifficulttodo.Successhasbeenlimited.Copyright©2010,ElsevierInc.AllrightsReservedApproachestotheserialproblMoreproblemsSomecodingconstructscanberecognizedbyanautomaticprogramgenerator,andconvertedtoaparallelconstruct.However,it’slikelythattheresultwillbeaveryinefficientprogram.Sometimesthebestparallelsolutionistostepbackanddeviseanentirelynewalgorithm.Copyright©2010,ElsevierInc.AllrightsReservedMoreproblemsSomecodingconstExampleComputenvaluesandaddthemtogether.Serialsolution:Copyright©2010,ElsevierInc.AllrightsReservedExampleComputenvaluesandadExample(cont.)Wehavepcores,pmuchsmallerthann.Eachcoreperformsapartialsumofapproximatelyn/pvalues.Copyright©2010,ElsevierInc.AllrightsReservedEachcoreusesit’sownprivatevariablesandexecutesthisblockofcode

independentlyoftheothercores.Example(cont.)WehavepcoresExample(cont.)Aftereachcorecompletesexecutionofthecode,isaprivatevariablemy_sumcontainsthesumofthevaluescomputedbyitscallstoCompute_next_value.Ex.,8cores,n=24,thenthecallstoCompute_next_valuereturn:Copyright©2010,ElsevierInc.AllrightsReserved1,4,3,9,2,8,5,1,1,5,2,7,2,5,0,4,1,8,6,5,1,2,3,9Example(cont.)AftereachcoreExample(cont.)Onceallthecoresaredonecomputingtheirprivatemy_sum,theyformaglobalsumbysendingresultstoadesignated“master”corewhichaddsthefinalresult.Copyright©2010,ElsevierInc.AllrightsReservedExample(cont.)OnceallthecoExample(cont.)Copyright©2010,ElsevierInc.AllrightsReservedExample(cont.)Copyright©201Example(cont.)Copyright©2010,ElsevierInc.AllrightsReservedCore01234567my_sum8197157131214Globalsum8+19+7+15+7+13+12+14=95Core01234567my_sum95197157131214Example(cont.)Copyright©201Copyright©2010,ElsevierInc.AllrightsReservedButwait!There’samuchbetterway

tocomputetheglobalsum.Copyright©2010,ElsevierIncBetterparallelalgorithmDon’tmakethemastercoredoallthework.Shareitamongtheothercores.Pairthecoressothatcore0addsitsresultwithcore1’sresult.Core2addsitsresultwithcore3’sresult,etc.Workwithoddandevennumberedpairsofcores.Copyright©2010,ElsevierInc.AllrightsReservedBetterparallelalgorithmDon’tBetterparallelalgorithm(cont.)Repeattheprocessnowwithonlytheevenlyrankedcores.Core0addsresultfromcore2.Core4addstheresultfromcore6,etc.Nowcoresdivisibleby4repeattheprocess,andsoforth,untilcore0hasthefinalresult.Copyright©2010,ElsevierInc.AllrightsReservedBetterparallelalgorithm(conMultiplecoresformingaglobalsumCopyright©2010,ElsevierInc.AllrightsReservedMultiplecoresformingaglobaAnalysisInthefirstexample,themastercoreperforms7receivesand7additions.Inthesecondexample,themastercoreperforms3receivesand3additions.Theimprovementismorethanafactorof2!Copyright©2010,ElsevierInc.AllrightsReservedAnalysisInthefirstexample,Analysis(cont.)Thedifferenceismoredramaticwithalargernumberofcores.Ifwehave1000cores:Thefirstexamplewouldrequirethemastertoperform999receivesand999additions.Thesecondexamplewouldonlyrequire10receivesand10additions.

That’sanimprovementofalmostafactorof100!Copyright©2010,ElsevierInc.AllrightsReservedAnalysis(cont.)ThedifferenceHowdowewriteparallelprograms?TaskparallelismPartitionvarioustaskscarriedoutsolvingtheproblemamongthecores.

DataparallelismPartitionthedatausedinsolvingtheproblemamongthecores.Eachcorecarriesoutsimilaroperationsonit’spartofthedata.Copyright©2010,ElsevierInc.AllrightsReservedHowdowewriteparallelprogrProfessorPCopyright©2010,ElsevierInc.AllrightsReserved15questions300examsProfessorPCopyright©2010,EProfessorP’sgradingassistantsCopyright©2010,ElsevierInc.AllrightsReservedTA#1TA#2TA#3ProfessorP’sgradingassistanDivisionofwork–

dataparallelismCopyright©2010,ElsevierInc.AllrightsReservedTA#1TA#2TA#3100exams100exams100examsDivisionofwork–

dataparalDivisionofwork–

taskparallelismCopyright©2010,ElsevierInc.AllrightsReservedTA#1TA#2TA#3Questions1-5Questions6-10Questions11-15Divisionofwork–

taskparalDivisionofwork–

dataparallelismCopyright©2010,ElsevierInc.AllrightsReservedDivisionofwork–

dataparalDivisionofwork–

taskparallelismCopyright©2010,ElsevierInc.AllrightsReservedTasksReceivingAdditionDivisionofwork–

taskparalCoordinationCoresusuallyneedtocoordinatetheirwork.Communication–oneormorecoressendtheircurrentpartialsumstoanothercore.Loadbalancing–sharetheworkevenlyamongthecoressothatoneisnotheavily

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论