|
11 | 11 | from optparse import OptionParser, OptionGroup, OptionValueError |
12 | 12 | from decimal import Decimal, InvalidOperation |
13 | 13 | from datetime import datetime |
14 | | - |
| 14 | +import multiprocessing |
15 | 15 | from mccode import McStas, Process |
16 | | -from optimisation import Scanner, LinearInterval, MultiInterval, Optimizer |
| 16 | +from optimisation import Scanner, Scanner_split, LinearInterval, MultiInterval, Optimizer |
17 | 17 |
|
18 | 18 | # import config |
19 | 19 | import sys |
@@ -224,6 +224,11 @@ def add_mcrun_options(parser): |
224 | 224 | default="", |
225 | 225 | ) |
226 | 226 |
|
| 227 | + add("--scan_split", |
| 228 | + type=int, |
| 229 | + metavar="scan_split", |
| 230 | + help='Scanning over a variable is split onto individual cpu threads') |
| 231 | + |
227 | 232 | # --optimize-maxiter maxiter max iter of optimization |
228 | 233 | # --tol tol tolerance criteria to end the optimization |
229 | 234 | # --method method Method to maximize the intensity in ['nelder-mead', 'powell', 'cg', 'bfgs', 'newton-cg', 'l-bfgs-b', 'tnc', 'cobyla', 'slsqp', 'trust-constr', 'dogleg', 'trust-ncg', 'trust-exact', 'trust-krylov'] |
@@ -259,15 +264,11 @@ def add_mcstas_options(parser): |
259 | 264 |
|
260 | 265 | add('-n', '--ncount', |
261 | 266 | metavar='COUNT', type=float, default=1000000, |
262 | | - help='Set number of %ss to simulate' % (mccode_config.configuration["PARTICLE"])) |
| 267 | + help='Set number of %s to simulate' % (mccode_config.configuration["PARTICLE"])) |
263 | 268 |
|
264 | 269 | add('-t', '--trace', |
265 | 270 | metavar='trace', type=int, default=0, |
266 | | - help='Enable trace of %ss through instrument' % (mccode_config.configuration["PARTICLE"])) |
267 | | - |
268 | | - add('--no-trace', |
269 | | - action='store_true', metavar='notrace', default=None, |
270 | | - help='Disable trace of %ss in instrument (combine with -c)' % (mccode_config.configuration["PARTICLE"])) |
| 271 | + help='Enable trace of %s through instrument' % (mccode_config.configuration["PARTICLE"])) |
271 | 272 |
|
272 | 273 | add('-y', '--yes', |
273 | 274 | action='store_true', default=False, |
@@ -574,13 +575,28 @@ def main(): |
574 | 575 | elif options.numpoints is not None: |
575 | 576 | interval_points = LinearInterval.from_range(options.numpoints, intervals) |
576 | 577 |
|
| 578 | + |
| 579 | + # Check that mpi and scan split are not both used. Default to mpi if they are |
| 580 | + if options.scan_split is not None and options.mpi is not None: |
| 581 | + options.scan_split = None |
| 582 | + |
577 | 583 | # Parameters for linear scanning present |
578 | | - if interval_points: |
| 584 | + if interval_points and (options.scan_split is None): |
579 | 585 | scanner = Scanner(mcstas, intervals) |
580 | 586 | scanner.set_points(interval_points) |
581 | 587 | if (not options.dir == ''): |
582 | 588 | mkdir(options.dir) |
583 | 589 | scanner.run() # in optimisation.py |
| 590 | + |
| 591 | + elif options.scan_split is not None: |
| 592 | + if options.scan_split == 0: |
| 593 | + options.scan_split = multiprocessing.cpu_count()-1 |
| 594 | + split_scanner = Scanner_split(mcstas, intervals, options.scan_split) |
| 595 | + split_scanner.set_points(interval_points) |
| 596 | + if (not options.dir == ''): |
| 597 | + mkdir(options.dir) |
| 598 | + split_scanner.run() # in optimisation.py |
| 599 | + |
584 | 600 | elif options.optimize: |
585 | 601 | optimizer = Optimizer(mcstas, intervals) |
586 | 602 | if (not options.dir == ''): |
|
0 commit comments