title: multiprocessing.Pool with a global variable
body: <p>I am using the Pool class from python's multiprocessing library write a program that will run on an HPC cluster.</p>
  
  <p>Here is an abstraction of what I am trying to do:</p>
  
  <pre><code>def myFunction(x):
      # myObject is a global variable in this case
      return myFunction2(x, myObject)
  
  def myFunction2(x,myObject):
      myObject.modify() # here I am calling some method that changes myObject
      return myObject.f(x)
  
  poolVar = Pool()
  argsArray = [ARGS ARRAY GOES HERE]
  output = poolVar.map(myFunction, argsArray)
  </code></pre>
  
  <p>The function f(x) is contained in a *.so file, i.e., it is calling a C function.</p>
  
  <p>The problem I am having is that the value of the output variable is different each time I run my program (even though the function myObject.f() is a deterministic function). (If I only have one process then the output variable is the same each time I run the program.)</p>
  
  <p>I have tried creating the object rather than storing it as a global variable:</p>
  
  <pre><code>def myFunction(x):
      myObject = createObject()
      return myFunction2(x, myObject)
  </code></pre>
  
  <p>However, in my program the object creation is expensive, and thus, it is a lot easier to create myObject once and then modify it each time I call myFunction2(). Thus, I would like to not have to create the object each time.</p>
  
  <p>Do you have any tips? I am very new to parallel programming so I could be going about this all wrong. I decided to use the Pool class since I wanted to start with something simple. But I am willing to try a better way of doing it.</p>