Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qucsator crashes when noise analysis is enabled in S-parameters simulation #133

Closed
in3otd opened this issue Nov 27, 2014 · 4 comments
Closed

Comments

@in3otd
Copy link
Contributor

in3otd commented Nov 27, 2014

With this simple circuit qucsator segfaults (and qucs does not even realize that, see #132 ); when the noise analysis is disabled simulation works fine.

noisecrash

Schematic file is available at https://gist.github.com/in3otd/b90e9f9b658d4e1db290/download

Edit: works in 0.0.17 but not in 0.0.18 or later

@guitorri
Copy link
Member

I am getting this backtrace from the debugger:

~/git/qucs/qucs-core $ lldb -- /Users/guitorri/local/qucs-devel/bin/qucsator -i /Users/guitorri/qucs_area/netlist.txt 
(lldb) target create "/Users/guitorri/local/qucs-devel/bin/qucsator"
Current executable set to '/Users/guitorri/local/qucs-devel/bin/qucsator' (x86_64).
(lldb) settings set -- target.run-args  "-i" "/Users/guitorri/qucs_area/netlist.txt"
(lldb) r
Process 41644 launched: '/Users/guitorri/local/qucs-devel/bin/qucsator' (x86_64)
project location: 
modules to load: 0
factorycreate.size() is 0
factorycreate has registered:
parsing netlist...
checking netlist...
checker notice, variable `S' in equation `dB_S21' not yet defined
checker notice, variable `S' in equation `Rin' not yet defined
checker notice, variable `S' in equation `Xin' not yet defined
< clip >
NOTIFY: SP1: preparing circuit for analysis
NOTIFY: SP1: inserted 2 tees, 1 crosses, 0 opens and 4 grounds
NOTIFY: SP1: creating sorted nodelist for SP analysis
NOTIFY: SP1: solving SP netlist
Process 41622 stopped
* thread #1: tid = 0x45952, 0x000000010005dd9a libqucs.0.dylib`qucs::circuit::getMatrixS(this=0x0000000100c0df30) + 154 at circuit.cpp:658, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x100d00000)
    frame #0: 0x000000010005dd9a libqucs.0.dylib`qucs::circuit::getMatrixS(this=0x0000000100c0df30) + 154 at circuit.cpp:658
   655    matrix res (size);
   656    for(unsigned int i=0; i < size; ++i)
   657      for(unsigned int j=0; i < size; ++j)
-> 658        res(i,j) = MatrixS[i*size + j];
   659    return res;
   660  }
   661  
(lldb) bt
* thread #1: tid = 0x45bad, 0x000000010005dd9a libqucs.0.dylib`qucs::circuit::getMatrixS(this=0x0000000100c0df30) + 154 at circuit.cpp:658, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x100d00000)
  * frame #0: 0x000000010005dd9a libqucs.0.dylib`qucs::circuit::getMatrixS(this=0x0000000100c0df30) + 154 at circuit.cpp:658
    frame #1: 0x00000001001e48f1 libqucs.0.dylib`bjt::calcNoiseSP(this=0x0000000100c0df30, frequency=100000) + 97 at bjt.cpp:129
    frame #2: 0x000000010007ab3a libqucs.0.dylib`qucs::spsolver::calc(this=0x0000000100c082e0, freq=100000) + 122 at spsolver.cpp:453
    frame #3: 0x000000010007b0e7 libqucs.0.dylib`qucs::spsolver::solve(this=0x0000000100c082e0) + 727 at spsolver.cpp:607
    frame #4: 0x000000010006e9fd libqucs.0.dylib`qucs::net::runAnalysis(this=0x0000000100c08180, err=0x00007fff5fbff008) + 493 at net.cpp:267
    frame #5: 0x0000000100002b09 qucsator`main(argc=3, argv=0x00007fff5fbffa00) + 8089 at ucs.cpp:251
    frame #6: 0x00007fff86ee95fd libdyld.dylib`start + 1
(lldb) 

@guitorri
Copy link
Member

This is the offending commit: 379559d, see this line change.

By comparison other getters are also broken.

@guitorri guitorri added this to the 0.0.19 milestone Nov 27, 2014
guitorri added a commit to guitorri/qucs that referenced this issue Nov 28, 2014
Fix issue Qucs#133

The C memcpy was replaced by loops, but it causes the kernel to segfault
during SP analysis with Noise.

For memcpy is good with POD and tends to be inlined [1].
Replacement candidate is std:copy. Please provide testcase and
testbench.

[1] http://nadeausoftware.com/articles/2012/05/c_c_tip_how_copy_memory_quickly
guitorri added a commit to guitorri/qucs that referenced this issue Nov 28, 2014
Fix issue Qucs#133

The C memcpy was replaced by loops, but it causes the kernel to segfault
during SP analysis with Noise.

memcpy is good with POD and tends to be inlined [1].
Replacement candidate is std:copy. Please provide testcase and
testbench.

[1] http://nadeausoftware.com/articles/2012/05/c_c_tip_how_copy_memory_quickly
@guitorri
Copy link
Member

Funny, I totally missed that the inner loop condition is wrong...
If loop with indexes give similar performance [1], I would use for loops. just because it is more readable.
I fill push a fix in a minute.

[1] http://nadeausoftware.com/articles/2012/05/c_c_tip_how_copy_memory_quickly

guitorri added a commit that referenced this issue Nov 30, 2014
Inner loop condition was using the outer loop index.
@guitorri
Copy link
Member

Fix merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants