I have the following code and since it is very slow for larger l i am asking myself if there is an easy possibility to parallelize this loop. I also tried to parallize it by my own, but because I never did it before I am not able to manage it. I would be happy if you can help me out
print('Create 2.0L%.3frec%.3f.npy' % (l, r))
for x1 in range(a**l):
for x2 in range(a**l):
for x3 in range(a**l):
f11 = 0
if numpy.ndarray.sum(numpy.absolute(numpy.subtract(ws[x1:x1+1], ws[x2:x2+1]))) == 0:
f11 += 1
if numpy.ndarray.sum(numpy.absolute(numpy.subtract(ws[x1:x1+1], ws[x3:x3+1]))) == 0:
f11 += 1
re[x1][x2][x3] = 1.0*r/(a**l-2)*(numpy.product(numpy.absolute(numpy.subtract((2*ws[x1:x1+1]+ws[x2:x2+1]+ws[x3:x3+1]), 2)))-f11)
cv1 = numpy.ndarray.sum(numpy.absolute(numpy.subtract(ws[x1:x1+1], ws[x2:x2+1])))
cv2 = numpy.ndarray.sum(numpy.absolute(numpy.subtract(ws[x1:x1+1], ws[x3:x3+1])))
c2 = 0
if cv1 == 0:
c2 += 1
if cv2 == 0:
c2 += 1
c2 *= 1.0*(1-r)/2
re[x1][x2][x3] += c2
numpy.save('2.0L%.3frec%.3f' % (l, r), re)
print('Saved 2.0L%.3frec%.3f.npy' % (l, r))
So since all entries of re are independent of the others, there should be a way. I guess I would be helped if I know a solution how to parllize a python program like:
for x1 in range(a):
for x2 in range(a):
for x3 in range(a):
re[x1][x2][x3] = 5*3