7.1 Environment and task

All interaction with Optimizer API for C proceeds through one of two entry points: the MOSEK tasks and, to a lesser degree the MOSEK environment .

7.1.1 Task

The MOSEK task provides a representation of one optimization problem. It is the main interface through which all optimization is performed. Many tasks can be created and disposed of in one process.

A typical scenario for working with a task is shown below:

MSKrescodee res = MSK_RES_OK;
MSKtask_t  task = NULL;

/* Create the task */
res = MSK_makeemptytask(NULL,     // NULL indicates we use the global environment
                        &task);

if (res == MSK_RES_OK) {
  /* Define and solve the optimization problem here 
   * ...
   */
}
else printf("An error %d while creating the task\n", res);

/* Dispose of the task */
if (task) MSK_deletetask(&task);

7.1.2 Environment

The MOSEK environment coordinates access to MOSEK from the current process. It provides various general functionalities, in particular those related to license management, linear algebra, parallel optimization and certain other auxiliary functions. All tasks are explicitly or implicitly attached to some environment. It is recommended to have at most one environment per process.

Creating an environment is optional and only recommended for those users who will require some of the features it provides. Most users will NOT need their own environment and can skip this object. In this case MOSEK will internally create a global environment transparently for the user. The user can access this global environment by passing NULL in any function call that takes an environment argument.

A typical scenario for working with MOSEK through an explicit environment is shown below:

MSKrescodee res = MSK_RES_OK;
MSKenv_t    env = NULL;

/* Create the environment */
res = MSK_makeenv(&env, NULL);

if (res == MSK_RES_OK) {
  /* Now we create a task. We could create more tasks. */
  MSKtask_t task = NULL;
  res = MSK_makeemptytask(env, &task);

  if (res == MSK_RES_OK) {
    /* Define and solve the optimization problem here 
     * ...
     */
  }
  else printf("An error %d while creating the task\n", res);
  
  /* Dispose of the task */
  if (task) MSK_deletetask(&task);
}
else printf("An error %d while creating the environment\n", res);

/* When we stop using MOSEK then dispose of the environment */
if (env) MSK_deleteenv(&env);