def check_utilization(nn, np, ppn, threshold=0.9, name=None):
    """Check whether the calculated node utilization is below threshold.

    This function raises a :class:`RuntimeError` if the calculated
    node utilization is below the given threshold or if the number
    of calculated required nodes is zero.

    :param nn:
        Number of requested nodes.
    :param np:
        Number of required processing units (e.g. CPUs, GPUs).
    :param ppn:
        Number of processing units available per node.
    :param threshold:
        The minimally required node utilization.
    :param name:
        A human-friendly name for the tested processing unit
        to be used in the error message, for example: CPU or GPU.
    :returns:
        The number of calculated nodes.
    :raises RuntimeError:
        Raised if the node utilization is below the given threshold.
    """
    if not (0 <= threshold <= 1.0):
        raise ValueError("The value for 'threshold' must be between 0 and 1.")

    # Zero nodes are just returned and possible utilization or validation checks
    # must be performed elsewhere.
    if nn == 0:
        return 0

    # The utilization is the number of processing units (np) required divided
    # by the product of the number of nodes (nn) and the number of processing
    # units per node (ppn).
    utilization = np / (nn * ppn)

    # Raise RuntimeError if the utilization is below the specified threshold.
    if utilization < threshold:
        raise RuntimeError(
            "Low{name} utilization warning: {util:.0%}\n"
            "Total resources requested would require {nn} node(s), "
            "but each node supports up to {ppn}{name} task(s).\n"
            "Requesting {np} total{name} task(s) would result in node underutilization. "
            "Use --force to ignore the warning, but users are encouraged to use --pretend to "
            "confirm that the submission script fully utilizes the compute resources before "
            "force submission" .format(
                util=utilization, np=np, nn=nn, ppn=ppn,
                name=' {}'.format(name) if name else ''))

    # Everything fine, return number of nodes (nn).
    return nn