# Segmentation fault occurs when a compiled source is used for fixed source calculations

**URL:** <https://openmc.discourse.group/t/segmentation-fault-occurs-when-a-compiled-source-is-used-for-fixed-source-calculations/5272>\
**Category:** User Support\
**Created:** [February 26, 2025, 7:09am UTC](https://openmc.discourse.group/t/segmentation-fault-occurs-when-a-compiled-source-is-used-for-fixed-source-calculations/5272 "2025-02-26T07:09:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsy](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@jsy](https://openmc.discourse.group/u/jsy)\
**Post date:** [February 26, 2025, 7:09am UTC](https://openmc.discourse.group/t/segmentation-fault-occurs-when-a-compiled-source-is-used-for-fixed-source-calculations/5272/1 "2025-02-26T07:09:42Z")

</div>

Hi everyone,

I designed a complex source area for fixed source calculation, but a Segmentation fault occurred when I used openmc for calculation. I thought there was a problem with the source area, so I switched to the simplest point source, but the problem persisted.

> Copyright | 2011-2024 MIT, UChicago Argonne LLC, and contributors  
> License | [License Agreement — OpenMC Documentation](https://docs.openmc.org/en/latest/license.html)  
> Version | 0.15.0  
> Git SHA1 | 84fb85977f46e162fea8f5a20ea653a3ec62ac24  
> Date/Time | 2025-02-26 14:30:12  
> MPI Processes | 1  
> OpenMP Threads | 128  
> Reading model XML file ‘model.xml’ …  
> Reading cross sections XML file…  
> Reading U234 from /dat3/endfb80\_hdf5/U234.h5  
> Reading U from /dat3/endfb80\_hdf5/photon/U.h5  
> Reading U235 from /dat3/endfb80\_hdf5/U235.h5  
> Reading U238 from /dat3/endfb80\_hdf5/U238.h5  
> Reading U236 from /dat3/endfb80\_hdf5/U236.h5  
> Reading O16 from /dat3/endfb80\_hdf5/O16.h5  
> Reading O from /dat3/endfb80\_hdf5/photon/O.h5  
> Reading O17 from /dat3/endfb80\_hdf5/O17.h5  
> Reading O18 from /dat3/endfb80\_hdf5/O18.h5  
> Reading Zr90 from /dat3/endfb80\_hdf5/Zr90.h5  
> Reading Zr from /dat3/endfb80\_hdf5/photon/Zr.h5  
> Reading Zr91 from /dat3/endfb80\_hdf5/Zr91.h5  
> Reading Zr92 from /dat3/endfb80\_hdf5/Zr92.h5  
> Reading Zr94 from /dat3/endfb80\_hdf5/Zr94.h5  
> Reading Zr96 from /dat3/endfb80\_hdf5/Zr96.h5  
> WARNING: Negative value(s) found on probability table for nuclide Zr96 at 294K  
> Reading H1 from /dat3/endfb80\_hdf5/H1.h5  
> Reading H from /dat3/endfb80\_hdf5/photon/H.h5  
> Reading H2 from /dat3/endfb80\_hdf5/H2.h5  
> Reading c\_H\_in\_H2O from /dat3/endfb80\_hdf5/c\_H\_in\_H2O.h5  
> Minimum neutron data temperature: 294 K  
> Maximum neutron data temperature: 294 K  
> Preparing distributed cell instances…  
> Writing summary.h5 file…  
> Maximum neutron transport energy: 20000000 eV for O17  
> ===============\> FIXED SOURCE TRANSPORT SIMULATION \<===============  
> Simulating batch 1  
> [ps-Super-Server:39836:0:40076] Caught signal 11 (Segmentation fault: Sent by the kernel at address (nil))  
> [ps-Super-Server:39836] \*\*\* Process received signal \*\*\*  
> [ps-Super-Server:39836] Signal: Segmentation fault (11)  
> [ps-Super-Server:39836] Signal code: Address not mapped (1)  
> [ps-Super-Server:39836] Failing at address: (nil)  
> [ps-Super-Server:39836] [0] /lib64/libc.so.6(+0x4adc0)[0x7fbb0c9ebdc0]  
> [ps-Super-Server:39836] [1] /dat3/jiashy/miniconda3/envs/openmc-env/bin/…/lib/libopenmc.so(\_ZN6openmc22sample\_external\_sourceEPm+0x47)[0x7fbb0d1004c7]  
> [ps-Super-Server:39836] [2] /dat3/jiashy/miniconda3/envs/openmc-env/bin/…/lib/libopenmc.so(\_ZN6openmc18initialize\_historyERNS\_8ParticleEl+0x3df)[0x7fbb0d0fcc0f]  
> [ps-Super-Server:39836] [3] /dat3/jiashy/miniconda3/envs/openmc-env/bin/…/lib/libopenmc.so(+0x1b75aa)[0x7fbb0d0fd5aa]  
> [ps-Super-Server:39836] [4] /dat3/jiashy/miniconda3/envs/openmc-env/bin/…/lib/./libgomp.so.1(+0x18f09)[0x7fbb0bd2ff09]  
> [ps-Super-Server:39836] [5] /lib64/libpthread.so.0(+0xa6ea)[0x7fbb0bbb16ea]  
> [ps-Super-Server:39836] [6] /lib64/libc.so.6(clone+0x41)[0x7fbb0cab958f]  
> [ps-Super-Server:39836] \*\*\* End of error message \*\*\*~~~

Here is my source definition and model:

```c++
#include <memory> // for unique_ptr
#include "openmc/random_lcg.h"
#include "openmc/source.h"
#include "openmc/particle.h"
class CompiledSource : public openmc::Source{
   openmc::SourceSite sample(uint64_t* seed) const{
       openmc::SourceSite particle;
       particle.particle = openmc::ParticleType::photon;
       particle.r.x = 0.0;
       particle.r.y = 0.0;
       particle.r.z = 0.0;
       particle.u = openmc::Isotropic().sample(seed);
       particle.E = 5.0e6;
       particle.wgt = 1.0;
       particle.delayed_group = 0;
       return particle;
   };
};
extern "C" std::unique_ptr<openmc::Source>
openmc_create_source(int source_type, void* params)
{
   return std::make_unique<CompiledSource>();
}

```

I would appreciate it if anyone could help me!  
[model.py](https://openmc.discourse.group/uploads/short-url/pnXzWeczbODQY9iCeCTLPO1Da5y.py) (2.5 KB)
