problem:Segmentation fault (core dumped)

_Geant4 Version:_11.2.1
_Operating System:_Ubuntu24.04.1
Compiler/Version:
_CMake Version:_3.28.3

I copied the project that works successfully on the server to run on my own Ubuntu and got a Segmentation fault (core dumped) error.

I debugged using gdb and the result was the following picture

I’m a beginner so I didn’t figure out what the problem is, can someone please help me see where my code is wrong?
CT_detector_construction.hh (7.2 KB)
CT_detector_construction.cc (6.9 KB)


Recommend print statements in that Construct() function at various points to figure out when the failure occurs. You will be doing that a lot in Geant and C.

Can you run the basic examples on your machine such as B1? Nothing looks wrong offhand about this except that giant nested for loop of 360000 elements

for (G4int i=0; i<600; i++){
   for(G4int j=0; j<600; j++){

      sprintf(name_sol,"de_sol_%d_%d",i+1,j+1);
      sprintf(name_log,"de_log_%d_%d",i+1,j+1);
      sprintf(name_phy,"de_phy_%d_%d",i+1,j+1);

      de_box[i][j] = new G4Box(name_sol,0.06*mm,0.06*mm,0.1*mm);
      de_log [i][j] = new G4LogicalVolume(de_box[i][j],Vaccum,name_log,0,0,0);
      double length=72.*mm;
      double dd=0.12*mm;

      de_phys[i][j] = new G4PVPlacement(0, G4ThreeVector((-1.*length/2.+i*dd+dd/2.), (-1.*length/2.+j*dd+dd/2.), 0),
                                  de_log[i][j], name_phy, de_ba_log, false, j+i*600);

    }
 }

A big server could potentially handle this many elements placed on the heap but it could definitely cause memory issues on something smaller, like a personal laptop. First check with print statements that everything works before this. Then I recommend seeing if you still get failures if the for loop indices are, say 5 each, instead of 600.

If you want to place that many elements, you will want/have to use repeated volume methods. Offhand, parameterized volumes would work well here. Examples B2 and B4 would be good places to start. This will require modifying code elsewhere since probably the original code references elements with strings (which is slow) instead of with copy IDs from the methods I alluded to earlier (much faster).

1 Like

You are right. There are too many elements in my model. I have reduced to 100*100 and it successfully run. Thank you!
Best wishes for you!

There is no need to construct so many identical boxes. It’s sufficient to have one logical volume and use it for construction of all physical volumes.

Physical volumes may also have the same name, you can distinguish them by copy numbers.

Oh, thank you for your advice. I think it’s useful for me. Thanks again!

I tried your method and it worked. Now I have other problems, I get the following error when I run my project:

I re-downloaded G4NDL4.6 according to the online method and unzipped it in /geant4-v10.7.2-install/share/Geant/data, and I still get the same error when I re-run my project, do you have any idea how to fix it?

Duplicate of post in SaG4n error about netron data library - #2 by bmorgan