Skip to content

Commit

Permalink
Cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
peremato committed Dec 4, 2024
1 parent b5fef1f commit c2414d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 5 additions & 8 deletions advanced/EmbedJulia/G4example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ int main(int, char**)
int nthreads = 0; // Default number of threads
if (getenv("G4NUMTHREADS")) nthreads = atoi(getenv("G4NUMTHREADS"));

//--- Required to setup the Julia context
//--- Required to setup the Julia context------------------------------------------------------
jl_init();
/* run Julia commands */
jl_eval_string("include(\"MyCode.jl\")");
if (jl_exception_occurred()) {
std::cout << "=====> " << jl_typeof_str(jl_exception_occurred()) << std::endl;
}

//---Construct the default run manager
//---Construct the default run manager (taking into account the number of threads)-------------
G4RunManager* runManager;
if (nthreads > 0) {
runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::MT);
Expand All @@ -171,10 +171,7 @@ int main(int, char**)
runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial);
}

//---Set mandatory initialization classes



//---Set mandatory initialization classes------------------------------------------------------
// Detector construction
runManager->SetUserInitialization(new DetectorConstruction());

Expand All @@ -197,12 +194,12 @@ int main(int, char**)
UImanager->ApplyCommand("/gun/energy 100 MeV");

// Start a run (we need to enter GC safe region here because the worker threads
// will enter a wait state waiting for workers to finish and can block GC
// will enter a wait state while waiting for workers to finish and this can block GC
auto state = jl_gc_safe_enter(jl_current_task->ptls);
runManager->BeamOn(100000);
jl_gc_safe_leave(jl_current_task->ptls, state);

// Job termination
// Job termination---------------------------------------------------------------------------
delete runManager;

// strongly recommended: notify Julia that the program is about to terminate.
Expand Down
7 changes: 4 additions & 3 deletions advanced/EmbedJulia/MyCode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using Parameters
println("=====> Loading MyCode.jl")

#---Simulation data struct-------------------------------------------------------------------------
# define a mutable struct to store the simulation data (counters, hitograms, etc.)
# make N+1 instances of this struct, where N is the number of threads
@with_kw mutable struct MyData
edep = 0.0
edepHist = H1D("Event total Edep distribution", 100, 0., 110.)
Expand Down Expand Up @@ -46,12 +48,11 @@ function begin_of_run_action(run)
end

function end_of_run_action(run)
if G4Threading!G4GetThreadId() < 0
if G4Threading!G4GetThreadId() < 0 # only for the master thread
println("=====> End of run")
data = simdata[1]
##---This is the master thread, so we need to add all the simulation results-----------------
for d in simdata[2:end]
add!(data, d)
add!(data, d) # merge all thread data to the master data
end
h = data.edepHist
img = plot(h.hist, title=h.title)
Expand Down

0 comments on commit c2414d3

Please sign in to comment.