Python Multiprocessing Pool.map() issue -
i have code performs lot of independent tasks in loop i'd convert multiprocessing speed up. i've managed speed looping task elsewhere in code in manner, , 1 appears similar. however, fails giving error below:
file "z:\blade test ktp\bladetestoptimisationsoftware\python\source\steadystatemp.py", line 2196, in <module> x0,fitnesstracker=gamainfunc(gapopulation,gageneration,crossover,mutation,fitnessscaling,swapvariables,bounds,args+(false,)) file "z:\blade test ktp\bladetestoptimisationsoftware\python\source\steadystatemp.py", line 1480, in gamainfunc result = pool.map(func,populationlist) file "c:\python27\lib\multiprocessing\pool.py", line 251, in map return self.map_async(func, iterable, chunksize).get() file "c:\python27\lib\multiprocessing\pool.py", line 558, in raise self._value nameerror: global name 'nodeslist' not defined
unfortunately, runable example isn't feasible because of amount of code, size of input files , fact i'd in trouble putting in public domain... i've not managed replicate problem on smaller scale either (as mentioned above, succesfully implemented multiprocessing elsewhere , i've made code similar). structure of code shown below:
functools import partial import multiprocessing mp def optimfunc(x0,sectionprops,sectiontoanalyse,nodes,elnormtarget,optiminput, k,kl,m,rlb,damping,cdb,testtype,teststandpitch,bladepitch,gravity,fullreturn): #do stuff , return scalar value. nodeslist can printed def swapvariables(consts,string): x0=stringtoarray(string) return optimfunc(x0,*consts[0]) populationlist=[list,containing,different,trial,solutions,for,optimisation,function] consts=(sectionprops,sectiontoanalyse,nodes,elnormtarget,optiminput, k,kl,m,rlb,damping,cdb,testtype,teststandpitch,bladepitch,gravity) func=partial(swapvariables,[consts]) nocpus=mp.cpu_count() pool=mp.pool(processes=nocpus) result = pool.map(func,populationlist) error=np.array(result) pool.close()
a non-parallel implementation of works fine (literally replacing pool.map() itertools.map() or looping). difference between , succesful implementation nodeslist numpy array, tried putting array inside dictionary , list (which types of variables function used in succesful parallel loop takes) same error. avoid global variables plague insulted python suggest i'm using them! weirdest part can print nodeslist inside optimfunc before used in anger. on appreciated!
Comments
Post a Comment