CS 3650 2017 notes 21 PDF

Title CS 3650 2017 notes 21
Course Computer Systems
Institution Northeastern University
Pages 4
File Size 42.3 KB
File Type PDF
Total Downloads 4
Total Views 147

Summary

Download CS 3650 2017 notes 21 PDF


Description

CS3650:POSI XThr eads-Ex ampl es Fi r s tThi ng 

Homewor kQuest i ons ?

Pr obl emswi t hConc ur r enc y   

Shar eddat acausesdat ar aces. Lockssol vedat ar aces,causedeadl ock. Car ef ulanal ysi ssol vesdeadl ock,causesunmai nt ai nabi l i t y .

Pr obl emswi t hPar al l el i sm   

Ever yt hi ngf r om Concur r ency Wantspeedup Sequent i al i z edex ecut i onbecomesaf ai l ur ecase.

Pr i mi t i v es&Abs t r act i ons Howdowewr i t ecor r ectconcur r ent&par al l elpr ogr ams ?   

Thehar dwar egi v esusat omi ci ns t r uct i ons. Thosel etusbui l dmut exes&condv ar sorsemaphor es. Butev enwi t ht hose,ourpr ogr amsar epr obabl ywr ongandsl ow.

Thepr i mi t i v esar eni cebecauset heymak ei tpossi bl et owr i t eanypr ogr am t hatt hehar dwar eal l ows . Butt omak eourpr ogr amscor r ect ,weneedt oaddconst r ai nt s-ei t herbyconv ent i on,ori nt het ool s weuse. Somemoder nl anguagespi cki mposespeci ficcons t r ai nt sandconcur r encypat t er nst hathel p. Condi t i onsf oradat ar ace:   

Concur r ency+pr empt i onorpar al l el i sm. Shar eddat a. Mut abl edat a.

Condi t i onsf oradeadl ock:   

Hol dandwai t Ci r cul ardependenc y mut ualex cl usi onwi t hnopr eempt i on

I fweel i mi nat eanyoft hosecondi t i ons,wecanav oi dt hepr obl ems .

J av aScr i pt :NonPar al l elEv ent s 

 

Br owserJ av aScr i ptneedst ohandl eacoupl et ypesofconcur r ency : o Us eract i ons( cl i cks)coul dhappenatanyt i me. o Res ponsest onet wor kr equest scoul dhappenatanyt i me. o set Ti meout ( f unc,when)wi l lr unaf unct i onaf t eradel ay . o Somecoder unsei t herdur i ngoraf t erapagei sl oaded. Thesear eev ent s .Codet ohandl et hem needst or un,butwecan’ tspeci f yt heor derf or “ si mul t anei ous ”ev ent s . SoJav aScr i pthasanev entl oop.Ev ent sgoonaqueue,andt hehandl ercodei sr un.When onehandl eri sdone,t henextev entont hequeuei shandl ed.

Thi shassomei nt er est i ngpr oper t i es :  

Nopr eempt i on.Thenex tev enthandl ercan’ tst ar tunt i lt hepr evi ousonehasfini shed. Handl erf unct i onsar eat omi c .Thi smeanst her eusual l yar en’ tdat ar aces . Nopar al l el i sm.Onl yoneev enti shandl edatat i me.

Thi sconcur r encycans t i l l causei ssues .Yougener al l ydon’ tknowwhator derhandl er swi l lbecal l ed i n,soy ouneedt omak esur et hi sor derdoesn’ tmat t er . Thi si st hesamemodel t hatBi gBangusedi nFundi es1.Ti cksandk eyev ent scanhappenatany t i me.Handl er sr uni nsomeor der .

Mes s agePas si ng Wecanel i mi nat edat ar acesbyel i mi nat i ngshar eddat a. I ns t eadofshar i ngmemor y ,wecancommuni cat ebet weent hr eadsorpr ocessesbypassi ng mess ages. Mess agesusual l ywor koneoft woway s :  

Themessagei sacopyoft heobj ect .Si nceev er yt hr eadget si t sowncopy ,not hi ngi sshar ed andt her ear enodat ar aces. Themessagei st heonl ypoi nt ert ot heobj ect .Si ncet hesendi ngt hr eaddoesn’ tk eepacopy oft hepoi nt er ,not hi ngi sshar edandt her ear enodat ar aces .

Mess agesf r equent l yi nv ol v eamess agequeue,l i k et heonesweusedi nHW8andHW9. Al t er ni t i v el y ,messagescanbesentov eranet wor k,whi chal l owsdi s t r i but edpr ogr amst or unon mul t i pl emachi nes. Wi t hmess agepassi ng,y oust i l lhav et ol ookoutf ordeadl ocks .Acy cl eofpr ocesseswai t i ngf or mess agesf r om eachot heri sadeadl ock .Thi scanbeav oi dedei t herbybei ngcar ef ulorbymaki ng y ourcommuni c at i ongr aphaDAG. Somesy st emst hatusemess agepassi ngast hei rpr i mar ymet hodofcommuni cat i ngbet ween concur r entuni t sofex ecut i on:

  

MPI Go Er l ang

