Standard debugging not giving more info than RuntimeError: OpenMC aborted unexpectedly

When running a recent simulation (see test_filters.py), I hit a a segfault and the error message RuntimeError: OpenMC aborted unexpectedly. I have OpenMC compiled in debug mode, using v0.13.3. I tried running my script with a python debugger and a breakpoint on the openmc.run() line + stepping through the python API calls, but it doesn’t print any extra info.

Basically what happens is that the simulation builds the XML (geometry.xml, materials.xml, and tallies.xml), finishes the last requested batch and prints the following

      100/1    0.55415    0.53825 +/- 0.00092
 Creating state point statepoint.100.h5...
Traceback (most recent call last):
  File "/home/lgross/gcmr/mwes/test_filters/test_filters.py", line 246, in <module>
    openmc.run()
  File "/home/lgross/openmc/openmc/executor.py", line 314, in run
    _run(args, output, cwd)
  File "/home/lgross/openmc/openmc/executor.py", line 125, in _run
    raise RuntimeError(error_msg)
RuntimeError: OpenMC aborted unexpectedly.

Some output files are produced (statepoint.100.h5, a blank tallies.out, and a summary.h5), but the timing statistics are not printed. I’m getting kind of stumped here. I could try a mixed python-C++ debugger to see what is going wrong on the C++ side of things. I can run other OpenMC simulations, so I’m pretty confident my build is good (plus all tests pass when I run pytest). Can anyone see any issues with my test_filters.py?

You can try to attach gdb to the existing openmc process. That is, once openmc.run() is called, get the process ID and then run gdb -p <pid>. That will allow you to get a proper backtrace to see where the problem is occurring.

1 Like

Thanks for the tip! I was able to attach to the simulation’s process ID, then click c for continue and witness the backtrace on gdb.

(gdb) c
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0x00007fb809ccab5f in openmc::distribcell_path_inner[abi:cxx11](int, int, int, openmc::Universe const&, int) (target_cell=2, 
    map=2, target_offset=0, search_univ=..., offset=0) at /home/lgross/openmc/src/geometry_aux.cpp:559
559         path << "l" << lat.id_;
(gdb) bt
#0  0x00007f4acf317b5f in openmc::distribcell_path_inner[abi:cxx11](int, int, int, openmc::Universe const&, int) (target_cell=2, 
    map=2, target_offset=0, search_univ=..., offset=0) at /home/lgross/openmc/src/geometry_aux.cpp:559
#1  0x00007f4acf317eef in openmc::distribcell_path[abi:cxx11](int, int, int) (target_cell=2, map=2, target_offset=0)
    at /home/lgross/openmc/src/geometry_aux.cpp:579
#2  0x00007f4acf4e2a0f in openmc::DistribcellFilter::text_label[abi:cxx11](int) const (this=0x5602c67846e0, bin=0)
    at /home/lgross/openmc/src/tallies/filter_distribcell.cpp:71
#3  0x00007f4acf3ed7f8 in openmc::write_tallies () at /home/lgross/openmc/src/output.cpp:724
#4  0x00007f4acf48575c in openmc_simulation_finalize () at /home/lgross/openmc/src/simulation.cpp:176
#5  0x00007f4acf4852ba in openmc_run () at /home/lgross/openmc/src/simulation.cpp:62
#6  0x00005602c4d2639d in main (argc=1, argv=0x7ffc12a8cab8) at /home/lgross/openmc/src/main.cpp:34

I looked at geometry_aux.cpp:559 and it appears this issue has to do with my use of universes and/or Tally filters. I have various tallies, some with DistribcellFilter and some with UniverseFilter. I’m not really sure about the pathology of this error, but for now I’ll try commenting out all the tallies and commenting them in one by one until I find which one causes the problem.

Made a more minimal example and GH Issue.

Some extra useful info is that the error goes away if I turn off the writing of tallies.out. The stack trace seems to agree since this happens during write_tallies().

My hunch is that I should be able to do what I’m asking OpenMC to do and that there’s some bug in the tally writing script. Though, it’s possible that I’m doing something ill-advised that we could check for earlier in the process and maybe even throw an error before the simulation starts to get the user to prevent this.