Skip to content

Commit

Permalink
Enable OpenFOAM to run a list of dimensions as input.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=286940020
bvliu authored and asaksena committed Dec 26, 2019
1 parent 6b7e42e commit 19bcced
Showing 2 changed files with 52 additions and 47 deletions.
97 changes: 51 additions & 46 deletions perfkitbenchmarker/linux_benchmarks/openfoam_benchmark.py
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
import re

from perfkitbenchmarker import configs
from perfkitbenchmarker import errors
from perfkitbenchmarker import flags
from perfkitbenchmarker import hpc_util
from perfkitbenchmarker import sample
@@ -53,34 +54,14 @@
'openfoam_case', _DEFAULT_CASE,
sorted(list(_CASE_PATHS.keys())),
'Name of the OpenFOAM case to run.')

# Convenience flag when running motorbike. Motorbike is the most common case,
# so we provide different sizes here.
_DEFAULT_MOTORBIKE_DIMENSIONS = 'small'
_MOTORBIKE_DIMENSIONS = {
'small': '20 8 8',
'medium': '40 16 16',
'large': '80 32 32',
'x-large': '160 64 64',
}
assert _DEFAULT_MOTORBIKE_DIMENSIONS in _MOTORBIKE_DIMENSIONS
flags.DEFINE_enum(
'openfoam_motorbike_dimensions', _DEFAULT_MOTORBIKE_DIMENSIONS,
sorted(list(_MOTORBIKE_DIMENSIONS.keys())),
'If running motorbike, sets the dimensions of the motorbike case.')

# Problem size and scaling
flags.DEFINE_string(
'openfoam_dimensions', _MOTORBIKE_DIMENSIONS[_DEFAULT_MOTORBIKE_DIMENSIONS],
'Dimensions of the case.')
flags.DEFINE_list('openfoam_dimensions', ['20 8 8'], 'Dimensions of the case.')
flags.DEFINE_integer(
'openfoam_num_threads', None,
'The number of threads to run OpenFOAM with.')
flags.DEFINE_string(
'openfoam_mpi_mapping', 'core:SPAN',
'Mpirun process mapping to use as arguments to "mpirun --map-by".')


BENCHMARK_NAME = 'openfoam'
_BENCHMARK_ROOT = '$HOME/OpenFOAM/run'
BENCHMARK_CONFIG = """
@@ -131,6 +112,10 @@
def GetConfig(user_config):
"""Returns the configuration of a benchmark."""
config = configs.LoadConfig(BENCHMARK_CONFIG, user_config, BENCHMARK_NAME)
logging.info(FLAGS.openfoam_dimensions)
if FLAGS.openfoam_dimensions is None:
raise errors.Config.MissingOption(
'Missing argument for --openfoam_dimensions.')
if FLAGS['num_vms'].present:
config['vm_groups']['default']['vm_count'] = FLAGS.num_vms
return config
@@ -265,6 +250,9 @@ def _SetDimensions(vm, dimensions):
with:
hex (0 1 2 3 4 5 6 7) (dimensions) simpleGrading (1 1 1)
The actual contents of the second set of parentheses doesn't matter. This
function will just replace whatever is inside those.
Args:
vm: The vm to make the replacement on.
dimensions: String, new mesh dimensions to run with.
@@ -278,7 +266,15 @@ def _SetDimensions(vm, dimensions):


def _UseMpi(vm, num_processes):
"""Configure OpenFOAM to use MPI if running with more than 1 VM."""
"""Configure OpenFOAM to use MPI if running with more than 1 VM.
This function looks for the word "runParallel" in the run script and replaces
it with an mpirun command.
Args:
vm: The worker vm to use MPI on.
num_processes: The total number of processes for the MPI job.
"""
runscript = _GetPath(_RUNSCRIPT)
vm_util.ReplaceText(
vm, 'runParallel', 'mpirun '
@@ -293,6 +289,24 @@ def _UseMpi(vm, num_processes):
vm_util.ReplaceText(vm, '^mpirun.*', '& -parallel', runscript)


def _RunCase(master_vm, dimensions):
"""Runs the case with the given dimensions.
Args:
master_vm: The vm to run the case commands on. If using the default NFS
server, it doesn't actually matter which vm this is.
dimensions: A string of the dimensions to run with. Like "100 24 24".
Returns:
A list of performance samples for the given dimensions.
"""
_SetDimensions(master_vm, dimensions)
run_command = ' && '.join(
['cd %s' % _GetWorkingDirPath(), './Allclean', 'time ./Allrun'])
_, run_output = master_vm.RemoteCommand(run_command)
return _GetSamples(run_output)


def Run(benchmark_spec):
"""Runs the benchmark and returns a dict of performance data.
@@ -321,35 +335,26 @@ def Run(benchmark_spec):
master_vm.RemoteCommand('cp -r {case_path} {destination}'.format(
case_path=posixpath.join(openfoam.OPENFOAM_ROOT, _CASE_PATHS[case]),
destination=_BENCHMARK_ROOT))
if case == 'motorbike':
dimensions = _MOTORBIKE_DIMENSIONS[FLAGS.openfoam_motorbike_dimensions]
if FLAGS['openfoam_dimensions'].present:
dimensions = FLAGS.openfoam_dimensions
_SetDimensions(master_vm, dimensions)
_SetDecomposeMethod(master_vm, 'scotch')
_SetNumProcesses(master_vm, num_cpus_to_use)
if num_vms > 1:
_UseMpi(master_vm, num_cpus_to_use)

# Run and collect samples
run_command = ' && '.join([
'cd %s' % _GetWorkingDirPath(),
'./Allclean',
'time ./Allrun'
])
_, run_output = master_vm.RemoteCommand(run_command)
samples = _GetSamples(run_output)
common_metadata = {
'case_name': FLAGS.openfoam_case,
'dimensions': dimensions,
'total_cpus_available': num_cpus_available,
'total_cpus_used': num_cpus_to_use,
'openfoam_version': _GetOpenfoamVersion(master_vm),
'openmpi_version': _GetOpenmpiVersion(master_vm),
'mpi_mapping': FLAGS.openfoam_mpi_mapping,
}
for result in samples:
result.metadata.update(common_metadata)
samples = []
for dimensions in FLAGS.openfoam_dimensions:
results = _RunCase(master_vm, dimensions)
common_metadata = {
'case_name': FLAGS.openfoam_case,
'dimensions': dimensions,
'total_cpus_available': num_cpus_available,
'total_cpus_used': num_cpus_to_use,
'openfoam_version': _GetOpenfoamVersion(master_vm),
'openmpi_version': _GetOpenmpiVersion(master_vm),
'mpi_mapping': FLAGS.openfoam_mpi_mapping,
}
for result in results:
result.metadata.update(common_metadata)
samples.extend(results)
return samples


2 changes: 1 addition & 1 deletion tests/linux_benchmarks/openfoam_benchmark_test.py
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ def setUp(self):
return_value='1.10.2')
@mock.patch.object(openfoam_benchmark, '_GetOpenfoamVersion',
return_value='7')
@flagsaver.flagsaver(openfoam_motorbike_dimensions='large')
@flagsaver.flagsaver(openfoam_dimensions=['80 32 32'])
def testRunReturnsCorrectlyParsedSamples(self,
mock_getopenfoamversion,
mock_getmpiversion):

0 comments on commit 19bcced

Please sign in to comment.