ImportMultiprocessing as MPImportNumPy as NPdefworker (size, IDX, arr): Array=Np.zeros ((size,size,size))Print(IDX) array[idx[0],idx[1],IDX[2]] = 100 forSliceinchRange (size): forRowinchRange (size): Arr[slice*size*size+row*size:slice*size*size+row*size+size] =Array[slice, Row,:]if __name__=='__main__': Size= 3myarray_list= [] forIinchRange (9): Myarray_list.append (MP. Array ('F', size*size*size)) PS= [MP. Process (Target=worker, args= (size, [x%3,x%3,x%3], myarray_list[x]) forXinchRange (9)] forPinchPs:p.start () forPinchPs:p.join () forXinchRange (9): Print(x) Res=Np.array (myarray_list[x]) res1=Res.reshape ((size,size,size))Print(RES1)Print(res1[1,2, 0]) Print('After all workers finished')
Multi-process data synchronization cannot be used with global, because it cannot be accessed across processes, it must be passed with multiprocessing queue, value, Array, Rawarray.
And this pass does not support multidimensional arrays, only one-dimensional support, so before and after the conversion.
Python multi-process multidimensional array data transfer example