6.12 Parallel optimization

In this section we demonstrate the method optimizebatch which is a parallel optimization mechanism built-in in MOSEK. It has the following features:

  • One license token checked out by the environment will be shared by the tasks.

  • It allows to fine-tune the balance between the total number of threads in use by the parallel solver and the number of threads used for each individual task.

  • It is very efficient for optimizing a large number of task of similar size, for example tasks obtained by cloning an initial task and changing some coefficients.

In the example below we simply load a few different tasks and optimize them together. When all tasks complete we access the response codes, solutions and other information in the standard way, as if each task was optimized separately.

Listing 6.24 Calling the parallel optimizer. Click here to download.
using Mosek

# Example of how to use env.optimizebatch().
# Optimizes tasks whose names were read from command line.
if length(ARGS) < 2
    println("Usage: parallel FILENAME FILENAME [ FILENAME ... ]")
else
    n = length(ARGS)
    makeenv() do env
        # Use remote server: putoptserverhost(task,"http://solve.mosek.com:30080")
        tasks = [ maketask(filename=f) for f in ARGS ]

        # Size of thread pool available for all tasks
        threadpoolsize = 6

        for t in tasks
            putintparam(t,MSK_IPAR_NUM_THREADS, 2)
        end

        # Optimize all the given tasks in parallel
        (trm,res) = optimizebatch(env,
                                  false,          # No race
                                  -1.0,           # No time limit
                                  threadpoolsize,
                                  tasks)          # Array of tasks to optimize

        for (i,t) in enumerate(tasks)
            println("Task  $i  res $(res[i])   trm $(trm[i])   obj_val  $(getdouinf(t,MSK_DINF_INTPNT_PRIMAL_OBJ))  time $(getdouinf(t,MSK_DINF_OPTIMIZER_TIME))")
        end
    end
end

Another, slightly more advanced application of the parallel optimizer is presented in Sec. 11.3 (Concurrent optimizer).