Segmentation fault (core dump)
This message is almost always annoying when writing C or C ++ This is one of the places where beginners can easily stumble because the cause of the error is not output directly to the terminal.
Lambda:11 Em:1.01 ARI:0
Lambda:11 Em:1.02 ARI:0.290903
Segmentation fault (Core dump)
A Segmentation fault (core dump)
occurs while executing Program for clustering (unsupervised machine learning) .. Suddenly the program stopped.
A tool called gdb
can help you find the cause.
https://ja.wikipedia.org/wiki/GNU%E3%83%87%E3%83%90%E3%83%83%E3%82%AC
The GNU Debugger (also just GDB) is a standard debugger that runs on GNU software systems. It is a highly portable debugger that works on many Unix-like systems and supports programming languages such as Ada, C, C ++, FORTRAN, and FreeBASIC.
gdb is a standard Unix CUI debugger. IDEs such as eclipse and Visual Studio have a GUI debugger as standard, but their purpose is similar to those.
First, compile with "-g" added to the compile option.
g++ [file name] -g -o
Core Dump features are disabled by default on many Linux distributions, so enable them.
ulimit -c unlimited
The meaning of this command is do not limit the size of the core to be generated
.
Run the program.
./a.out
...
(abridgement)
...
Lambda:11 Em:1.01 ARI:0
Lambda:11 Em:1.02 ARI:0.290903
Segmentation fault (Core dump)
If you look at the current directory here, you should see a file named "core". Let's debug this core with GDB.
gdb ./a.out core
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
[New LWP 10366]
Core was generated by `./a.out'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00005599dc02eccb in Hcm::set_crispMembership (this=0x7ffcf0375ea0) at hcm.cxx:159
159 CrispMembership[max_index][k]=1.0;
Here, the name of the function causing the problem is written at the bottom.
I want to take a closer look, so I'll backtrace.
(gdb) backtrace
#0 0x00005599dc02eccb in Hcm::set_crispMembership (this=0x7ffcf0375ea0) at hcm.cxx:159
#1 0x00005599dc03c300 in main () at qfcma_main_user_knowledge.cxx:112
I want to see the cause of the main function in detail, so specify # 1.
(gdb) frame 1
112 test.set_crispMembership();
Now you have identified the function that caused the core dump.
You can also view the code for the cause and local variables as needed. Please refer to the following article for details.
https://qiita.com/ShikiSumiya/items/a08363db88f21c81d351
The cause of this core dump was that NaN was generated due to the calculation limit of the double type variable, and an out-of-array reference occurred as a result of trying to refer to the NaN stored in the array.
Recommended Posts