文档详情

《并行程序设计导论》-第五章.pptx

发布:2025-01-11约1.32万字共92页下载文档
文本预览下载声明

Chapter5SharedMemoryProgrammingwithOpenMPAnIntroductiontoParallelProgrammingPeterPacheco

RoadmapWritingprogramsthatuseOpenMP.UsingOpenMPtoparallelizemanyserialforloopswithonlysmallchangestothesourcecode.Taskparallelism.Explicitthreadsynchronization.Standardproblemsinshared-memoryprogramming.#ChapterSubtitle

OpenMPAnAPIforshared-memoryparallelprogramming.MP=multiprocessingDesignedforsystemsinwhicheachthreadorprocesscanpotentiallyhaveaccesstoallavailablememory.SystemisviewedasacollectionofcoresorCPU’s,allofwhichhaveaccesstomainmemory.

Asharedmemorysystem

PragmasSpecialpreprocessorinstructions.Typicallyaddedtoasystemtoallowbehaviorsthataren’tpartofthebasicCspecification.Compilersthatdon’tsupportthepragmasignorethem.#pragma

gcc?g?Wall?fopenmp?oomp_helloomp_hello.c./omp_hello4compilingrunningwith4threadsHellofromthread0of4Hellofromthread1of4Hellofromthread2of4Hellofromthread3of4Hellofromthread1of4Hellofromthread2of4Hellofromthread0of4Hellofromthread3of4Hellofromthread3of4Hellofromthread1of4Hellofromthread2of4Hellofromthread0of4possible

outcomes

OpenMppragmas#pragmaompparallel

Mostbasicparalleldirective.Thenumberofthreadsthatrun

thefollowingstructuredblockofcode

isdeterminedbytherun-timesystem.

Aprocessforkingandjoiningtwothreads

clauseTextthatmodifiesadirective.Thenum_threadsclausecanbeaddedtoaparalleldirective.Itallowstheprogrammertospecifythenumberofthreadsthatshouldexecutethefollowingblock.#pragmaompparallelnum_threads(thread_count)

Ofnote…Theremaybesystem-definedlimitationsonthenumberofthreadsthataprogramcanstart.TheOpenMPstandarddoesn’tguaranteethatthiswillactuallystartthread_countthreads.Mostcurrentsystemscanstarthundredsoreventhousandsofthreads.Unlesswe’retryingtostartalo

显示全部
相似文档