Segmentation fault when running custom pair potential

Hi,

I wrote my custom granular pair potential and have tested it on relatively small systems such as the compression of 6 and 13 granules. However when I scale it up to 100+ granules, I get a segmentation fault after 2 timesteps with the following backtrace:

Does anyone have experience encountering an error thrown by std::locale::~locale() or know why it might happen?

You need to compile with debug info included, so you can better pinpoint which line of code the failure happens. The locale error is likely a consequence of some output statement that you included in your code. The reason is likely that you are indexing an array with an invalid index and then the translation to your locale failed.

When doing program development it is usually much better to work in the “C” locale and avoid any issues with native language processing. This is easily done by using the shell command: export LC_ALL=C

Thanks Dr Axel, I wasn’t aware of the debug info. Thanks for that tip! After running gdb with the -g flag in the makefile, I encountered an error at a line where i write data to a file (using std::fstream ). I got rid of all the commands pertaining to writing to the file but now it seems to jump to a fault at verlet.cpp :disappointed:


I will have to investigate this more (like if the array goes out of bounds) but I am really surprised the smaller granular systems still give meaningful results.

I am not. For small systems, an array index cannot be far off. Allocation is usually in pages, so only when you have larger systems with more particles, you will require more allocations and then out-of-bounds accesses will point to unallocated memory addresses and cause a segfault.

Please note that the “this” pointer in the Verlet run call is “null”. This is often an indication of problems with the virtual function tables which means there are some very fundamental mistakes or you are accessing a class after it has been deleted.