Skip to content

Commit abc1b11

Browse files
Add --ncores flag to specify the nb of cores used to parallelize evolution
1 parent ee92787 commit abc1b11

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

n3fit/src/evolven3fit/cli.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def cli_evolven3fit(
5-
configuration_folder, q_fin, q_points, op_card_info, theory_card_info, force, load, dump
5+
configuration_folder, q_fin, q_points, op_card_info, theory_card_info, force, load, dump, ncores
66
):
77
"""Evolves the fitted PDFs.
88
@@ -23,5 +23,13 @@ def cli_evolven3fit(
2323
"""
2424
utils.check_is_a_fit(configuration_folder)
2525
return evolve.evolve_fit(
26-
configuration_folder, q_fin, q_points, op_card_info, theory_card_info, force, load, dump
26+
configuration_folder,
27+
q_fin,
28+
q_points,
29+
op_card_info,
30+
theory_card_info,
31+
force,
32+
load,
33+
dump,
34+
ncores,
2735
)

n3fit/src/evolven3fit/evolve.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from collections import defaultdict
22
import json
33
import logging
4-
import multiprocessing
54
import pathlib
65
import sys
76

87
from ekobox import apply, genpdf, info_file
98
from joblib import Parallel, delayed
109
import numpy as np
10+
import psutil
1111

1212
import eko
1313
from eko import basis_rotation, runner
@@ -24,11 +24,19 @@
2424
"level": logging.DEBUG,
2525
}
2626

27-
NUM_CORES = multiprocessing.cpu_count()
27+
NUM_CORES = psutil.cpu_count(logical=False)
2828

2929

3030
def evolve_fit(
31-
fit_folder, q_fin, q_points, op_card_dict, theory_card_dict, force, eko_path, dump_eko=None
31+
fit_folder,
32+
q_fin,
33+
q_points,
34+
op_card_dict,
35+
theory_card_dict,
36+
force,
37+
eko_path,
38+
dump_eko=None,
39+
ncores=1,
3240
):
3341
"""
3442
Evolves all the fitted replica in fit_folder/nnfit
@@ -125,7 +133,9 @@ def _wrap_evolve(pdf, replica):
125133
evolved_blocks = evolve_exportgrid(pdf, eko_op, x_grid)
126134
dump_evolved_replica(evolved_blocks, usr_path, int(replica.removeprefix("replica_")))
127135

128-
Parallel(n_jobs=NUM_CORES)(
136+
# Choose the number of cores to be the Minimal value
137+
nb_cores = min(NUM_CORES, ncores)
138+
Parallel(n_jobs=nb_cores)(
129139
delayed(_wrap_evolve)(pdf, r) for r, pdf in initial_PDFs_dict.items()
130140
)
131141

n3fit/src/n3fit/scripts/evolven3fit.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import pathlib
88
import sys
99

10-
from evolven3fit import cli, eko_utils, evolve, utils
1110
import numpy as np
1211

1312
from eko.runner.managed import solve
13+
from evolven3fit import cli, eko_utils, evolve, utils
1414
from n3fit.io.writer import XGRID
1515
from validphys.loader import FallbackLoader, Loader
1616

@@ -82,6 +82,13 @@ def construct_evolven3fit_parser(subparsers):
8282
parser.add_argument(
8383
"-d", "--dump", type=pathlib.Path, default=None, help="Path where the EKO is dumped"
8484
)
85+
parser.add_argument(
86+
"-n",
87+
"--ncores",
88+
type=int,
89+
default=1,
90+
help="Specify the number of cores to parallelize evolution",
91+
)
8592
parser.add_argument(
8693
"-f",
8794
"--force",
@@ -169,6 +176,7 @@ def main():
169176
args.force,
170177
eko_path,
171178
None,
179+
args.ncores,
172180
)
173181
else:
174182
# If we are in the business of producing an eko, do some checks before starting:

0 commit comments

Comments
 (0)