Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* cmake preset and env script for building celeritas on Zeus
* vecgeom and geant4 version used by AtlasExternals
* check geant4 version
* include G4Version.hh
* if guards for G4Backtrace
* make sure that we use gcc11.2, removed duplicate cmake preset
* use if preprocess directives as if constexpr still checks that the expression is valid
* fix compatibility issue with geant4 10.6 api
  • Loading branch information
esseivaju authored and sethrj committed Feb 24, 2023
1 parent 11274e6 commit a9fa8a2
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 18 deletions.
15 changes: 9 additions & 6 deletions app/demo-geant-integration/HitRootIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "corecel/Macros.hh"
#include "corecel/io/Logger.hh"
#include "celeritas/ext/GeantSetup.hh"
#include "accel/ExceptionConverter.hh"
#include "accel/SetupOptions.hh"

Expand Down Expand Up @@ -112,10 +113,11 @@ void HitRootIO::WriteObject(HitRootEvent* hit_event)
{
if (!event_branch_)
{
event_branch_ =tree_->Branch("event.",
&hit_event,
GlobalSetup::Instance()->GetRootBufferSize(),
this->SplitLevel());
event_branch_
= tree_->Branch("event.",
&hit_event,
GlobalSetup::Instance()->GetRootBufferSize(),
this->SplitLevel());
}
else
{
Expand Down Expand Up @@ -170,13 +172,14 @@ void HitRootIO::Close()
*/
void HitRootIO::Merge()
{
auto nthreads = G4RunManager::GetRunManager()->GetNumberOfThreads();
auto const nthreads
= celeritas::get_num_threads(*G4RunManager::GetRunManager());
std::vector<TFile*> files;
std::vector<TTree*> trees;
std::unique_ptr<TList> list(new TList);

CELER_LOG_LOCAL(info) << "Merging hit root files from " << nthreads
<< " threads into \"" << file_name_ << "\"";
<< " threads into \"" << file_name_ << "\"";

for (int i = 0; i < nthreads; ++i)
{
Expand Down
15 changes: 5 additions & 10 deletions app/demo-geant-integration/demo-geant-integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,13 @@ void run(std::string const& macro_filename)
CLHEP::HepRandom::setTheSeed(0xcf39c1fa9a6e29bcul);

std::unique_ptr<G4RunManager> run_manager;
#if CELERITAS_G4_V10
if (CELERITAS_G4_MT)
{
run_manager = std::make_unique<G4MTRunManager>();
}
else
{
run_manager = std::make_unique<G4RunManager>();
}
#else
#if !CELERITAS_G4_V10
run_manager.reset(G4RunManagerFactory::CreateRunManager(
CELERITAS_G4_MT ? G4RunManagerType::MT : G4RunManagerType::Serial));
#elif CELERITAS_G4_MT
run_manager = std::make_unique<G4MTRunManager>();
#else
run_manager = std::make_unique<G4RunManager>();
#endif
CELER_ASSERT(run_manager);
celeritas::self_logger() = celeritas::make_mt_logger(*run_manager);
Expand Down
93 changes: 93 additions & 0 deletions scripts/cmake-presets/zeus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"version": 3,
"cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0},
"configurePresets": [
{
"name": ".base",
"hidden": true,
"inherits": ["full"],
"binaryDir": "${sourceDir}/build-${presetName}",
"generator": "Ninja",
"cacheVariables": {
"BUILD_SHARED_LIBS": {"type": "BOOL", "value": "ON"},
"CELERITAS_BUILD_DOCS": {"type": "BOOL", "value": "OFF"},
"CELERITAS_USE_OpenMP": {"type": "BOOL", "value": "ON"},
"CELERITAS_USE_Geant4": {"type": "BOOL", "value": "ON"},
"CELERITAS_USE_HepMC3": {"type": "BOOL", "value": "ON"},
"CELERITAS_USE_CUDA": {"type": "BOOL", "value": "ON"},
"CELERITAS_USE_HIP": {"type": "BOOL", "value": "OFF"},
"CELERITAS_USE_JSON": {"type": "BOOL", "value": "ON"},
"CELERITAS_USE_MPI": {"type": "BOOL", "value": "OFF"},
"CELERITAS_USE_ROOT": {"type": "BOOL", "value": "ON"},
"CELERITAS_USE_SWIG": {"type": "BOOL", "value": "OFF"},
"CELERITAS_USE_VecGeom": {"type": "BOOL", "value": "ON"},
"CMAKE_CXX_FLAGS": "-Wall -Wextra -Wno-psabi -pedantic -pedantic-errors",
"CMAKE_CUDA_FLAGS": "-Xcompiler -Wno-psabi",
"CMAKE_CUDA_ARCHITECTURES": {"type": "STRING", "value": "80"},
"CMAKE_CXX_STANDARD": {"type": "STRING", "value": "17"},
"CMAKE_CXX_EXTENSIONS": {"type": "BOOL", "value": "OFF"},
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install-${presetName}",
"CMAKE_PREFIX_PATH": "/bld3/build/celeritas/geant4/geant4-v10.6.0-install/lib64;/bld3/build/celeritas/VecGeom/install-v1.1.20/lib64/cmake;/cvmfs/atlas-nightlies.cern.ch/repo/sw/master_Athena_x86_64-centos7-gcc11-opt/2023-02-13T2101/AthenaExternals/23.0.17/InstallArea/x86_64-centos7-gcc11-opt/lib/cmake;/cvmfs/sft.cern.ch/lcg/views/LCG_102b_ATLAS_11/x86_64-centos7-gcc11-opt/lib64/cmake;/cvmfs/sft.cern.ch/lcg/views/LCG_102b_ATLAS_11/x86_64-centos7-gcc11-opt/cmake",
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_CXX_FLAGS_RELEASE": "-O3 -DNDEBUG -march=cascadelake -mtune=cascadelake",
"CMAKE_EXPORT_COMPILE_COMMANDS": {"type": "BOOL", "value": "ON"}
}
},
{
"name": "base",
"displayName": "Zeus default options (GCC, debug)",
"inherits": [".base"],
"binaryDir": "${sourceDir}/build"
},
{
"name": "reldeb-novg",
"displayName": "Zeus release mode",
"inherits": [".reldeb", ".base"],
"cacheVariables": {
"CELERITAS_USE_VecGeom": {"type": "BOOL", "value": "OFF"}
}
},
{
"name": "reldeb",
"displayName": "Zeus release mode",
"inherits": [".reldeb", ".base"]
},
{
"name": "ndebug-novg",
"displayName": "Zeus release mode",
"inherits": [".ndebug", ".base"],
"cacheVariables": {
"CELERITAS_USE_VecGeom": {"type": "BOOL", "value": "OFF"}
}
},
{
"name": "ndebug",
"displayName": "Zeus release mode",
"inherits": [".ndebug", ".base"]
}
],
"buildPresets": [
{
"name": "base",
"configurePreset": "base",
"jobs": 8,
"nativeToolOptions": ["-k0"]
},
{"name": "ndebug", "configurePreset": "ndebug", "inherits": "base"},
{"name": "ndebug-novg", "configurePreset": "ndebug-novg", "inherits": "base"},
{"name": "reldeb", "configurePreset": "reldeb", "inherits": "base"},
{"name": "reldeb-novg", "configurePreset": "reldeb-novg", "inherits": "base"}
],
"testPresets": [
{
"name": "base",
"configurePreset": "base",
"output": {"outputOnFailure": true},
"execution": {"noTestsAction": "error", "stopOnFailure": false, "jobs": 8}
},
{"name": "ndebug", "configurePreset": "ndebug", "inherits": "base"},
{"name": "ndebug-novg", "configurePreset": "ndebug-novg", "inherits": "base"},
{"name": "reldeb", "configurePreset": "reldeb", "inherits": "base"},
{"name": "reldeb-novg", "configurePreset": "reldeb-novg", "inherits": "base"}
]
}
13 changes: 13 additions & 0 deletions scripts/env/zeus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh -e

export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase
# we need to clear exit on unchecked error for atlasLocalSetup...
set +e
source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh
lsetup "views LCG_102b_ATLAS_11 x86_64-centos7-gcc11-opt"
asetup none,gcc112,cmakesetup,siteroot=cvmfs
set -e

# not in standard Atlas build env but we need it for cuda-enabled vecgeom
module load cuda/11.8.0
source /bld3/build/celeritas/geant4/geant4-v10.6.0-install/bin/geant4.sh
7 changes: 6 additions & 1 deletion src/accel/Logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
#include <string>
#include <G4RunManager.hh>
#include <G4Threading.hh>
#include <G4Version.hh>
#include <G4ios.hh>

#if G4VERSION_NUMBER < 1070
# include <celeritas/ext/GeantSetup.hh>
#endif
#include "corecel/Assert.hh"
#include "corecel/io/ColorUtils.hh"
#include "corecel/io/Logger.hh"
#include "corecel/io/LoggerTypes.hh"
#include "corecel/sys/MpiCommunicator.hh"
#include "celeritas/ext/GeantSetup.hh"

namespace celeritas
{
Expand Down Expand Up @@ -110,7 +115,7 @@ void MtLogger::operator()(Provenance prov, LogLevel lev, std::string msg)
Logger make_mt_logger(G4RunManager const& runman)
{
return Logger(MpiCommunicator{},
MtLogger{runman.GetNumberOfThreads()},
MtLogger{get_num_threads(runman)},
"CELER_LOG_LOCAL");
}

Expand Down
28 changes: 27 additions & 1 deletion src/celeritas/ext/GeantSetup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

#include <memory>
#include <utility>
#include <G4Version.hh>
#if G4VERSION_NUMBER < 1070
# include <G4MTRunManager.hh>
#endif

#include <G4ParticleTable.hh>
#include <G4RunManager.hh>
#include <G4VPhysicalVolume.hh>
#include <G4VUserDetectorConstruction.hh>

Expand Down Expand Up @@ -61,6 +65,28 @@ class DetectorConstruction : public G4VUserDetectorConstruction
//---------------------------------------------------------------------------//
} // namespace

//---------------------------------------------------------------------------//
/*!
* Get the number of threads in a version-portable way.
*
* G4RunManager::GetNumberOfThreads isn't virtual before Geant4 v10.7.0 so we
* need to explicitely try dynamic cast to G4MTRunManager to get the number of
* threads.
*/
int get_num_threads(G4RunManager const& runman)
{
#if G4VERSION_NUMBER >= 1070
return runman.GetNumberOfThreads();
#else
if (auto const* runman_mt = dynamic_cast<G4MTRunManager const*>(&runman))
{
return runman_mt->GetNumberOfThreads();
}
// Not multithreaded
return 1;
#endif
}

//---------------------------------------------------------------------------//
/*!
* Construct from a GDML file and physics options.
Expand Down
12 changes: 12 additions & 0 deletions src/celeritas/ext/GeantSetup.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class G4RunManager;

namespace celeritas
{

//---------------------------------------------------------------------------//
/*!
* Construct a Geant 4 run manager and populate internal Geant4 physics.
Expand Down Expand Up @@ -72,6 +73,12 @@ class GeantSetup
G4VPhysicalVolume const* world_{nullptr};
};

//---------------------------------------------------------------------------//
// FREE FUNCTIONS
//---------------------------------------------------------------------------//
// Get the number of threads in a version-portable way
int get_num_threads(G4RunManager const&);

//---------------------------------------------------------------------------//
// INLINE DEFINITIONS
//---------------------------------------------------------------------------//
Expand All @@ -96,6 +103,11 @@ inline void GeantSetup::RMDeleter::operator()(G4RunManager*) const
{
CELER_ASSERT_UNREACHABLE();
}

inline int get_num_threads(G4RunManager const&)
{
CELER_ASSERT_UNREACHABLE();
}
#endif

//---------------------------------------------------------------------------//
Expand Down
3 changes: 3 additions & 0 deletions src/celeritas/ext/detail/GeantGeoExporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <G4GDMLParser.hh>
#include <G4Threading.hh>
#include <G4VPhysicalVolume.hh>
#include <G4Version.hh>

#include "corecel/Assert.hh"
#include "corecel/io/Logger.hh"
Expand Down Expand Up @@ -57,7 +58,9 @@ void GeantGeoExporter::operator()(std::string const& filename) const
parser.SetEnergyCutsExport(true);
parser.SetSDExport(true);
parser.SetOverlapCheck(true);
#if G4VERSION_NUMBER >= 1070
parser.SetOutputFileOverwrite(true);
#endif
constexpr bool append_pointers = true;
parser.Write(filename, world_, append_pointers);
}
Expand Down
Loading

0 comments on commit a9fa8a2

Please sign in to comment.