User guide

92 CHAPTER 3. THE LIBRARY
AND messcofn(node) = VALOF
{ qitem(node) // Put the message on the work queue for this node
{ // Start processing the first message
LET prtime = rnd(ptmax) // a random processing time
LET dest = rnd(nodes) + 1 // a random destination node
LET netdelay = ABS(node-dest) // the network delay
IF tracing DO
writef("%i8: node %i4: processing message until %n*n",
simtime, node, simtime+prtime)
waitfor(prtime)
count := count + 1 // One more message processed
IF tracing DO
writef("%i8: node %i4: message processed*n",
simtime, node, dest, simtime+netdelay)
dqitem(node) // De-queue current item and activate the next, if any
IF tracing DO
writef("%i8: node %i4: sending message to node %n to arrive at %n*n",
simtime, node, dest, simtime+netdelay)
waitfor(netdelay)
node := dest // The message has arrived at the destination node
IF tracing DO
writef("%i8: node %i4: message reached this node*n",
simtime, node)
qitem(node) // Queue the message if necessary
// The node can now process the first message on its work queue
} REPEAT
}
// ######################### Main Program ############################
LET start() = VALOF
{ LET seed = 0
LET argv = VEC 50
UNLESS rdargs("-n/n,-s/n,-p/n,-r/n,-t/s", argv, 50) DO
{ writef("Bad arguments for cosim*n")
RESULTIS 0
}
nodes, stoptime, ptmax := 500, 1_000_000, 1000
IF argv!0 DO nodes := !(argv!0) // -n/n
IF argv!1 DO stoptime := !(argv!1) // -s/n
IF argv!2 DO ptmax := !(argv!2) // -p/n
IF argv!3 DO seed := !(argv!3) // -r/n
tracing := argv!4 // -t/s