next up previous contents index
Next: Initialization Files Up: The WRspice User Interface Previous: WRspice Environment Variables   Contents   Index

Sparse Matrix Package

The core of a SPICE simulator is the set of functions that set up, factor, and solve the circuit equations. The circuit equations form a matrix, whose elements, for most circuits, are mostly zero. This type of matrix is deemed ``sparse''. The speed with which the matrix can be filled, factored, and solved has a major impact on simulation speed.

Historically, WRspice has used a derivative of the venerable Sparse package written by Ken Kundert at Berkeley for sparse matrix processing. The package has been modified for improved performance, specifically by sorting the matrix elements into an order which maximizes memory locality and minimizes page-swapping and cache misses. The original C-language package was also translated into a set of C++ classes, improving maintainability and easing the integration of enhancements.

Although the Sparse package provides solid performance, newer algorithms have become available in recent years which, in some or most cases, provide better performance. The KLU package, written by Tim Davis at the University of Florida, is one such example. This package is distributed under a GNU license, which prevents direct incorporation into a proprietary commercial application such as WRspice, however commercial applications may use the package as a shared library.

WRspice distributions provide KLU in the form of a ``plug-in''. A plug-in is a shared library that is loaded directly by the application at run-time, rather than relying on the system loader. By using the plug-in, the application can still run properly whether or not the plug-in is available. If loading was performed by the system as for a normal shared library, WRspice would not run unless the plug-in is accessible.

The KLU plug-in is installed in the startup directory in the WRspice installation area. Thus, for normal installations, it should always be accessible. By default, WRspice will load and use KLU for spares matrix processing, overriding the Sparse package. However, it is possible to direct WRspice to use Sparse rather than KLU if desired.

For large post-extraction mixed-mode CMOS circuits used for benchmarking, the KLU package provides a 2-3 times improvement in simulation speed over Sparse. These circuits contain hundreds of transistors, and thousands of resistors and capacitors. For less complex circuits, the speed advantage may be smaller, and in some cases KLU may actually be slower. KLU was observed to be slower in rather simple circuits containing Josephson junctions. Users are encouraged to use the rusage command and determine which package provides the best performance on their circuits.

The following option variables control the sparse matrix handling. The first two can be set from the General page of the Simulation Options tool. The useadjoint variable can be set from the Devices page of the Simulation Options tool. The Simulation Options tool is obtained from the Sim Opts button in the Tools menu of the WRspice Tool Control Window. The variables can also be set with the set command, or in a .options line in SPICE input.

When this boolean variable is set, KLU will not be used for sparse matrix calculations. Otherwise, if the KLU plug-in is available, KLU will be used by default. The KLU plug-in is provided with all WRspice distributions, and is installed in the startup directory.

When using Sparse (i.e., KLU is unavailable or disabled), this boolean variable when set will prevent using element sorting to improve speed. This corresponds to the legacy WRspice sparse code. It may be interesting for comparison purposes, but setting this variable will slow simulation of most circuits. This variable has no effect if KLU is being used.

Most of the BSIM device models in WRspice have added code that builds an adjoint matrix which is used to accurately compute device currents. The computed currents are not used in the device models, but are available as simulation outputs. This has a small performance overhead so is not enabled by default, but will be enabled by setting this variable. Without this it may not be possible to obtain device currents during the simulation, using the device[param] ``pseudo-vector''. This applies whether KLU or Sparse is used for matrix operations.

next up previous contents index
Next: Initialization Files Up: The WRspice User Interface Previous: WRspice Environment Variables   Contents   Index
Stephen R. Whiteley 2022-09-18