2023

.pdf
School
The University of Hong Kong**We aren't endorsed by this school
Course
ELEC 3543
Subject
Electrical Engineering
Date
Dec 20, 2024
Pages
8
Uploaded by PresidentCoyote3454
THEUNIVERSITYOFHONGKONGBachelorofEngineeringDepartmentofElectrical&ElectronicEngineeringELEC3543AdvancedSystemsProgrammingExaminationDate:13December2023__Time:—2:30pm-5:30pm___AnswerALLquestions.UseofElectronicCalculators:“OnlyapprovedcalculatorsasannouncedbytheExaminationsSecretarycanbeusedinthisexamination.Itiscandidates’responsibilitytoensurethattheircalculatoroperatessatisfactorily,andcandidatesmustrecordthenameandtypeofthecalculatorusedonthefrontpageoftheexaminationscript.”EEE/ELEC3543/2023Decpage1of8
Background image
Question1.(36marks)(a)ThefollowingPythonprogramisaslightlymodifiedversionofthesampleprogramasdiscussedintheMod-3notestocreateanobjectoftheqm_moleculeclassasextendedfromtheatomclass,andthendisplaytheinvolvedobjects.Classatom(object):definit(self,atno,x,y,z):self.atno=atnoself.position=(x,y,z)defrepr(self):a#Amissingstatementhere!#Definetheextendedqmmoleculeclass#andalsotheaddbasismethodherevestesees.#Afewmissingstatementshere!atom(6,O.1,1.1,2.3)Vatom(8,-1.2,2.4,3.7)Zatom(ll,0.5,1.3,1.9)gqml=qmmolecule(-1,0.66,2.7,1.99)gml.atomlist=[x,y,2]qml.addbasis()print(x)print(y)print(z)|(xXprint(qm1)print(qml.basis)Insidetheaddbasismethod,eachatomobjectoftheatomlistwillbeaddedintothebasislistthatisinitializedasanemptylistinthebeginning.ClearlystateALLthemissingstatementsONLYtocompletetheabovePythonprogramsothatthefollowingoutputwillbeproduced.$python3Ola.py60.1000J1.10002.30008-1.20002.40003.7000110.50001.30001.9000-10.66002.70001.9900[60.10001.10002.3000,8-1.20002.40003.7000,110.50001.30001.9000](12marks)(b)Theaboveprogramoutputbyexecuting“OJa.py”isre-directedtoatextfilenamed“QM_Molecules.log”underthecurrentdirectory.WiththefollowingprogramfragmentonsocketprogramminginPython,EEE/ELEC3543/2023Dec|page2of8
Background image
#ASimpleTCPClient/ServerProgramimportsocketHOSTPORT'127.0.0.1'#Theclient/server'sIPaddress65332#Theportusedbyclient/server#SomeMissingstatementshere!astudentenrolledinELEC3543successfullyimplementsbothTCPclientandserverprogramsinPythoninwhichtheTCPclientprogramreadseachlinefromthe“OMMolecules.log”underthecurrentdirectory,andsendsthelineviaitsconstructedTCPsockettothelocalTCPserver.Ontheotherhand,thelocalTCP serverprogramreceiveseachtextlinesentbytheTCPclientprogramviatheTCPsocket,andthendisplaythereceivedtextlineonthestandardoutput.Basedontheaboveprogramfragment,clearlystateALLthemissingstatementsONLYtocompleteBOTHTCPclientandserverprogramssothatthefollowingoutputwillbeproducedonthesamehostmachine.$python3O1lbSockProgTCP_Server.pyConnectedby('127.0.0.1',54662)60.10001.10002.30008-1.20002.40003.7000Il0.50001.30001.9000-l0.66002.70001.9900[60.10001.10002.3000,8-1.20002.40003.7000,110.50001.30001.9000]|$python3Olb_Sock_ProgTCP_Client.py(24marks)EEE/ELEC3543/2023Decpage3 of8
Background image
Question2.(28marks)(a)Concurrencycanbeusefultohandletwomajortypesofproblems.Clearlydefineeachtypeoftheproblemswiththeaidofadiagram.Besides,explainhowconcurrencymayhelpineachcase.(10marks)(b)Detailthereason(s)whythelatesttrendsofnetworkservicesisimplementedbymulti-threadingratherthanmulti-processing.(6marks)(c)ThefollowingGPUprogramwasexecutedontheGoogleColaboratory(Colab)platform.fromnumbaimportvectorizeimportnumpyasnpy@vectorize(['float32(float32,Float32)'],target='cuda')defadd_unifunc(i,4):reCurn2+4n=121200a=npy.arange(n).astype(npy.float32)b=3*aS6timeitaddunifunc(a,b)YettheGoogleColabreturnswithanerrormessageas“CudaSupportError:Erroratdriverinit:”.Clearlyexplaintheunderlyingreason(s)forsucherror,andsuggestonepossiblesolutiontofixtheproblem.Besides,usingthe“devicememory”undertheCUDAprogrammingmodelasdiscussedintheMod-8notes,modifytheaboveGPUprogramtoenhanceitstimeperformance.Clearlyshowyourcodemodifications(i.e.simplyhighlightingthe*codechanges*withoutcopyingthewholeprogram)intheanswerbook.(12marks)EEE/ELEC3543/2023Dec.page4of8
Background image
Question3.(36marks)ARevisiononEssentialConceptsCarefullyread eachofthefollowing questionsandwritedownthe mostappropriateoptioninyouranswerbook,e.g.1)X;2)YwhereXandYareyourselectedoptionsforthecorrespondingquestions.Eachquestioncarries3marks.Imarkwillbedeductedforanywronganswer_ormultipleoptionsprovidedtoeachquestion.Nomarkwillbedeductedforanyblankanswer.1)Whichofthefollowingshouldbespecifiedfor theJIT compilationusingtheNumbalibrary?A.whetherthePythonfunctionisarray-orientedornot;themaximumnumberofthreadstomanageeachdatablock;thetargetedGPUmodellikeRTX4090;thetypesignaturesofthePythonfunction;mofFfwhetherthereturntypeofthePythonfunctionisarray-orientedornot.2)WhatistheexpectedoutputafterexecutingthefollowingPythonprogram?a=[6.34,4,'?']c=(3.46,8,'3')a.insert(2,Cc)print(a)c=d=ad+=('foo',)print(c)A.[6.34,4,'?"',(3.46,8,'3')][6.34,4,"?",(3.46,8,"S3'),"foo']B.(6.34,4,'?"',(3.46,8,'3"))(6.34,4,'?',(3.46,8,'%S'),'foo')C.[6.34,4,(3.46,8,'S'),'?'][6.34,4,(3.46,8,'S'),'?','foo']D.[6.34,4,(3.46,8,'S'),'?"](6.34,4,(3.46,8,'S'),'?','foo')E.TheexceptionTypeErrorisraised.EEE/ELEC3543/2023Dec.page5of8
Background image
3)Thest_ctimefieldofafileasreturnedbycallingtheos.fstat(...)functionwillonlybechangedaftercallingA.lseek(...);read(...);_write(...);chown(...);mooODWopen(...).4)Howmanytimeswilltheoutputlineof“Insidetheloop.”bedisplayedafterexecutingthefollowingPythonprogram?forainrange(2,17,2):ifa>9:a+=2?Continuea=at+iprint("Insidetheloop.")ifa==16:breakprint("Outsidetheloop.")3times;4times;5times;6times;moOw>7times.5)Whenthelinkcountofani-nodeisgreaterthan0,itmeansA.thei-nodeissharedbyoneormoreprocessesundertheUnixsystem;B.thei-nodeisasymboliclink;C.thei-nodeisavirtualdevicefilelocatedonblock-0ofthefile-system;D.thei-nodeisactuallyadirectoryfile;E.thei-nodeisreferencedbysomedirectoryofthefile-system.EEE/ELEC3543/2023Decpage6of8
Background image
6)ThesharedmemoryoftheCUDAprogrammingmodelcannotbeusedforA.bufferingoutputfromthreadswithinthesameblockformergingbeforewritingitbacktodevicememory;B.cachingoflookuptablestobeandonilyaccessed;C.cachingofpersistentresultsafteraCUDAkernelfinishesitsexecution;D.stagingdataforscatteroperationswithinablock;E.stagingdataforgatheroperationswithinablock.7)Adual-bootsystembuiltontheUnixfile-systemisA.onediskpartitionwithtwobootstrapprograms,asuperblock,ani-nodetableandthedata/directoryblocks;B.onediskpartitionwithmultiplebootstrapprograms,asuperblock,ani-nodetable,thedeviceblocksanddata/directoryblocks;C.twodiskpartitionsinwhicheachpartitionhasitsownsuperblock,i-nodetableanddata/directoryblocks;D.twodiskpartitionsinwhicheachpartitionhasitsownbootstrapprogram,superblock,i-nodetableanddata/directoryblocks;E.onediskmanagerpartitionandtwobootablepartitionscontainingitsownprocesstable,ani-nodetable,anv-nodetableandthedata/directoryblocks.8)DevicefunctionsinNumbaareA.createdwiththenumba.cuda.devicedecorator;B.moreefficientthanuniversalfunctionsinNumpy;C.requiringalllogicstobeputintoonesinglefunction;D.creatingnormalfunctionstobeonlycalledfromotherfunctionsrunningontheCPU;E.creatingnormalfunctionstobeonlycalledfromotherfunctionsrunningontheGPU.9)ForthestaticinnovationinCORBA,theIDLcompilergeneratesA.theclientstubandtheserverstub;B.theORBagent;C.theclientstubandtheserverskeleton;D.theserverobject;E.theresponsepageinXMLtocommunicatewiththeserverobject.EEE/ELEC3543/2023Dec|page7of8
Background image
10)WhichofthefollowingstatementscanhelptopreservethecommandlineargumentsinaPythonprogram?A.arg=sys.argv[0]B.arg=sys.argv[1:]C.print(sys.argv)D.SyS.argv.pop()BE.SyS.argv.push(‘*END’)11)Thetimes.process_time()functioninPythonreturnsA.theaveragedwall-clockexecutiontimeinsecondsformultipleprocesses;B.theCPUtimeinsecondsofthecurrentprocess:C.theCPUandsleeptimeinsecondsofthecurrentprocess;D.theCPUtimeinnanosecondsofthecurrentprocess;EtheCPUtimeinmicrosecondsofthecurrentandchildprocesses.12)WhichofthefollowingstatementsshouldbeusedtoSpawnanewthreadforinvokingaPythonfunction£withoutanyargument?A.thread.start_newthread(f,())-thread.startnewthread(f,[])BC.thread.start_newthread(f,{})D.thread.startnewthread(f,null).thread.start_new_thread(f,argv,EMPTYARGS)#%*ENDOFPAPER**#EEE/ELEC3543/2023Decpage8of8
Background image