I have a multiprocessing function that takes a lot of input arguments of which all but one are the same across the processes. That is, my code would ideally look something like:
def Function(A,B,C,D):
  Do Something with A, B, C & D
  Return Result
if __name__ == '__main__':
  Workers = multiprocessing.cpu_count()
  pool = multiprocessing.Pool(processes=Workers)
  Output = pool.map(Function,A,B,C,D)
Only A changes from process to process i.e. B,C and D are global variables of different sizes and shapes. I currently have to evaluate these variables within the function as:
def Function(A):
  A = Code...
  B = Code...
  C = Code...
  Do Something with A, B, C & D
  Return Result
if __name__ == '__main__':
  Workers = multiprocessing.cpu_count()
  pool = multiprocessing.Pool(processes=Workers)
  Output = pool.map(Function,A)
This means that my code in theory could be lot faster if I could evaluate these variables globally and then pass them to pool.map(). Is there any way to do this?
