Hey I've got a working script but it work on k-combinations so it work long... I want to parallelize a for loop to divide the work time.
Here is the simplified code:
fin2 = open('combi_nod.txt','r')
for lines in fin2:
(i, j) = eval(lines)
edgefile = open('edge.adjlist', 'a')
count = 0
for element in intersection(
eval(linecache.getline('triangleset.txt', i+1)),
eval(linecache.getline('triangleset.txt', j+1))):
if element not in merge:
count = 1
break
if count == 0:
edgefile.write(' ' + str(j))
edgefile.close()
fin2.close()
How can I do this?
EDIT
After some modification I have accomplished the multiprocessing loop. But their is a associate issue:
in my initial for
loop I search in the combi_nod.txt
file;
combi_nod.txt
content is the itertools.combinaison
of large number. (so, at a point I can anymore store them in variable)
My multiprocessing loop work with a list of this itertools.combinaison
because I haven't see a way to pass line of a file in arguments (so I have a memory issue), have you a new Idea?
EDIT2
For clarification, here is the code like it is a this point:
def intersterer(lines):
(i, j) = lines
counttt = 0
for element in some_stuff:
if element not in merge:
counttt = 1
break
if counttt == 0:
return (int(i), int(j))
else:
return (0, 0)
fin2 = open('combi_nod.txt','w')
for trian_c in itertools.combinations(xrange(0, counter_tri), 2):
#counter_tri is a large number
fin2.write(str(trian_c) + "\n")
fin2.close()
fin2 = open('combi_nod.txt','r')
if __name__ == '__main__':
pool = Pool()
listt = pool.map(intersterer, itertools.combinations(xrange(0, counter_tri), 2))
f2(listt)
if (0,0) in listt: listt.remove((0,0))
and I want to have something working like:
listt = pool.map(intersterer, fin2)
But all my tests doesn't work at all... Help...