3 from AthenaCommon
import Logging
4 from ...decorators
import timed
5 from ...utility
import FileParser, ProcessManager, SingleProcessThread
6 from functools
import partial
11 logger = Logging.logging.getLogger(
"PowhegControl")
15 """! Run multiple Powheg processes, each in its own thread.
17 @param process PowhegBox process.
19 @author James Robinson <james.robinson@cern.ch>
22 logger.info(
"Running in multicore mode with {} subjobs".
format(process.cores))
23 with open(
"pwgseeds.dat",
"w")
as random_seed_list:
24 for idx
in range(process.cores):
25 random_seed_list.write(
str(process.random_seed +
int(idx * 1e6)) +
"\n")
28 FileParser(
"powheg.input").text_remove(
"^iseed")
29 logger.debug(
"Disabling iseed variable when multiple seeds are used")
32 generation_fn = partial(multicore_untimed, process)
34 if process.powheg_version ==
"V1":
36 elif process.powheg_version ==
"V2" or process.powheg_version ==
"RES":
39 raise ValueError(
"Powheg version {} is not supported for multicore running!".
format(process.powheg_version))
41 @
timed(
"multi-core generation (V1)")
43 """! Run Powheg V1 generation in multi-core mode.
45 @param generation_fn Function that can be called without argument to generate events.
47 @author James Robinson <james.robinson@cern.ch>
51 @
timed(
"multi-core generation (V2/RES)")
53 """! Run Powheg V2/RES generation in multi-core mode.
55 @param process PowhegBox process.
56 @param generation_fn Function that can be called without argument to generate events.
58 @author James Robinson <james.robinson@cern.ch>
60 shutil.rmtree(
"multistage_inputs", ignore_errors=
True)
61 os.mkdir(
"multistage_inputs")
62 shutil.copy(
"pwgseeds.dat",
"multistage_inputs/pwgseeds.dat")
64 if(process.executable !=
"pwhg_semileptonic" ):
65 if process.stage_is_completed(1):
66 logger.info(
"=> Skipping multi-core generation (V2/RES): stage 1 <=")
68 process.modify_parameter(stage = 1)
70 if process.stage_is_completed(2):
71 logger.info(
"=> Skipping multi-core generation (V2/RES): stage 2 <=")
73 process.modify_parameter(stage = 2)
75 if process.stage_is_completed(3):
76 logger.info(
"=> Skipping multi-core generation (V2/RES): stage 3 <=")
78 process.modify_parameter(stage = 3)
81 process.modify_parameter(stage = 3)
84 process.modify_parameter(stage = 4)
87 @
timed(
"multi-core generation (V2/RES): stage 1)")
89 """! Run Powheg V2/RES (stage 1) generation in multi-core mode.
91 @param generation_fn Function that can be called without argument to generate events.
92 @param n_xgrid_iterations Number of xgrid iterations to perform.
94 @author James Robinson <james.robinson@cern.ch>
96 FileParser(
"powheg.input").text_replace(
"parallelstage.*",
"parallelstage 1")
98 for xgrid_iteration
in range(1, n_xgrid_iterations + 1):
99 FileParser(
"powheg.input").text_replace(
"xgriditeration.*",
"xgriditeration {}".
format(xgrid_iteration))
100 shutil.copy(
"powheg.input",
"multistage_inputs/powheg.input.parallelstage{ps}.xgriditeration{xgi}".
format(ps=1, xgi=xgrid_iteration))
103 @
timed(
"multi-core generation (V2/RES): stage 2)")
105 """! Run Powheg V2/RES (stage 2) generation in multi-core mode.
107 @param generation_fn Function that can be called without argument to generate events.
109 @author James Robinson <james.robinson@cern.ch>
111 FileParser(
"powheg.input").text_replace(
"parallelstage.*",
"parallelstage 2")
112 shutil.copy(
"powheg.input",
"multistage_inputs/powheg.input.parallelstage{ps}".
format(ps=2))
115 @
timed(
"multi-core generation (V2/RES): stage 3)")
117 """! Run Powheg V2/RES (stage 3) generation in multi-core mode.
119 @param generation_fn Function that can be called without argument to generate events.
121 @author James Robinson <james.robinson@cern.ch>
123 FileParser(
"powheg.input").text_replace(
"parallelstage.*",
"parallelstage 3")
124 shutil.copy(
"powheg.input",
"multistage_inputs/powheg.input.parallelstage{ps}".
format(ps=3))
127 @
timed(
"multi-core generation (V2/RES): stage 4)")
129 """! Run Powheg V2/RES (stage 4) generation in multi-core mode.
131 @param generation_fn Function that can be called without argument to generate events.
133 @author James Robinson <james.robinson@cern.ch>
135 FileParser(
"powheg.input").text_replace(
"parallelstage.*",
"parallelstage 4")
136 shutil.copy(
"powheg.input",
"multistage_inputs/powheg.input.parallelstage{ps}".
format(ps=4))
137 generation_fn(parallel_stage=4)
140 """! Run multiple Powheg processes, each in its own thread.
142 @param process PowhegBox process.
144 @author James Robinson <james.robinson@cern.ch>
147 if not os.path.isfile(process.executable):
148 raise OSError(
"Powheg executable {} not found!".
format(process.executable))
151 threads = [SingleProcessThread(process.executable, seed_index=idx,
152 warning_output=(process.warning_output
if hasattr(process,
"warning_output")
else None),
153 info_output=(process.info_output
if hasattr(process,
"info_output")
else None),
154 error_output=(process.error_output
if hasattr(process,
"error_output")
else None))
for idx
in range(1, process.cores + 1)]
155 manager = ProcessManager(threads)
156 while manager.monitor():