adde threading locks in case it's needed downstream
This commit is contained in:
+11
-10
@@ -170,7 +170,8 @@ def run_batch(
|
||||
particleSpec: str,
|
||||
minEnergy_GeV: float,
|
||||
maxEnergy_GeV: float = -1.0,
|
||||
filename: str = ""):
|
||||
filename: str = "",
|
||||
threading_lock = None):
|
||||
'''
|
||||
splits the batch in jobs depending on how many cores are available and runs mini batches in parallel
|
||||
'''
|
||||
@@ -188,15 +189,15 @@ def run_batch(
|
||||
|
||||
nevents = [nEventsPerCore if i < nCores - 1 else nEventsLastCore for i in range(nCores)]
|
||||
|
||||
#the used seeds are stored in the home directory in a file called .seeds.txt
|
||||
# check if file exists, if so, read last seed. If not create it
|
||||
if os.path.exists(os.path.expanduser("~/.g4calo_seeds.txt")):
|
||||
with open(os.path.expanduser("~/.g4calo_seeds.txt"), "r") as f:
|
||||
seed = int(f.read())
|
||||
else:
|
||||
seed = 0
|
||||
with open(os.path.expanduser("~/.g4calo_seeds.txt"), "w") as f:
|
||||
f.write(str(seed + nCores))
|
||||
with threading_lock if threading_lock is not None else contextlib.nullcontext():
|
||||
# check if file exists, if so, read last seed. If not create it
|
||||
if os.path.exists(os.path.expanduser("~/.g4calo_seeds.txt")):
|
||||
with open(os.path.expanduser("~/.g4calo_seeds.txt"), "r") as f:
|
||||
seed = int(f.read())
|
||||
else:
|
||||
seed = 0
|
||||
with open(os.path.expanduser("~/.g4calo_seeds.txt"), "w") as f:
|
||||
f.write(str(seed + nCores))
|
||||
|
||||
seed += 1
|
||||
print(f"Batch seed: {seed}")
|
||||
|
||||
Reference in New Issue
Block a user