Exemplo n.º 1
0
def Run(benchmark_spec):
    """Runs the benchmark and returns a dict of performance data.

  It must be possible to run the benchmark multiple times after the Prepare
  stage. This method runs a single case with multiple dimensions.

  Args:
    benchmark_spec: The benchmark spec for the OpenFOAM benchmark.

  Returns:
    A list of performance samples.
  """
    vms = benchmark_spec.vms
    master_vm = vms[0]
    num_vms = len(vms)

    # Run configuration metadata:
    num_cpus_available = num_vms * master_vm.NumCpusForBenchmark()
    if FLAGS.openfoam_num_threads_per_vm is None:
        num_cpus_to_use = num_cpus_available // 2
    else:
        num_cpus_to_use = num_vms * FLAGS.openfoam_num_threads_per_vm
    case_name = FLAGS.openfoam_case
    mpi_mapping = FLAGS.openfoam_mpi_mapping
    decomp_method = FLAGS.openfoam_decomp_method
    max_global_cells = FLAGS.openfoam_max_global_cells
    openfoam_version = _GetOpenfoamVersion(master_vm)
    openmpi_version = openmpi.GetMpiVersion(master_vm)
    common_metadata = {
        'case_name': case_name,
        'decomp_method': decomp_method,
        'max_global_cells': max_global_cells,
        'mpi_mapping': mpi_mapping,
        'openfoam_version': openfoam_version,
        'openmpi_version': openmpi_version,
        'total_cpus_available': num_cpus_available,
        'total_cpus_used': num_cpus_to_use,
    }
    logging.info('Running %s case on %s/%s cores on %s vms', case_name,
                 num_cpus_to_use, num_cpus_available, num_vms)
    logging.info('Common metadata: %s', common_metadata)

    # Copy the run directory.
    case_path = posixpath.join(openfoam.OPENFOAM_ROOT, _CASE_PATHS[case_name])
    master_vm.RemoteCommand(f'cp -r {case_path} {_BENCHMARK_ROOT}')

    # Configure common parameters.
    _SetDictEntry(master_vm, 'method', decomp_method, _DECOMPOSE_DICT)
    _SetDictEntry(master_vm, 'numberOfSubdomains', num_cpus_to_use,
                  _DECOMPOSE_DICT)
    _SetDictEntry(master_vm, 'hierarchicalCoeffs.n',
                  f'({num_cpus_to_use} 1 1)', _DECOMPOSE_DICT)
    _SetDictEntry(master_vm, 'castellatedMeshControls.maxGlobalCells',
                  max_global_cells, _SNAPPY_HEX_MESH_DICT)
    _UseMpi(master_vm, num_cpus_to_use, mpi_mapping)

    # Run and gather samples.
    samples = []
    for dimensions in FLAGS.openfoam_dimensions:
        results = _RunCase(master_vm, dimensions)
        # Update every case run with common metadata.
        for result in results:
            result.metadata.update(common_metadata)
        samples.extend(results)
    return samples
Exemplo n.º 2
0
def _GetMpiVersion(vm) -> Optional[str]:
    """Returns the MPI version to use for the given OS type."""
    if FLAGS.mpi_vendor == 'intel':
        return intelmpi.MpirunMpiVersion(vm)
    elif FLAGS.mpi_vendor == 'openmpi':
        return openmpi.GetMpiVersion(vm)