I have a netlist which is about 160,000 lines. Performing op analysis works fine. However, performing alter followed by op hangs forever.
You can find the problematic file in the link below labelled cct_bad. I am filing this as a bug since the circuit simulated successfully without alter.
Tested on ngspice-44.2 on Arch linux.
https://drive.google.com/file/d/1dDRBlHPpdnja-a68Lm3KmhOoaq0l-yds/view?usp=sharing
This is what I get with cct_bad.sp (git branch pre-master-45, VS2022, Windows 10, i9 9900):
That's not too bad considering the huge netlist. With KLU solver it is even a bit faster.
Last edit: Holger Vogt 2025-04-29
Thanks, but can you test on the current stable version ?
ngspice-44.2
I have just tried to run this on both my pc (arch linux) running
ngspice 44.2and another (ubuntu) runningngspice 42. In both of them, it just hangs. Could this be a linux this ?Also, my version does not print the time (Device Setup finished after 42.166 seconds.) like yours.
"Bad" does take some time on my Debian system, and the process is not growing, so an infinite loop seems likely. I will try it in a debug build.
Looks like a corrupted node list contains a cycle, so infinite loop at src/spicelib/analysis/cktdltn.c:36.
Last edit: Giles Atkinson 2025-04-29
Profiling my execution says it stays in function CKTdltNNum in line 116 of vsrcset.c for 98% of the time after the first op and before the second op.
Last edit: Holger Vogt 2025-04-29
Yes. It is a linked list loop. I have a function that detects the loop and can find the cause by inserting it in the "alter" code. I can take this one, but not if you want to continue digging.
Edit: Valgrind shows nothing useful (no corruption).
Thanks for the Windows build fix for the other change. I foolishly thought it was too simple to need a test build.
G.
Last edit: Giles Atkinson 2025-04-29
Adding a 'reset' make things faster:
see
The vsrc unset function obviously does not comply with 81000 voltage sources.
It is not the 'alter' command, but simply two 'op' in series. The second 'op' requires a voltage source reset, which does not comply well with such a large number of voltage sources. 'reset' removes the circuit completely and reloads it internally from an intermediate stage where subcircuit expansion is done already. Thus it is relatively efficient.
I was getting a false positive in loop detection.
The code for partially resetting the circuit is very inefficient. CKTdltNNum() searches to the end of the list every time, even after a match was found! Performance might be improved by reversing the order of the node list, so that generated nodes that get removed here are at the front. But several things rely on the current order.