next up previous contents index
Next: Program Control Up: Multi-threading Previous: Multi-Threaded Loading   Contents   Index

Multi-Threaded Looping

A second potentially profitable use of multiple threads is when performing parameter sweeps, i.e. performing repeated simulations of a circuit while varying one or more parameters. These simulations can be done in any order, as long as the computed results are saved in a well-defined sequence. Thus, multiple threads can be called upon to run the simulations concurrently.

In WRspice there are several ways to initiate this type of repeated analysis.

chained dc analysis
Most analysis specifications in WRspice can be followed by a dc sweep specification. In WRspice, a ``dc sweep'' is a one or two-dimensional sweep of any ciruit paramter, which is far more powerful than the original SPICE dc sweep which allowed only source outputs to be varied. In this ``chained dc'' analysis, the basic analysis is performed at each point in parameter space of the sweep. The result will be a family of multi-dimensional vectors, one dimension per parameter set. Multi-threading is supported in this type of analysis.

the sweep command
The sweep command is an interactive command that automatically sets one or two shell variables to points in a range, and initiates an arbitrary analysis at each point. At each point, a circuit object is created from the shell-expanded SPICE input, which will reflect the state of the shell variables. The specified analysis is then performed.

Unlike the chained dc analysis, the sweep can be run over any command, in particular a user's script. However, internally the command runs at the shell level and has a lot of overhead, so the chained dc analysis would be preferable for speed when possible. At present, the sweep command is not multi-threaded.

Monte-Carlo analysis
In Monte-Carlo analysis, repeated simulations are performed using a circuit object generated for each trial, where parameter values have been randomly generated according to a probability distribution. The simulation run is analyzed by pass/fail logic, and only this result is typically saved. At present, Monte Carlo analysis is not multi-threaded.

As mentioned, at present only the chained-dc analysis can be multi-threaded. This is accomplished by setting the loopthrds variable to a positive integer. This can be done in a .options line in the SPICE deck, or interactively from the command line using the set command, or graphically from the General page of the Simulation Options panel from the Tools menu.

Multiple threads will be used automatically in a chained dc analysis if:

  1. The loopthrds variable is set to an integer 1 or larger. This option variable indicates the number of ``helper'' threads to use. It can be set to an integer in the range 0 through 31, with 0 being the same as not set (single threading). The ``best'' value can be found experimentally, but the value plus the main thread probably equals twice the number of available CPU cores.

  2. The analysis specification supports multi-threading. Presently the following analyses can be multi-threaded:
    tran, without scrolling, segmenting, and with the nousertp mode not set.
    ac
    tf

Multi-threading in the sweep command and Monte Carlo analysis is not yet available, but will be provided (it is hoped) in a future release. These analyses require a rebuild of the circuit object for each trial, requiring that the entire input parser be thread safe. This is because shell variables are used to pass parameters, requiring a re-parse of the circuit deck to create a modified internal circuit representation. In chained dc analysis, the same circuit object is re-used multiple times.

The loopthrds and loadthrds can be used together. One should experiment to find the fastest settings.


next up previous contents index
Next: Program Control Up: Multi-threading Previous: Multi-Threaded Loading   Contents   Index
Stephen R. Whiteley 2022-09-18