Problem 2156 - GDML export shows Segmentation Fault in Multithreading, but runs fine in Sequential
Summary: GDML export shows Segmentation Fault in Multithreading, but runs fine in Sequ...
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: persistency/gdml (show other problems)
Version: 10.5
Hardware: PC Linux
: P4 major
Assignee: Gabriele Cosmo
URL:
Depends on:
Blocks:
 
Reported: 2019-03-29 18:32 CET by Sanchit Sharma
Modified: 2019-04-02 07:57 CEST (History)
0 users

See Also:


Attachments
Main file (2.61 KB, text/x-c++src)
2019-03-29 18:32 CET, Sanchit Sharma
Details

Note You need to log in before you can comment on or make changes to this problem.
Description Sanchit Sharma 2019-03-29 18:32:14 CET
Created attachment 558 [details]
Main file

Hello,

I have made a GDML file to export in Geant4. The code works fine when I
compile and run in Sequential mode of Geant4(compiled without
multithreading). But when I try to run this on Geant4 with
multithreading. It gives me a Segmentation Fault.

My Main file is attached along with this mail.

Thanks!
Comment 1 Gabriele Cosmo 2019-04-01 17:42:59 CEST
Thanks for reporting this. A protection has been now put to the internal Write() function of the GDML parser to prevent worker threads to execute writing and restrict this to only the master thread. The fix will be available in the next patch release.
Comment 2 Sanchit Sharma 2019-04-01 17:56:21 CEST
Respected Dr. Cosmo,

Greetings! I am not using the Write() function of the parser, but only Read().

My detector construction is below:

#include "DetectorConstruction.hh"
#include <G4LogicalVolume.hh>
#include <G4PVPlacement.hh>
#include <G4NistManager.hh>
#include <G4SystemOfUnits.hh>
#include <G4VisAttributes.hh>
#include <G4Box.hh>
#include <G4Tubs.hh>
#include <G4Orb.hh>
#include <G4SDManager.hh>
#include <G4RotationMatrix.hh>
#include <G4Transform3D.hh>
#include <G4SubtractionSolid.hh>
#include <G4Polyhedra.hh>
#include <G4Colour.hh>
#include <G4Material.hh>
#include <G4RunManager.hh>
#include <G4MultiFunctionalDetector.hh>
#include <G4PSEnergyDeposit.hh>
#include <G4SDManager.hh>
#include <G4SDParticleWithEnergyFilter.hh>
#include <G4PVParameterised.hh>
#include <G4LogicalVolume.hh>
#include <G4PVPlacement.hh>
#include <G4NistManager.hh>
#include <G4SystemOfUnits.hh>
#include <G4VisAttributes.hh>
#include <G4Box.hh>
#include <G4Orb.hh>
#include <G4SDManager.hh>
#include "G4GlobalMagFieldMessenger.hh"
#include "G4AutoDelete.hh"
#include "G4GeometryTolerance.hh"
#include "G4GeometryManager.hh"
#include "G4UnionSolid.hh"
#include "G4GDMLParser.hh"
#include "G4PSEnergyDeposit.hh"
#include <G4TessellatedSolid.hh>

#include "G4UserLimits.hh"

using namespace std;


G4VPhysicalVolume* DetectorConstruction::Construct() 
{
  G4String GDMLsolid;
  G4GDMLParser parser;
  parser.Read("/homes/sanchitsharma/Geant4/X-D-MSND/CAD_RUNS/source/src/475.gdml");
  G4VPhysicalVolume* world = parser.GetWorldVolume(); //world volume
  return world;
}
void DetectorConstruction::ConstructSDandField()
{ G4GDMLParser parser;
  parser.Read("/homes/sanchitsharma/Geant4/X-D-MSND/CAD_RUNS/source/src/475.gdml");
  G4SDManager* SDman = G4SDManager::GetSDMpointer();
  
  G4String fltName,particleName;
  // Sensitive Detector Name
  G4String phantomSDname = "BM";
  //------------------------
  // MultiFunctionalDetector
  //------------------------
  //
  // Define MultiFunctionalDetector with name.
  G4MultiFunctionalDetector* BM = new G4MultiFunctionalDetector(phantomSDname);
  SDman->AddNewDetector( BM );                // Register SD to SDManager.
  parser.GetVolume("fingdml")->SetSensitiveDetector(BM);    // Assign SD to the logical volume.
  G4String psName;
  G4PSEnergyDeposit * scorer0 = new G4PSEnergyDeposit(psName="eDep");
  G4SDParticleFilter* PFilter = new G4SDParticleFilter(fltName="PFilter");
  PFilter->add(particleName="triton");
  scorer0->SetFilter(PFilter);
  BM->RegisterPrimitive(scorer0);
}
Comment 3 Gabriele Cosmo 2019-04-02 07:57:28 CEST
Hi Sanchit, the title of this ticket explicitly refers to "GDML export"...
I have verified that "importing" (i.e. reading) GDML descriptions does not reproduce thread contention or crashes, as this operation should be only executed while defining the geometry in either your main() at the beginning, or inside your Construct() method, where everything is operated by the master thread.
The code you attached shows an issue though, i.e. you are repeating the GDML import within ConstructSDandField(). Why??  This may explain the crash.