³ò N ¤Ec@smdZddkZddkZddkZddkZddkZddkZddkZddkZddk Z ddk Z dZ dZ edjo™hZeiZeiZeiƒZee_ee_eieeiƒƒdƒeiƒx9eiiƒZeieƒpáeidƒeiƒeeiiƒƒZ eii!e ƒZ"e i#e"ƒ\Z$Z%Z&gZ'e%D]Z(e'e)e(dd ƒqw['Z*xGe&D]?Z+ye,e+ƒe-ƒe+e*D]6Z1ye2e1ƒWq[d GHei.ei/ƒŒq[Xq[We-ƒe$Z3ye3e0ŒZ4Wn%d GHei.ei/ƒŒdZ4nXe i6e4ei7ƒfƒZ"eiee8e"ƒƒdƒeie"ƒeiƒq÷nddd„ƒYZ9ddd„ƒYZ:ddd„ƒYZ;dS(sfParallel Python SMP http://www.parallelpython.com - documentation, usage examples and support forum iÿÿÿÿNs>Copyright (c) 2005-2007 Vitalii Vanovschi. All rights reserveds1.1 betat__main__s sY stexecs-An error has occured during the module importsN s/An error has occured during the function imports2An error has occured during the function executiont_TaskcBseZd„Zd„ZRS(cCs)tiƒ|_|iiƒ||_dS(N(tthreadt allocate_locktlocktacquirettid(tselftserverR((s/home/vitaly/dev/ppsmp/ppsmp.pyt__init__Fs cCs!|iiƒ|iiƒ|iS(N(RRtreleasetresult(R((s/home/vitaly/dev/ppsmp/ppsmp.pyt__call__Ks  (t__name__t __module__R R (((s/home/vitaly/dev/ppsmp/ppsmp.pyREs t_WorkercBseZd„ZRS(cCs~dtidtd}tiidƒod|d}nti|ƒ\|_|_t|ii ƒƒ|_ t |_ dS(Ns"s" "twin( tsyst executablet__file__tplatformt startswithtpopen2trtwtinttreadlinetpidtTruetis_free(Rtcommand((s/home/vitaly/dev/ppsmp/ppsmp.pyR Rs (RRR (((s/home/vitaly/dev/ppsmp/ppsmp.pyRQstServercBs’eZdZdeieid„Zd„Zd„Z d„Z ddd„Z d„Z dd„Z d „Zd „Zd „Zd „Zd „ZRS(s/Parallel Python SMP execution server class t autodetectcCsš|i||ƒtidt|ƒƒd|_g|_d|_tiƒ|_ tiƒ|_ g|_ h|_ |i |ƒtid|ifƒdS(sè Creates server instance ncpus - the number of worker processes, if parammeter is omitted it will be set to the number of processors in the system loglevel - logging level logstream - log destiunation With ncpus = 1 all tasks are executed consequently For the best performance either use default "autodetect" value or set ncpus to the total number of processors in the system screating server instance is$ppsmp server started with %d workersN(t_Server__initLogtloggingtdebugtstrt _Server__tidt_Server__queuet_Server__activeTasksRRt_Server__addToActiveTasks_lockt_Server__scheduler_lockt_Server__workerst_Server__sourcesHMt set_ncpustinfot_Server__ncpus(Rtncpustloglevelt logstream((s/home/vitaly/dev/ppsmp/ppsmp.pyR `s       cCs¡tidt|ƒƒxƒ|iD]x}tid|ifƒtiidƒo"ti dt|iƒdƒq!ti |idƒti |idƒq!WdS(Nsdeleting server instance s#exiting worker process with pid=%d RsTASKKILL /PID s /Fi i( R#R$R%R+RRRRtostpopentkilltwaitpid(Rtworker((s/home/vitaly/dev/ppsmp/ppsmp.pyt__del__xs "cCs‹ttdƒo8tidƒ}t|tƒo|djo|SqHntiidƒo,ttidƒ}|djo|Sq‡ndS(NtsysconftSC_NPROCESSORS_ONLNitNUMBER_OF_PROCESSORSi(thasattrR3R9t isinstanceRtenvironthas_key(RR0((s/home/vitaly/dev/ppsmp/ppsmp.pyt__detect_ncpus„s   cCshti|ƒ}|i|ƒ|itidƒƒtidƒ|_|ii|ƒ|ii|ƒdS(Ns%%(asctime)s %(levelname)s %(message)st(R#t StreamHandlertsetLevelt setFormattert Formattert getLoggert_Server__loggert addHandler(RR1R2t logHandler((s/home/vitaly/dev/ppsmp/ppsmp.pyt __initLog’s  cCse|iƒ}t||ƒ}|ii|||||fƒ|iid||ifƒ|iƒ|S(sSubmits function to the execution queue func - function to be executed args - tuple with arguments of the 'func' depfuncs - tuple with functions which might be called from 'func' modules - tuple with module names to import sTask %i submited, function='%s'(t_Server__gentidRR'tappendRGR$t func_namet_Server__scheduler(RtfunctargstdepfuncstmodulesRtjob((s/home/vitaly/dev/ppsmp/ppsmp.pytsubmit›s  cCs|iS(s&Returns the number of worker processes(R/(R((s/home/vitaly/dev/ppsmp/ppsmp.pyt get_ncpus«scCsÂ|djo|iƒ}nt|tƒptdƒ‚n|djotdƒ‚n|t|iƒjoE|iig}t|t|iƒƒD]}|t ƒq—~ƒn||_ dS(s¶Sets the number of worker processes ncpus - the number of worker processes, if parammeter is omitted it will be set to the number of processors in the systemR!sncpus must have 'int' typeis ncpus must be a positive integerN( t_Server__detect_ncpusR=Rt TypeErrort ValueErrortlenR+textendtrangeRR/(RR0t_[1]tx((s/home/vitaly/dev/ppsmp/ppsmp.pyR-¯s  Ec CsÈ|iiƒ|i|ijo—|io|iidƒ}x?|iD]}|iot|_PqFqFW|i i dƒd‚|i dƒyt i |i||fƒWq·q·Xn|iiƒdS(NisThere are no free workers leftsError: No free workersi(R*RR(R/R'tpopR+RtFalseRGterrort_Server__add_to_active_tasksRtstart_new_threadt _Server__runR (RttaskR7((s/home/vitaly/dev/ppsmp/ppsmp.pyt __scheduler½s       cCsDt|ƒ}|ii|ƒpti|ƒ|i|srl          -