title: Implementing Pool on a for loop with a lot of inputs
body: <p>I have been trying to improve my code (with numba and multiprocessing), but I cannot quite get it, because my function has a lot of arguments. </p>
  
  <p>I have already simplified it with other functions (see below)...</p>
  
  <p>As each agent (a class instance) is independent of each other for these actions, I would like to replace the <code>for</code> with <code>Pool</code>. </p>
  
  <p>So I would get a large function <code>pooling()</code> that I would call and pass the list of agents</p>
  
  <pre><code>from multiprocessing import Pool
  
  p = Pool(4)
  p.map(pooling, list(agents))
  </code></pre>
  
  <p>But, where do I ADD all the arguments that the pooling function will need?</p>
  
  <p>As it is:</p>
  
  <pre><code>def check_demographics(month, my_agents, families, firms, year, mortality_men, mortality_women, fertility, state_id):
  
      dummy = list(my_agents)
      d = str(state_id.iloc[0])
  
  # Place where I would like to replace the LOOP. All below would be a function 
  
      for agent in dummy:
  
          if agent.get_region_id()[:2] == d:
  
              # Brithday
              if month % 12 == agent.month - 1:
                  agent.update_age()
  
              # Mortality probability 
              if agent.get_gender() == 'Male':
                  prob = mortality_men[mortality_men['age'] == agent.get_age()][year].iloc[0]
  
              # When gender is Female
              else:
                  # Extract specific agent data to calculate mortality 'Female'
                  prob = mortality_women[mortality_women['age'] == agent.get_age()][year].iloc[0]
  
              # Give birth decision 
                  age = agent.get_age()
                  if 14 &lt; age &lt; 50:
                      pregnant(agent, fertility, year, families, my_agents)
  
              # Mortality procedures 
              if fixed_seed.random() &lt; prob:
                  mortal(my_agents, my_graveyard, families, agent, firms)
  </code></pre>
  
  <p>It is the most time consuming function in my programme.
  And <code>@jit</code> is not helping much.</p>
  
  <p>Thanks a bunch</p>