5 Guidelines

5.1 Parallel optimization Using the The Multicore Package

The R package called multicore, provides functions for parallel execution of R code on machines with multiple cores or CPUs. Windows is not currently supported, but the package should work on most UNIX-alike platforms.

The multicore package works by copying the full memory state of the R session to new processes. While this seems like a large overhead, in practice, the copy is delayed until modification assuring a smooth parallel execution. The downside is that this low-level memory state copy is not safe for all types of resources. As an example, parallel interactions with the GUI or on-screen devices can cause the R session to crash. It is thus recommended only to use the multicore package in console R.

In the Rmosek package a license is an externally acquired resource, and attempts to simply copy the memory state of this resource will provoke a session crash. Thus, licenses should always be released before the time of parallelization.

Note

Always call mosek_clean() before a parallelizing operator. Failure to do so is likely to provoke session crashes.

A consequence of this is that each new process will be using a separate license. That is, your license system should allow 8 licenses to be checked out simultaneously, if you wish to solve 8 optimization problems in parallel. Please note that unlimited academic and commercial licenses are available at MOSEK.

5.2 The license system

MOSEK is a commercial product that always needs a valid license to work. MOSEK uses a third party license manager to implement license checking. The number of license tokens provided determines the number of optimizations that can be run simultaneously.

By default a license token remains checked out from the first optimization until the end of the MOSEK session, i.e.

  • a license token is checked out when mosek is called the first time and
  • it is returned when R is terminated, or mosek_clean is called.

Starting the optimization when no license tokens are available will result in an error.

Default behaviour of the license system can be changed in several ways:

  • Setting the parameter MSK_IPAR_CACHE_LICENSE to "MSK_OFF" will force MOSEK to return the license token immediately after the optimization completed.

    prob$iparam <- list(CACHE_LICENSE = "MSK_OFF");
    
  • Setting the parameter MSK_IPAR_LICENSE_WAIT will force MOSEK to wait until a license token becomes available instead of returning with an error.

    prob$iparam <- list(LICENSE_WAIT = "MSK_ON");
    
  • The license can be manually released by calling mosek_clean.