0

I would like to run the fmin_powell optimizer for different arguments from the f list at the same time.

f = ['1','2','3','4','5','6']
optg_res = opt.fmin_powell(runner, coeff, args=(f,f), disp=0)

Is there any easy method of doing it? Maybe I would use any bash command to run it?

Monica
  • 1,030
  • 3
  • 17
  • 37

1 Answers1

0

You can use the multiprocessing module for it and have each call to fmin_powell run in a separate process in parallel. Pool.map() submits the calls to a process pool and returns a list of result values for each value in the parameter list.

See this example code for 4 processes in parallel based on the code given in your question:

from multiprocessing.pool import Pool

def optimize(f):
    return opt.fmin_powell(runner, coeff, args=(f,f), disp=0)

f = [1,2,3,4,5,6]

p = Pool(processes=4)
results = p.map(optimize,f)
acidtobi
  • 1,375
  • 9
  • 13
  • Is it going to work out fine if I open a file in a runner function in order to save iteration steps? I got multiply files with the right names, but I have impression that the results are saving randomly. – Monica Mar 29 '17 at 21:58
  • Writing to files should work, but keep in mind that the order in which optimize() is called depends on a few factors, see this question: http://stackoverflow.com/questions/17903355 – acidtobi Mar 29 '17 at 22:24