并行程序設計導論課件_第1頁
并行程序設計導論課件_第2頁
并行程序設計導論課件_第3頁
并行程序設計導論課件_第4頁
并行程序設計導論課件_第5頁
已閱讀5頁,還剩38頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

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-memoryTypeofparallelsystemsCopyriTerminologyConcurrentcomputin

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論