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 runrtdistrconf.mos
   Running a model on a remote machine,
   setting configuration options for the remote instance.

   Before running this model, you need to set up the 
   NODENAME with a machine name/address of your local network.
   The node that is used needs to have the same version of
   Xpress installed and suitably licensed, and the server 
   "xprmsrv" must have been started on this machine.
   (c) 2010 Fair Isaac Corporation
       author: S. Heipcke, May 2010, rev. Feb. 2014

model "Run model rtparams remotely"
 uses "mmjobs"

  modPar: Model
  mosInst: Mosel
                                   ! Compile the model file
 if compile("rtparams.mos")<>0 then exit(1); end-if

!!! Connection name string:
!!! ======================
!!! Use the name or IP address of a machine in your local network,
!!! or "" for current node.
!!! The name may also include configuration options (e.g., new values for
!!! environment variables, or arguments for the Mosel command line), or,
!!! with the 'rcmd' driver specify a command to be executed.
!!! Here are some examples:
! NODENAME:= ""             ! A new local instance with unchanged settings
! NODENAME:= "localhost"    ! A new Mosel instance on local host
                            ! (similar to previous, but uses xsrv protocol)

! NODENAME:= "xsrv:localhost|MOSEL_CWD=c:\\mydir\\"
                            ! Set working directory for local instance (Win)
! NODENAME:= "xsrv:localhost|MOSEL_CWD=/tmp/mydir"
                            ! Set working directory for local instance (Unix)

! NODENAME:= "ABCD123"      ! Remote instance on machine "ABCD123"
! NODENAME:= "123.456.789"  ! Remote instance at address 123.456.789
                            ! Set working directory for remote instance (Unix)

! NODENAME:= "xsrv:localhost|MOSEL_ARGS=-rv 10 -rl '/tmp/mylog.txt'"
                            ! Set Mosel command line arguments.
                            ! Full list is obtained with:  mosel -h
                            ! -rv 10      very verbose remote communication
                            ! -rl aFile   define logging file for rmt instance

! NODENAME:= "rcmd:mosel -r -rv 10 -rl '/tmp/mylog.txt'"
                            ! Similar to the above, more direct communication
                            ! as this does not use the network server
! NODENAME:= "rcmd:rsh ABCD123 mosel -r"
                            ! Start remote instance on "ABCD123" connecting
                            ! via rsh
                            ! (Note: option -r is required for remote runs)

! NODENAME:= "xsrv:localhost|XPRESSDIR=c:\\xpress7\\"
                            ! Use some other Xpress version (must support
                            ! remote features!), e.g. 32bit remotely with
                            ! this model running under 64bit

!!! Aliases:
!!! =======
!!! You can also associate other connections than default with node names.
!!! For example:
! sethostalias("localhost","rcmd:mosel -r")
! sethostalias("ABCD123","rcmd:rsh ABCD123 mosel -r")

                                   ! Open connection to a remote node
 if connect(mosInst, NODENAME)<>0 then exit(2); end-if
                                   ! Load the bim file into the remote instance
 load(mosInst, modPar, "rmt:rtparams.bim") 
                                   ! Start model execution
 run(modPar, "PARAM1=" + 2 + ",PARAM2=" + 3.4 + 
             ",PARAM3='a string'" + ",PARAM4=" + true)
 wait                              ! Wait for model termination
 dropnextevent                     ! Ignore termination event message


Back to examples browserPrevious exampleNext example