Document Type:Tutorial NI Supported:Yes Publish Date:Nov1,2007
Why Dataflow Programming Languages are Ideal for Programming Parallel Hardware
Overview This document is part of the
Multicore Programming Fundamentals Whitepaper Series
MulticoreProgrammingFundamentalsWhitepaperSeries
Viewthiswhitepapertolearnaboutdataflowprogramminglanguagesandwhytheyareanidealchoiceforprogrammingparallelhardware. Table of Contents 1.DataflowProgrammingOverview 2.ExampleofCreatingaParallelTaskinLabVIEW 3.MoreResourcesonMulticoreProgramming Dataflow Programming Overview DataflowprogrammingmodelscontrasttothecontrolflowmodelimplementedinlanguagessuchasC. Becauseofthetop-downsequentialprogrammingapproach,applicationswritteninChaveinherentlimitationswhenmappingtoparallelhardware.Incontrast,withadataflowmodel,nodesona blockdiagramareconnectedtooneanothertoexpressthelogicalexecutionflow,andtheycanbeusedtoeasilyexpressparallelism.Whenablockdiagramnodereceivesallrequiredinputs,it producesoutputdataandpassesthatdatatothenextnodeinthedataflowpath.Themovementofdatathroughthenodesdeterminestheexecutionorderofthefunctionsontheblockdiagram. Example of Creating a Parallel Task in LabVIEW TaskparallelismisoftencreatedinherentlywhenwritingaprograminLabVIEW.ThefollowingexampletakesadvantageoftheLabVIEWmultithreadedexecutionsystem.Thisexamplehastwo paralleltasks,onetaskisanevent-drivenUItask,andtheotherperformsanacquisitionfromaperipheraldevice.LabVIEWrecognizesthatitcanexecutethetwoloopsindependently,andina multiprocessingorhyperthreadedenvironment,oftensimultaneously.
Figure1-ImplicitParallelisminLabVIEW Noticethatthesetheaboveexampledoesnotincludecodeforexplicitthreadmanagement.TheLabVIEWdataflowprogrammingparadigmallowstheLabVIEWexecutionsystemtorunthetwo loopsindifferentthreads.Inmanytext-basedprogramminglanguages,youmustexplicitlycreateandhandlethreads. LabVIEWalsooffersspecialstructuresthatwillmapcodetoparallelhardwareresourcesforexplicitthreading.Forexample,onesuchstructureistheTimedLoop.Whencodethatiscontainedina TimedLoopisrunonadual-coreormulticoresystem,auniquethreadwillbecreated.Figure1belowdemonstrateshowtwoTimedLoopswillcreatetwouniquethreadswhichcanbebalanced acrosstwoseparatecoresofamulticoresystem.
Figure2-ExplicitParallelisminLabVIEW InthecaseofFPGAs,theconceptofthreadingdoesnotexist,soloopstructuresinsteadreservereal-estateonthefabricoftheFPGAandexecuteasauniqueprocessorcores. Insummary,sincedataflowprogramminglanguagesareinherentlyparallelinnature,developerscancreateapplicationsthatareimplicitlyparallel.Thischaracteristicofaprogramminglanguage signifiesthatdevelopersdon'tneedtobeexpertsinthelow-levelintricaciesofparallelhardwaresuchasmulticoreprocessorsandFPGAsinordertoreaptheperformancebenefits--thelanguage itselfhelpsparallelizethecode. More Resources on Multicore Programming MulticoreProgrammingFundamentalsWhitepaperSeries
www.ni.com/multicore OvercomingMulticoreProgrammingChallengeswithLabVIEW DifferencesbetweenMultithreadingandMultitasking UnderstandingParallelHardware:Multiprocessors,Hyperthreading,Dual-Core,MulticoreandFPGAs Legal Thistutorial(this"tutorial")wasdevelopedbyNationalInstruments("NI").AlthoughtechnicalsupportofthistutorialmaybemadeavailablebyNationalInstruments,thecontentinthistutorialmay notbecompletelytestedandverified,andNIdoesnotguaranteeitsqualityinanywayorthatNIwillcontinuetosupportthiscontentwitheachnewrevisionofrelatedproductsanddrivers.THIS TUTORIALISPROVIDED"ASIS"WITHOUTWARRANTYOFANYKINDANDSUBJECTTOCERTAINRESTRICTIONSASMORESPECIFICALLYSETFORTHINNI.COM'STERMSOFUSE( http://ni.com/legal/termsofuse/unitedstates/us/).
1/1
www.ni.com