Ce qui justifie l'utilisation du multiprocessing est que plusieurs fonctions qui prennent du temps peuvent être accélérées de la même façon.
Qvar :
Citation:
[[-1.4794819743158694, 15.431016222977084, -55.49544789532253],
[-1.219318858733191, 12.585954720927015, -44.872927469225765],
[-0.2496199733795712, 1.9816345769222128, -5.279896790137833],
81.0,
114.7,
0,
0,
-0.17739858471018485],
[[-1.4794819743158694, 15.431016222977084, -55.49544789532253],
[-1.195667666407493, 12.32731276619519, -43.90724379412606],
[-0.22596878105387308, 1.7229926221903895, -4.314213115038129],
81.0,
114.7,
0,
0,
-0.17739858471018485],
[[-1.4794819743158694, 15.431016222977084, -55.49544789532253],
[-1.1720164740817949, 12.068670811463367, -42.941560119026356],
[-0.20231758872817518, 1.4643506674585645, -3.3485294399384316],
85.5,
114.7,
0,
0,
-0.16861638330503265],
[[-1.4794819743158694, 15.431016222977084, -55.49544789532253],
[-1.1483652817560968, 11.810028856731542, -41.97587644392665],
[-0.17866639640247706, 1.2057087127267394, -2.38284576483872],
91.1,
114.7,
0,
0,
-0.15768742155639878],
(elle fait plusieurs dizaines de milliers de lignes, je n'en ai mis qu'un extrait.)
Pour les erreurs, le premier code me renvoie :
Citation:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
self.run()
File "/usr/lib/python3.2/threading.py", line 693, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3.2/multiprocessing/pool.py", line 346, in _handle_tasks
put(task)
_pickle.PicklingError: Can't pickle <class 'function'>: attribute lookup builtins.function failed
Et le second donne plus d'erreurs, celle sur le processus 1 :
Citation:
Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python3.2/multiprocessing/process.py", line 267, in _bootstrap
Process Process-2:
self.run()
File "/usr/lib/python3.2/multiprocessing/process.py", line 116, in run
self._target(*self._args, **self._kwargs)
File "./find_membranes/testparall.py", line 96, in f
Traceback (most recent call last):
File "/usr/lib/python3.2/multiprocessing/process.py", line 267, in _bootstrap
File "./find_membranes/testparall.py", line 76, in <lambda>
File "/home/cacao/guiraud/find_membranes/functions.py", line 652, in ffind_all_axis_method2
Ensuite, je ne suis pas sûr de comprendre la question sur l'OS
Et le code est moyennement optimisé, la fonction prend plusieurs axes et calcule une Qvalue pour chaque tranche de chaque axe. L'idée pour accélérer le programme était de donner une partie des axes à la fonction (en donnant une partie de la variable sphere_pts) par processus et regrouper les résultats à la fin.
Sphere_points ressemble à ça (extrait) :
Citation:
[[-0.9633258011405611, -71.39091101647321, -8.727625808298926],
[12.264360679139417, -70.01880032074531, -11.814972725936206],
[0.22271086690316289, -68.64668962501743, -27.80207842745018],
[-20.40442187336518, -67.27457892928955, -21.543938022575837],
[-26.25613373248748, -65.90246823356166, -0.027326028766863075],
[-13.025339716462094, -64.53035753783378, 18.463752754254664],
[9.749799218353143, -63.15824684210588, 21.862711279404518],
[29.049424890526844, -61.786136146377984, 8.926997218458123],
[35.75193021940098, -60.414025450650094, -13.480168874381004],
[27.480160649108644, -59.04191475492221, -35.48477747346122],
[7.91415338009759, -57.66980405919432, -48.68738645536939]]
Voilà le code de la fonction, même si seule je doute que cela semble très clair
Citation:
def ffind_all_axis_method2(center, sphere_pts, data, kyteD, widthmin, widthmax, step):
"""Get the Q value for all axis and all points """
Qvar=[] #Will be the var that countains all Q valuzes for all points
for point in sphere_pts:
diam_vect=fvect(point, center)
for i,plop in enumerate(diam_vect): #We take the vector that is 2*RR
diam_vect[i]=2*plop
#We build every interval for a diam_vect
i=0 # i will be ||sphere-point C1 ||
diam_norm=fnorm(diam_vect)
Qvartemp=[]
structure=0
while (i+1) < diam_norm:
#We get the 2 plans
d_pointC1=i
d_pointC2=i+1
C1=fthales(diam_vect, d_pointC1, point )
C2=fthales(diam_vect, d_pointC2, point )
hydrophile=0
hydrophobe=0
tot=0
for elt in data: # elt : ligne de data
ok=fis_in_space(diam_vect, C1, C2, elt[:3])
if ok:
if elt[4] >= 50:
tot+=1
#Find hydrophilic and hydrophobic values
hydrophile, hydrophobe = fcalc_hydroph(hydrophile,
hydrophobe, elt, kyteD)
Qvartemp.append([point, C1, C2, hydrophobe, hydrophile, tot, structure, 0, i])
i += step
width2=widthmin
while width2 <= widthmax:
imax=len(Qvartemp)-width2 -1
i=0
while i < imax:
C1=Qvartemp[i][1]
C2=Qvartemp[(i+width2)][2]
j=0
hydrophobe=0
hydrophile=0
tot=0
while j < width2:
hydrophile+=Qvartemp[i+j][4]
hydrophobe+=Qvartemp[i+j][3]
tot+=Qvartemp[i+j][5]
j+=1
if hydrophobe !=0:
Qvar.append([point,C1, C2, hydrophobe, hydrophile, structure, 0, width2])
i+=1
width2+=1
return Qvar
Après la fonction en appelle pas mal d'autres, et l'ensemble est plutôt assez moche...