remotecall
remotecall(func, id, args...)
Call a function asynchronously on the given arguments on the specified process. Returns a RemoteRef.
Examples
jldoctest
julia> addprocs(2) # Start two additional worker processes
2-element Vector{Int64}:
2
3
julia> @everywhere function square(x)
return x^2
end
julia> r = remotecall(square, 2, 5)
RemoteRef(2,1,5)
julia> fetch(r)
25
In this example, we start two additional worker processes using addprocs(2). Then, we define a function square that calculates the square of a number. We use remotecall to asynchronously call the square function on the process with id 2 and pass 5 as the argument. The remotecall function returns a RemoteRef, which represents the remote computation. Finally, we use fetch to retrieve the result of the remote computation.
Common mistake example:
julia> r = remotecall(square, 4, 10)
ERROR: ArgumentError: invalid or unknown process id: 4
In this example, the process id 4 is not a valid process id since we only added two additional worker processes. Make sure to provide a valid process id when using remotecall.
See Also
accept, bind, :@spawn, connect, fetch, getaddrinfo, gethostname, getipaddr, getsockname, init_worker, IPv4, IPv6, isready, issocket, kill, listen, recv, recvfrom, remotecall, remotecall_fetch, remotecall_wait, RemoteRef, send, setopt,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.