FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Working with multiple models: submodels, coordination, communication, and parallelization

The Mosel module mmjobs enables the user to work with several models concurrently. We show here a series of examples of basic tasks that typically need to be performed when working with several models in Mosel:

Parallel computing:
  • Running a submodel from another Mosel model: runtestsub.mos (main model executing testsub.mos)
  • Retrieving termination status from submodels (means of coordination of different models): runsubevnt.mos (main model executing testsub.mos)
  • Retrieving user event sent by the submodel: runsubevnt2.mos (main model executing testsubev.mos)
  • Stopping a submodel: runsubwait.mos (main model executing testsub.mos)
  • Compiling to memory: runsubmem.mos (main model executing testsub.mos)
  • Setting runtime parameters: runrtparam.mos (main model executing rtparams.mos)
  • Sequential execution of submodels: runrtparseq.mos (main model executing rtparams.mos)
  • Parallel execution of submodels: runrtparprl.mos (main model executing rtparams.mos)
  • Parallel execution with cloning of submodels: runrtparclone.mos (main model executing rtparams.mos)
  • Job queue for parallel execution of submodels: runrtparqueue.mos (main model executing rtparams.mos)
  • Using the shmem (shared memory) I/O driver for data exchange (bin format): runsubshm.mos (main model executing testsubshm.mos)
  • Using the shmem (shared memory) I/O driver for data exchange (raw format): runsubshmr.mos (main model executing testsubshmr.mos)
  • Using the mempipe (memory pipe) I/O driver for data exchange: runsubpip.mos (main model executing testsubpip.mos)
  • Sharing data between cloned models: runsubclone.mos (main model executing a copy of itself)
Distributed computing:
  • Check for available remote Mosel servers: findservers.mos
  • Run a single model on a remote machine: runrtdistr.mos (main model executing rtparams.mos)
  • Run a single model on a remote machine with configuration options: runrtdistrconf.mos (main model executing rtparams.mos)
  • Running parallel submodels in a distributed architecture: runrtpardistr.mos (main model executing rtparams3.mos)
  • Queuing submodels for parallel execution in a distributed architecture with one or several models per node: runrtparqueued.mos (main model executing rtparams3.mos)
  • 3-level tree of (parallel) submodels: runrtpartree.mos (main model executing rtparams2.mos)
  • Running a submodel that detaches itself from its parent: runrtdetach.mos (main model executing rtparams4.mos)
  • Using the shmem (shared memory) I/O driver for data exchange (bin format): runsubshmdistr.mos (main model executing testsubshm.mos)
Further explanation of this example: Xpress Whitepaper 'Multiple models and parallel solving with Mosel', Section 'Basic tasks'.

Source Files


   Mosel Example Problems 

   file runrtpartree.mos
   Running several instances of a model from another
   Mosel model.
   - Parallel submodels over 3 levels (submodel tree)
     possibly running in a distributed architecture -

   Before running this model, you need to set up the array
   NODENAMES with machine names/addresses of your local network.
   All nodes that are used need to have the same version of
   Xpress installed and suitably licensed, and the server 
   "xprmsrv" must have been started on these machines.
   (c) 2010 Fair Isaac Corporation
       author: S. Heipcke, May 2010

model "Recursive model runs"
 uses "mmjobs", "mmsystem"

  LEVEL = 0
  BRANCH = 0
  PARAM1 = 0
  PARAM2 = 0.5
  PARAM3 = ''
  PARAM4 = false

  A = 1..5
  modPar: array(A) of Model
  NODENAMES: array(range) of string

!!! Select the (remote) machines to be used:
!!! Use names, IP addresses, or empty string for the node running this model
 NODENAMES:: (1..3)["", "", ""]     

 writeln(" "*LEVEL, LEVEL, "/", BRANCH, ": ", SUBMODNAME, "(", MODCOUNT, "), ",
         "Node: ", getparam("NODENUMBER"))

                                   ! Compile the model file in first run
 if LEVEL=0 then
  if compile("runrtpartree.mos")<>0 then exit(1); end-if
  if compile("rtparams2.mos")<>0 then exit(1); end-if
 forall(i in A) do
  load(M,modPar(i), RMT+NEWSUBNAME+".bim")  ! Load the bim file
                                   ! Start model execution
  run(modPar(i), "SUBMODNAME=" + NEWSUBNAME + ",MODCOUNT=" + (10*MODCOUNT+i) + 
                 ",LEVEL="+ (LEVEL+1) + ",BRANCH="+ i +
                 ",PARAM1=" + i + ",PARAM2=" + 0.1*i +
                 ",PARAM3='string " + i + "'" + ",PARAM4=" + isodd(i))
!  wait(1)
 forall(i in A) do
  wait                             ! Wait for model termination
  dropnextevent                    ! Ignore termination event message


Back to examples browserPrevious exampleNext example