Er l ang( ak aEl i xi r ) :I mmut abl eMes sage Pas si ng Wecanel i mi nat edat ar acesbymaki ngdat ai mmut abl e.Onceanobj ecti scr eat ed,i tcannotbe changed. Er l angpr ogr amsar est r uct ur edasacol l ect i onofl i ght wei ght“ pr ocesses ” .Communi cat i onbet ween pr ocessesi sbymess agepassi ng.Becausedat ai si mmut abl e,i t ’ ssaf et opas spoi nt er st oshar ed dat aasmess ages-al t houghEr l angcanal sober undi s t r i but edacr ossmul t i pl emachi nes ,i nwhi ch casemessagesar ecopi ed. Thi smodeli sgr eatf orconcur r ency ,andgr eatf orexecut i ngconcur r ent l yst r uct ur edpr ogr amsi n par al l elf oraspeedup.I t ’ snott hegr eat estf orpar al l elspeedupt hough-Er l angr unsi nani nt er pr et er , andmut at i ont endst obepr et t ygoodf orf as tcomput at i on. Er l ang’ smai ndesi gngoali sr el i abi l i t y .I fsomepi eceoft hes y st em cr ashes,anot herpi ece( pot ent i al l y onanot hermachi ne)cannot i c eandr est ar ti t .

Cl oj ur e:Tr ans act i onalMemor y Cl oj ur ei saLI SPont heJVM. Li k eEr l ang,i tt ak est hei mmut abi l i t ypat ht odealwi t hconcur r ency ,buti nst eadofmess agepassi ngi t hasaconceptof“ r ef s ” ,whi char emut abl er ef er encest oi mmut abl edat a. Ref scanbeupdat edt r ans act i onal l y .Rat hert hanav oi di ngdat ar aces ,t r ansact i onsdet ectt hem and r ol l back/r epl ayanyt r ans act i ont hatr anonol ddat a. Tr ans act i onAdvant ages :   

Nodat acor r upt i onf r om dat ar aces Nodeadl ock Nomut ualex cl usi onneededf orv al uest hatar en’ twr i t t ent odur i ngat r ansact i on.

Tr ans act i onDi sadv ant ages :  

Needt ohandl er ol l backs/r epl ay s .I ft r ans act i onshav esi deeffect s ,t hosesi deeffect smay happenmul t i pl et i mes . Sl owt r ansact i onscanbedel ay edpr et t ymuchf or ev erbyf as t ert r ansact i onst hati nv al i dat e t hei ri nput s.

Tr ans act i onsar et hesames t r at egyt hatdat abasesusef orconcur r entupdat es. Seeex ampl eher e: ht t p: / / cl oj ur e. or g/ r ef er ence/ r ef s

Concur r enc yv sPar al l el i s m Theabov es ys t emsgi v ey ougr eatconcur r ency .Wheny ourappl i cat i onconcept ual l ydoesmany di ffer entt hi ngsatat i me,andy ouwantt oav oi ddat ar acesanddeadl ock swhi l emai nt ai ni ngsome sor tofconsi st entshar edst at e,t hey’ r eex act l ywhaty ouneed. Butsomeappl i cat i onsdon’ tl ookl i k et hatatal l .I nst ead,t heywantt odosomesequenceof comput at i onal l yi nt ensi v eoper at i onsasqui ckl yaspossi bl e,andt heywantt ot ak eadv ant ageof par al l elhar dwar ei nt hepr ocess.

OpenCL:Dat aPar al l el i s m OpenCLi sapr ogr ammi ngsy st em f orbui l di ngpr ogr amst hatr unongr aphi cscar ds .Gr aphi cscar ds , orGPUs ,ar eabi tdi ffer entf r om r egul arCPUs.Rat hert hanhavi ngonepr ocessorwi t hacoupl e cor es ,t heyhav eabunchof“ pr ocessor s” ,eachwi t hhundr edsof“ shaderuni t s” .Ashaderuni ti s basi cal l yasi ngl evect orALU-somet hi ngt hatcanex ecut ear i t hmet i ci nst r uct i onson4orsov al uesi n par al l el . OnaGPU,i t ’ sper f ect l yr easonabl et opl ant oex ecut e2000addi t i onsi npar al l eli nonecl ockcy cl e. Thet r i cki st hatGPUsr eal l yl i k et oper f or mt hesameoper at i oni npar al l el .I nf act ,eachi ndi vi dual pr ocessorcangener al l yonl yl oadonepr ogr am t or unoni t shundr edsofshaderuni t s . Soi nst eadoft hebasi caddi t i onoper at i onaddi ngt oget hert wonumber s,onaGPUi taddst oget her t woar r ays .Thear r ay sgener al l yr epr esentmat hemat i calv ect or sormat r i ces,butt hat ’ sj ustament al model .Any t hi ngwher ey ouwantt ooper at eonent i r ear r ay satoncewi l lwor kgr eatonaGPU. Thi spr ogr ammi ngmodelofper f or mi ngt hesameoper at i oni npar al l elonmanydi ffer entv al ues ( el ement soft hear r ay )i scal l eddat apar al l el i sm.I t ’ sr equi r edonGPUs ,buti t ’ scommonon super comput er st oo.Wheny ouhav eac l ust erof1000PCs ,i t ’ seasi ert ot hi nkaboutt hem wor ki ng t oget herononear r ayc al cul at i ont hant or easonaboutt hem i ndi vi dual l y ....


Similar Free PDFs