remotecall_fetch

remotecall_fetch(func, id, args...)

Perform fetch(remotecall(...)) in one message. Any remote exceptions are captured in a RemoteException and thrown.

Examples

  1. Perform a remote function call and fetch the result:

    julia> result = remotecall_fetch(sqrt, 2, 4.0)
    2.0

    This example performs a remote function call to calculate the square root of 4 on the worker with id 2. The result is fetched and stored in the variable result.

  2. Handle remote exceptions:

    julia> try
              remotecall_fetch(div, 2, 5, 0)
          catch ex
              ex
          end
    RemoteException(Any[DivideError()])

    In this example, a remote function call is made to divide 5 by 0 on worker 2. Since dividing by zero raises a DivideError, the exception is captured in a RemoteException and thrown.

  3. Pass multiple arguments to the remote function:
    julia> remotecall_fetch(+, 2, 3, 4, 5)
    12

    Here, the + function is called on worker 2 with the arguments 3, 4, and 5. The result, which is the sum of the arguments, is fetched.

Common mistake example:

julia> result = remotecall_fetch(sqrt, 2, -4.0)
ERROR: DomainError with -4.0:
NaN result for non-NaN input.

In this case, the sqrt function is called on worker 2 with a negative value (-4.0). This results in a DomainError because the square root of a negative number is not defined. It's important to ensure that the arguments passed to the remote function are valid to avoid such errors.

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.

*Required Field
Details

Checking you are not a robot: