Skip to content

Commit

Permalink
Rename remotecall to remote_call (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Sep 12, 2023
1 parent 92b515b commit 3ee5867
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 52 deletions.
20 changes: 10 additions & 10 deletions doc/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Malt.Worker

## Calling Functions

The easiest way to execute code in a worker is with the `remotecall*` functions.
The easiest way to execute code in a worker is with the `remote_call*` functions.

Depending on the computation you want to perform, you might want to get the result
synchronously or asynchronously; you might want to store the result or throw it away.
Expand All @@ -44,16 +44,16 @@ The following table lists each function according to its scheduling and return v

| Function | Scheduling | Return value |
|:--------------------------------|:-----------|:----------------|
| [`Malt.remotecall_fetch`](@ref) | Blocking | <value> |
| [`Malt.remotecall_wait`](@ref) | Blocking | `nothing` |
| [`Malt.remotecall`](@ref) | Async | `Task` that resolves to <value> |
| [`Malt.remote_call_fetch`](@ref) | Blocking | <value> |
| [`Malt.remote_call_wait`](@ref) | Blocking | `nothing` |
| [`Malt.remote_call`](@ref) | Async | `Task` that resolves to <value> |
| [`Malt.remote_do`](@ref) | Async | `nothing` |


```@docs
Malt.remotecall_fetch
Malt.remotecall_wait
Malt.remotecall
Malt.remote_call_fetch
Malt.remote_call_wait
Malt.remote_call
Malt.remote_do
```

Expand All @@ -63,7 +63,7 @@ In some cases, evaluating functions is not enough. For example, importing module
alters the global state of the worker and can only be performed in the top level scope.
For situations like this, you can evaluate code using the `remote_eval*` functions.

Like the `remotecall*` functions, there's different a `remote_eval*` depending on the scheduling and return value.
Like the `remote_call*` functions, there's different a `remote_eval*` depending on the scheduling and return value.

| Function | Scheduling | Return value |
|:--------------------------------|:-----------|:----------------|
Expand All @@ -83,7 +83,7 @@ Malt.worker_channel
If an exception occurs on the worker while calling a function or evaluating an expression, this exception is rethrown to the host. For example:

```julia-repl
julia> Malt.remotecall_fetch(m1, :(sqrt(-1)))
julia> Malt.remote_call_fetch(m1, :(sqrt(-1)))
ERROR: Remote exception from Malt.Worker on port 9115:
DomainError with -1.0:
Expand All @@ -100,7 +100,7 @@ The thrown exception is of the type `Malt.RemoteException`, and contains two fie

!!! note

When using the async scheduling functions (`remotecall`, `remote_eval`), calling `wait` or `fetch` on the returned (failed) `Task` will throw a `Base.TaskFailedException`, not a `Malt.RemoteException`.
When using the async scheduling functions (`remote_call`, `remote_eval`), calling `wait` or `fetch` on the returned (failed) `Task` will throw a `Base.TaskFailedException`, not a `Malt.RemoteException`.

(The `Malt.RemoteException` is available with `task_failed_exception.task.exception`.)

Expand Down
16 changes: 8 additions & 8 deletions src/DistributedStdlibWorker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mutable struct DistributedStdlibWorker <: AbstractWorker
else
:($(Distributed_expr).addprocs(1; exeflags=$(exeflags), env=$(env)) |> first)
end
pid = Distributed.remotecall_eval(Main, 1, expr)
pid = Distributed.remote_call_eval(Main, 1, expr)

# TODO: process preamble from Pluto?

Expand Down Expand Up @@ -51,16 +51,16 @@ macro transform_exception(worker, ex)
end)
end

function remotecall(f, w::DistributedStdlibWorker, args...; kwargs...)
@async Distributed.remotecall_fetch(f, w.pid, args...; kwargs...)
function remote_call(f, w::DistributedStdlibWorker, args...; kwargs...)
@async Distributed.remote_call_fetch(f, w.pid, args...; kwargs...)
end

function remotecall_fetch(f, w::DistributedStdlibWorker, args...; kwargs...)
@transform_exception w Distributed.remotecall_fetch(f, w.pid, args...; kwargs...)
function remote_call_fetch(f, w::DistributedStdlibWorker, args...; kwargs...)
@transform_exception w Distributed.remote_call_fetch(f, w.pid, args...; kwargs...)
end

function remotecall_wait(f, w::DistributedStdlibWorker, args...; kwargs...)
@transform_exception w Distributed.remotecall_wait(f, w.pid, args...; kwargs...)
function remote_call_wait(f, w::DistributedStdlibWorker, args...; kwargs...)
@transform_exception w Distributed.remote_call_wait(f, w.pid, args...; kwargs...)
nothing
end

Expand All @@ -78,7 +78,7 @@ isrunning(w::DistributedStdlibWorker) = w.isrunning

function stop(w::DistributedStdlibWorker)
w.isrunning = false
Distributed.remotecall_eval(Main, 1, quote
Distributed.remote_call_eval(Main, 1, quote
$(Distributed_expr).rmprocs($(w.pid)) |> wait
end)
nothing
Expand Down
50 changes: 25 additions & 25 deletions src/Malt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ include("./shared.jl")
abstract type AbstractWorker end

"""
Malt will raise a `TerminatedWorkerException` when a `remotecall` is made to a `Worker`
Malt will raise a `TerminatedWorkerException` when a `remote_call` is made to a `Worker`
that has already been terminated.
"""
struct TerminatedWorkerException <: Exception end
Expand Down Expand Up @@ -308,7 +308,7 @@ end


"""
Malt.remotecall(f, w::Worker, args...; kwargs...)
Malt.remote_call(f, w::Worker, args...; kwargs...)
Evaluate `f(args...; kwargs...)` in worker `w` asynchronously.
Returns a task that acts as a promise; the result value of the task is the
Expand All @@ -319,23 +319,23 @@ The function `f` must already be defined in the namespace of `w`.
# Examples
```julia-repl
julia> promise = Malt.remotecall(uppercase ∘ *, w, "I ", "declare ", "bankruptcy!");
julia> promise = Malt.remote_call(uppercase ∘ *, w, "I ", "declare ", "bankruptcy!");
julia> fetch(promise)
"I DECLARE BANKRUPTCY!"
```
"""
function remotecall(f, w::Worker, args...; kwargs...)
function remote_call(f, w::Worker, args...; kwargs...)
_send_receive_async(
w,
MsgType.from_host_call_with_response,
_new_call_msg(true, f, args, kwargs),
)
end
function remotecall(f, w::InProcessWorker, args...; kwargs...)
w.latest_request_task = @async remotecall_fetch(f, w, args...; kwargs...)
function remote_call(f, w::InProcessWorker, args...; kwargs...)
w.latest_request_task = @async remote_call_fetch(f, w, args...; kwargs...)
end
function remotecall_fetch(f, w::InProcessWorker, args...; kwargs...)
function remote_call_fetch(f, w::InProcessWorker, args...; kwargs...)
try
f(args...; kwargs...)
catch ex
Expand All @@ -347,20 +347,20 @@ function remotecall_fetch(f, w::InProcessWorker, args...; kwargs...)
))
end
end
function remotecall_wait(f, w::InProcessWorker, args...; kwargs...)
remotecall_fetch(f, w, args...; kwargs...)
function remote_call_wait(f, w::InProcessWorker, args...; kwargs...)
remote_call_fetch(f, w, args...; kwargs...)
nothing
end

"""
Malt.remotecall_fetch(f, w::Worker, args...; kwargs...)
Malt.remote_call_fetch(f, w::Worker, args...; kwargs...)
Shorthand for `fetch(Malt.remotecall(…))`. Blocks and then returns the result of the remote call.
Shorthand for `fetch(Malt.remote_call(…))`. Blocks and then returns the result of the remote call.
"""
function remotecall_fetch(f, w::AbstractWorker, args...; kwargs...)
fetch(remotecall(f, w, args...; kwargs...))
function remote_call_fetch(f, w::AbstractWorker, args...; kwargs...)
fetch(remote_call(f, w, args...; kwargs...))
end
function remotecall_fetch(f, w::Worker, args...; kwargs...)
function remote_call_fetch(f, w::Worker, args...; kwargs...)
_send_receive(
w,
MsgType.from_host_call_with_response,
Expand All @@ -369,14 +369,14 @@ function remotecall_fetch(f, w::Worker, args...; kwargs...)
end

"""
Malt.remotecall_wait(f, w::Worker, args...; kwargs...)
Malt.remote_call_wait(f, w::Worker, args...; kwargs...)
Shorthand for `wait(Malt.remotecall(…))`. Blocks and discards the resulting value.
Shorthand for `wait(Malt.remote_call(…))`. Blocks and discards the resulting value.
"""
function remotecall_wait(f, w::AbstractWorker, args...; kwargs...)
wait(remotecall(f, w, args...; kwargs...))
function remote_call_wait(f, w::AbstractWorker, args...; kwargs...)
wait(remote_call(f, w, args...; kwargs...))
end
function remotecall_wait(f, w::Worker, args...; kwargs...)
function remote_call_wait(f, w::Worker, args...; kwargs...)
_send_receive(
w,
MsgType.from_host_call_with_response,
Expand All @@ -390,7 +390,7 @@ end
Start evaluating `f(args...; kwargs...)` in worker `w` asynchronously, and return `nothing`.
Unlike `remotecall`, no reference to the remote call is available. This means:
Unlike `remote_call`, no reference to the remote call is available. This means:
- You cannot wait for the call to complete on the worker.
- The value returned by `f` is not available.
"""
Expand All @@ -415,7 +415,7 @@ end
Malt.remote_eval(mod::Module=Main, w::Worker, expr)
Evaluate expression `expr` under module `mod` on the worker `w`.
`Malt.remote_eval` is asynchronous, like `Malt.remotecall`.
`Malt.remote_eval` is asynchronous, like `Malt.remote_call`.
The module `m` and the type of the result of `expr` must be defined in both the
main process and the worker.
Expand All @@ -432,21 +432,21 @@ julia> Malt.remote_eval_fetch(w, :x)
```
"""
remote_eval(mod::Module, w::AbstractWorker, expr) = remotecall(Core.eval, w, mod, expr)
remote_eval(mod::Module, w::AbstractWorker, expr) = remote_call(Core.eval, w, mod, expr)
remote_eval(w::AbstractWorker, expr) = remote_eval(Main, w, expr)


"""
Shorthand for `fetch(Malt.remote_eval(…))`. Blocks and returns the resulting value.
"""
remote_eval_fetch(mod::Module, w::AbstractWorker, expr) = remotecall_fetch(Core.eval, w, mod, expr)
remote_eval_fetch(mod::Module, w::AbstractWorker, expr) = remote_call_fetch(Core.eval, w, mod, expr)
remote_eval_fetch(w::AbstractWorker, expr) = remote_eval_fetch(Main, w, expr)


"""
Shorthand for `wait(Malt.remote_eval(…))`. Blocks and discards the resulting value.
"""
remote_eval_wait(mod::Module, w::AbstractWorker, expr) = remotecall_wait(Core.eval, w, mod, expr)
remote_eval_wait(mod::Module, w::AbstractWorker, expr) = remote_call_wait(Core.eval, w, mod, expr)
remote_eval_wait(w::AbstractWorker, expr) = remote_eval_wait(Main, w, expr)


Expand Down Expand Up @@ -567,7 +567,7 @@ end
Malt.interrupt(w::Worker)
Send an interrupt signal to the worker process. This will interrupt the
latest request (`remotecall*` or `remote_eval*`) that was sent to the worker.
latest request (`remote_call*` or `remote_eval*`) that was sent to the worker.
"""
function interrupt(w::Worker)
if Sys.iswindows()
Expand Down
2 changes: 1 addition & 1 deletion test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@testset "Evaluating functions" begin
w = W()
@test m.isrunning(w)
@test m.remotecall_fetch(&, w, true, true)
@test m.remote_call_fetch(&, w, true, true)

m.stop(w)
end
Expand Down
8 changes: 4 additions & 4 deletions test/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TEST_BENCHMARK = true
end

m.remote_eval_fetch(w, setup)
Distributed.remotecall_eval(Main, p, setup)
Distributed.remote_call_eval(Main, p, setup)

exprs = [
quote
Expand Down Expand Up @@ -75,7 +75,7 @@ const TEST_BENCHMARK = true
ex = exprs[i]

f1() = m.remote_eval_fetch(Main, w, ex)
f2() = Distributed.remotecall_eval(Main, p, ex)
f2() = Distributed.remote_call_eval(Main, p, ex)

@test f1() == f2() || f1() f2()

Expand Down Expand Up @@ -120,13 +120,13 @@ end
@testset "Benchmark launch" begin
function launch_with_malt()
w = m.Worker()
@assert(2 == m.remotecall_fetch(+, w, 1, 1))
@assert(2 == m.remote_call_fetch(+, w, 1, 1))
m.stop(w)
end

function launch_with_distributed()
p = Distributed.addprocs(1) |> only
@assert(2 == Distributed.remotecall_fetch(+, p, 1, 1))
@assert(2 == Distributed.remote_call_fetch(+, p, 1, 1))
Distributed.rmprocs(p; waitfor=30)
end

Expand Down
8 changes: 4 additions & 4 deletions test/exceptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ end

@test_nowarn m.remote_do(sqrt, w, -1)

@test m.remotecall_fetch(&, w, true, true)
@test m.remote_call_fetch(&, w, true, true)
end

W === m.InProcessWorker || @testset "Deserializing values of unknown types" begin
Expand All @@ -68,7 +68,7 @@ end
TaskFailedException,
fetch(m.remote_eval(w, :($(stub_type_name)()))),
)
@test m.remotecall_fetch(&, w, true, true)
@test m.remote_call_fetch(&, w, true, true)
end

stub_type_name2 = gensym(:NonLocalException)
Expand All @@ -94,7 +94,7 @@ end
fetch(m.remote_eval(w, :(throw($stub_type_name2())))),
)

@test m.remotecall_fetch(&, w, true, true)
@test m.remote_call_fetch(&, w, true, true)
end

@testset "Returning an exception" begin
Expand Down Expand Up @@ -129,7 +129,7 @@ end
# Exception,
# m.worker_channel(w, :(sqrt(-1)))
# )
@test m.remotecall_fetch(&, w, true, true)
@test m.remote_call_fetch(&, w, true, true)
end

# The worker should be able to handle all that throwing
Expand Down

0 comments on commit 3ee5867

Please sign in to comment.