Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions dask_jobqueue/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from contextlib import contextmanager

import dask
from dask.utils import factors
import docrep
from .deploy import ClusterManager
from distributed import LocalCluster
Expand Down Expand Up @@ -184,8 +185,18 @@ def __init__(
cores = dask.config.get("jobqueue.%s.cores" % config_name)
if memory is None:
memory = dask.config.get("jobqueue.%s.memory" % config_name)
if cores is None or memory is None:
raise ValueError(
"You must specify how much cores and memory per job you want to use, for example:\n"
"cluster = {}(cores={}, memory={!r})".format(
self.__class__.__name__, cores or 8, memory or "24GB"
)
)
if processes is None:
processes = dask.config.get("jobqueue.%s.processes" % config_name)
if cores <= 4:
processes = cores
else:
processes = min(f for f in factors(cores) if f >= math.sqrt(cores))
if interface is None:
interface = dask.config.get("jobqueue.%s.interface" % config_name)
if death_timeout is None:
Expand All @@ -203,14 +214,6 @@ def __init__(
if shebang is None:
shebang = dask.config.get("jobqueue.%s.shebang" % config_name)

if cores is None or memory is None:
raise ValueError(
"You must specify how much cores and memory per job you want to use, for example:\n"
"cluster = {}(cores={}, memory={!r})".format(
self.__class__.__name__, cores or 8, memory or "24GB"
)
)

# This attribute should be overridden
self.job_header = None

Expand Down
7 changes: 0 additions & 7 deletions dask_jobqueue/jobqueue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ jobqueue:
# Dask worker options
cores: null # Total number of cores per job
memory: null # Total amount of memory per job
processes: 1 # Number of Python processes per job

interface: null # Network interface to use like eth0 or ib0
death-timeout: 60 # Number of seconds to wait if a worker can not find a scheduler
Expand All @@ -28,7 +27,6 @@ jobqueue:
# Dask worker options
cores: null # Total number of cores per job
memory: null # Total amount of memory per job
processes: 1 # Number of Python processes per job

interface: null # Network interface to use like eth0 or ib0
death-timeout: 60 # Number of seconds to wait if a worker can not find a scheduler
Expand All @@ -51,7 +49,6 @@ jobqueue:
# Dask worker options
cores: null # Total number of cores per job
memory: null # Total amount of memory per job
processes: 1 # Number of Python processes per job

interface: null # Network interface to use like eth0 or ib0
death-timeout: 60 # Number of seconds to wait if a worker can not find a scheduler
Expand All @@ -75,7 +72,6 @@ jobqueue:
# Dask worker options
cores: null # Total number of cores per job
memory: null # Total amount of memory per job
processes: 1 # Number of Python processes per job

interface: null # Network interface to use like eth0 or ib0
death-timeout: 60 # Number of seconds to wait if a worker can not find a scheduler
Expand All @@ -99,7 +95,6 @@ jobqueue:
# Dask worker options
cores: null # Total number of cores per job
memory: null # Total amount of memory per job
processes: 1 # Number of Python processes per job

interface: null # Network interface to use like eth0 or ib0
death-timeout: 60 # Number of seconds to wait if a worker can not find a scheduler
Expand All @@ -122,7 +117,6 @@ jobqueue:
# Dask worker options
cores: null # Total number of cores per job
memory: null # Total amount of memory per job
processes: 1 # Number of Python processes per job

interface: null # Network interface to use like eth0 or ib0
death-timeout: 60 # Number of seconds to wait if a worker can not find a scheduler
Expand All @@ -147,7 +141,6 @@ jobqueue:
# Dask worker options
cores: null # Total number of cores per job
memory: null # Total amount of memory per job
processes: 1 # Number of Python processes per job

interface: null # Network interface to use like eth0 or ib0
death-timeout: 60 # Number of seconds to wait if a worker can not find a scheduler
Expand Down
9 changes: 8 additions & 1 deletion dask_jobqueue/tests/test_jobqueue_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_errors():


def test_command_template():
with PBSCluster(cores=2, memory="4GB") as cluster:
with PBSCluster(cores=2, processes=1, memory="4GB") as cluster:
assert (
"%s -m distributed.cli.dask_worker" % (sys.executable)
in cluster._command_template
Expand Down Expand Up @@ -189,3 +189,10 @@ def test_cluster_has_cores_and_memory(Cluster):

with pytest.raises(ValueError, match=cls_name + r"cores=4, memory='\d+GB'"):
Cluster(cores=4)


def test_default_workers():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could modify this further to cover all clusters:

@pytest.mark.parametrize(
    "Cluster",
    [PBSCluster, MoabCluster, SLURMCluster, SGECluster, LSFCluster, OARCluster],
)
def test_default_workers(Cluster):
    """For 6 cores, default is 1 workers with 3 procs, 2 threads/proc"""
    with Cluster(cores=6, memory="4GB") as cluster:
        assert " --nprocs 3" in cluster._command_template
        assert " --nthreads 2" in cluster._command_template

But let's only do this if there's agreement that this will be merged before the big rewrite.

"""For 6 cores, default is 1 workers with 3 procs, 2 threads/proc"""
with PBSCluster(cores=6, memory="4GB") as cluster:
assert " --nprocs 3" in cluster._command_template
assert " --nthreads 2" in cluster._command_template
6 changes: 3 additions & 3 deletions docs/source/configuration-setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ This can be avoided by always using 'GiB' in dask-jobqueue configuration.
Processes
---------

By default Dask will run one Python process per job. However, you can
optionally choose to cut up that job into multiple processes using the
``processes`` configuration value. This can be advantageous if your
Dask will, by default, divide each job into a number of processes according
to the number of cores per job. However, you can overwrite this default value
using the ``processes`` configuration value. This can be advantageous if your
computations are bound by the GIL, but disadvantageous if you plan to
communicate a lot between processes. Typically we find that for pure Numpy
workloads a low number of processes (like one) is best, while for pure Python
Expand Down