Skip to content

Commit

Permalink
Separate out creating parallel command step
Browse files Browse the repository at this point in the history
Creating the command is now a process that can be called without running
the command, for use when we wish to run the command separately.
  • Loading branch information
altheaden committed Jun 2, 2023
1 parent 4cee7f4 commit 8dce9b3
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions polaris/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,40 @@ def run_command(args, cpus_per_task, ntasks, openmp_threads, config, logger):
if openmp_threads > 1:
logger.info(f'Running with {openmp_threads} OpenMP threads')

command_line_args = get_parallel_command(args, cpus_per_task, ntasks,
config)
check_call(command_line_args, logger, env=env)


def get_parallel_command(args, cpus_per_task, ntasks, config):
"""
Run a subprocess with the given command-line arguments and resources
Parameters
----------
args : list of str
The command-line arguments to run in parallel
cpus_per_task : int
the number of cores per task the process would ideally use. If
fewer cores per node are available on the system, the substep will
run on all available cores as long as this is not below
``min_cpus_per_task``
ntasks : int
the number of tasks the process would ideally use. If too few
cores are available on the system to accommodate the number of
tasks and the number of cores per task, the substep will run on
fewer tasks as long as as this is not below ``min_tasks``
config : configparser.ConfigParser
Configuration options for the test case
Returns
-------
command_line_args : list
The full parallel command
"""
parallel_executable = config.get('parallel', 'parallel_executable')

# split the parallel executable into constituents in case it includes flags
Expand All @@ -174,8 +208,7 @@ def run_command(args, cpus_per_task, ntasks, openmp_threads, config, logger):
raise ValueError(f'Unexpected parallel system: {parallel_system}')

command_line_args.extend(args)

check_call(command_line_args, logger, env=env)
return command_line_args


def _get_subprocess_int(args):
Expand Down

0 comments on commit 8dce9b3

Please sign in to comment.