Skip to contents

This optimizes rxode2 code for computer evaluation by only calculating redundant expressions once.

Usage

rxOptExpr(x, msg = "model", chunkLines = 40L, parallel = 0L)

Arguments

x

rxode2 model that can be accessed by rxNorm

msg

This is the name of type of object that rxode2 is optimizing that will in the message when optimizing. For example "model" will produce the following message while optimizing the model:

finding duplicate expressions in model...

chunkLines

Integer; when positive (the default is 40), a model longer than this many lines is optimized in contiguous cost-balanced chunks of roughly this many lines instead of in a single pass; 0 always optimizes the whole model at once. Chunking amortizes the strongly superlinear cost of normalizing a large machine-generated model, which is what dominates the optimization of a sensitivity- or Jacobian-augmented model. Subexpressions are then shared only within a chunk, so the result is an equivalent model – the same states, parameters, solution and errors – carrying more temporaries. A chunk is a fragment, so if any chunk fails to optimize the whole model is optimized instead.

parallel

Integer; number of mirai daemons used to optimize the chunks in parallel, used only when the model is chunked. It carries the same semantics as rxControl(cores=): 0 (the default) means the rxode2 thread setting rxCores() (setRxThreads(), OMP_THREAD_LIMIT); 1 runs the chunks serially. It is capped by the number of chunks and by rxCores(), so it will not oversubscribe. An existing mirai daemon pool is used as-is and left running; otherwise a pool is started for the call and shut down when it returns, and only when the model splits into at least 4 chunks, where the parallel win covers the startup.

Value

Optimized rxode2 model text. The order and type lhs and state variables is maintained while the evaluation is sped up. While parameters names are maintained, their order may be modified.

Author

Matthew L. Fidler