From 79712a9f9c21c513ebfc0c3ccc2ba5edc2231346 Mon Sep 17 00:00:00 2001 From: Amit Murthy Date: Mon, 29 Sep 2014 15:33:47 +0530 Subject: [PATCH] Allow cluster managers to specify specific bind ports --- base/client.jl | 10 +++++++++- base/multi.jl | 12 +++++++++--- doc/manual/getting-started.rst | 7 ++++--- doc/manual/parallel-computing.rst | 5 ++++- doc/stdlib/base.rst | 7 ++++--- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/base/client.jl b/base/client.jl index 34f02fa2751a2..c3c05477d9c93 100644 --- a/base/client.jl +++ b/base/client.jl @@ -176,8 +176,15 @@ function init_bind_addr(args::Vector{UTF8String}) # --worker, -n and --machinefile options are affected by it btoidx = findfirst(args, "--bind-to") if btoidx > 0 - bind_addr = parseip(args[btoidx+1]) + bind_to = split(args[btoidx+1], ":") + bind_addr = parseip(bind_to[1]) + if length(bind_to) > 1 + bind_port = parseint(bind_to[2]) + else + bind_port = 0 + end else + bind_port = 0 try bind_addr = getipaddr() catch @@ -188,6 +195,7 @@ function init_bind_addr(args::Vector{UTF8String}) end global LPROC LPROC.bind_addr = bind_addr + LPROC.bind_port = uint16(bind_port) end diff --git a/base/multi.jl b/base/multi.jl index 9f6deb730bf2f..3f25cc2546291 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -188,6 +188,7 @@ end type LocalProcess id::Int bind_addr::IPAddr + bind_port::Uint16 LocalProcess() = new(1) end @@ -944,10 +945,15 @@ function start_worker(out::IO) # exit when process 1 shut down. Don't yet know why. #redirect_stderr(STDOUT) - (actual_port,sock) = listenany(uint16(9009)) + if LPROC.bind_port == 0 + (actual_port,sock) = listenany(uint16(9009)) + LPROC.bind_port = actual_port + else + sock = listen(LPROC.bind_port) + end sock.ccb = accept_handler print(out, "julia_worker:") # print header - print(out, "$(dec(actual_port))#") # print port + print(out, "$(dec(LPROC.bind_port))#") # print port print(out, LPROC.bind_addr) print(out, '\n') flush(out) @@ -1171,7 +1177,7 @@ function launch_on_machine(manager::SSHManager, config::Dict, resp_arr::Array, m thisconfig = copy(config) # config for this worker - # machine could be of the format [user@]host[:port] bind_addr + # machine could be of the format [user@]host[:port] bind_addr[:bind_port] machine_bind = split(machine) if length(machine_bind) > 1 exeflags = `--bind-to $(machine_bind[2]) $exeflags_base` diff --git a/doc/manual/getting-started.rst b/doc/manual/getting-started.rst index 5f8976b796656..b5cd1985ab182 100644 --- a/doc/manual/getting-started.rst +++ b/doc/manual/getting-started.rst @@ -71,9 +71,10 @@ worker processes, while ``--machinefile file`` will launch a worker for each line in file ``file``. The machines defined in ``file`` must be accessible via a passwordless ``ssh`` login, with Julia installed at the same location as the current host. Each machine definition takes the form -``[user@]host[:port] [bind_addr]`` . ``user`` defaults to current user, -``port`` to the standard ssh port. Optionally, in case of multi-homed hosts, -``bind_addr`` may be used to explicitly specify an interface. +``[user@]host[:port] [bind_addr[:port]]`` . ``user`` defaults to current user, +``port`` to the standard ssh port. The optional ``bind-to bind_addr[:port]`` +specifies the ip-address and port that other workers should use to +connect to this worker. If you have code that you want executed whenever julia is run, you can diff --git a/doc/manual/parallel-computing.rst b/doc/manual/parallel-computing.rst index 9f78ec08ce84c..852b24c4f1496 100644 --- a/doc/manual/parallel-computing.rst +++ b/doc/manual/parallel-computing.rst @@ -665,7 +665,10 @@ The ``launch`` method takes the following arguments: The ``launch`` method is called asynchronously in a separate task. The termination of this task signals that all requested workers have been launched. Hence the ``launch`` function MUST exit as soon -as all the requested workers have been launched. +as all the requested workers have been launched. The julia worker MUST be launched with a ``--worker`` +argument. Optionally ``--bind-to bind_addr[:port]`` may also be specified to enable other workers +to connect to it only at the specified ``bind_addr`` and ``port``. + Arrays of worker information tuples that are appended to ``resp_arr`` can take any one of the following forms:: diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index e62add041565d..f8329761ce78f 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -5061,9 +5061,10 @@ Parallel Computing Add processes on remote machines via SSH. Requires julia to be installed in the same location on each node, or to be available via a shared file system. - ``machines`` is a vector of host definitions of the form ``[user@]host[:port] [bind_addr]``. ``user`` defaults - to current user, ``port`` to the standard ssh port. Optionally, in case of multi-homed hosts, ``bind_addr`` - may be used to explicitly specify an interface. + ``machines`` is a vector of host definitions of the form ``[user@]host[:port] [bind_addr[:port]]``. ``user`` defaults + to current user, ``port`` to the standard ssh port. A worker is started at each host definition. + If the optional ``[bind_addr[:port]]`` is specified, other workers will connect to this worker at the + specified ``bind_addr`` and ``port``. Keyword arguments: