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.