mmjobs version of the example
A model with an mmjobs version of the application program has already been shown in Section mmjobs version of the example. From multiple models running on the same Mosel instance, we now move one step further, namely, running the submodel on a remote Mosel instance. Before compiling the submodel, we connect to another Mosel instance. This instance is used for compiling to model, the source of which is located on our local machine running the master model. Remote access to a file is achieved via the rmt driver (equally defined by module mmjobs). In our example, data is exchanged via shared memory (shmem) accessed from a remote Mosel instance (rmt, optionally followed by a node number in square brackets) using binary format (bin), resulting in extended file names that combine several driver prefixes, for example, bin:rmt:[-1]shmem:burgdata to access binary data held in shared memory of the parent node.
model "Run model burglar remotely IO"
uses "mmjobs", "mmsystem"
declarations
modBurg: Model ! Submodel
moselInst: Mosel ! Mosel instance
ISet,SSet: set of string ! Index set for data arrays
V,W: array(ISet) of real ! Data arrays
SolTake: array(SSet) of real ! Solution values
end-declarations
V:: (["camera","necklace","vase","picture","tv","video","chest","brick"])
[15, 100, 90, 60, 40, 15, 10, 1]
W:: (["camera","necklace","vase","picture","tv","video","chest","brick"])
[ 2, 20, 20, 30, 40, 30, 60, 10]
!!! Select the (remote) machines to be used:
!!! Use names, IP addresses, or empty string for the node running this model
MOSINST:= ""
! Connect to a remote instance
if connect(moselInst, MOSINST)<>0 then exit(1); end-if
! Compile the model remotely
if compile(moselInst, "", "rmt:"+expandpath("burglar2m.mos"),
"shmem:burglar.bim")<>0 then
exit(2); end-if
load(moselInst, modBurg, "shmem:burglar.bim") ! Load the bim file
fdelete("rmt:["+getnode(moselInst)+"]shmem:burglar.bim")
! bim file is no longer needed
setdefstream(modBurg, F_OUTPUT, "null:") ! Disable output from submodel
! Save data in shared memory on local host
initializations to "bin:shmem:burgdata"
V as "VALUE"
W as "WEIGHT"
end-initializations
! Start model execution, setting parameters
run(modBurg,
"DATA='bin:rmt:[-1]shmem:burgdata',SOL='bin:rmt:[-1]shmem:burgsol'")
wait ! Wait for model termination
dropnextevent ! Ignore termination event message
! Retrieve solution from shared memory
initializations from "bin:shmem:burgsol"
SolTake
end-initializations
forall(i in SSet) writeln(" take(", i, "): ", SolTake(i))
end-model
