Function timely::execute::execute_from_args

source ·
pub fn execute_from_args<I, T, F>(
    iter: I,
    func: F,
) -> Result<WorkerGuards<T>, String>
where I: Iterator<Item = String>, T: Send + 'static, F: Fn(&mut Worker<Allocator>) -> T + Send + Sync + 'static,
Expand description

Executes a timely dataflow from supplied arguments and per-communicator logic.

The execute method takes arguments (typically std::env::args()) and spins up some number of workers threads, each of which execute the supplied closure to construct and run a timely dataflow computation.

The closure may return a T: Send+'static. The execute_from_args method returns immediately after initializing the timely computation with a result containing a WorkerGuards<T> (or error information), which can be joined to recover the result T values from the local workers.

Note: if the caller drops the result of execute_from_args, the drop code will block awaiting the completion of the timely computation.

The arguments execute_from_args currently understands are:

-w, --workers: number of per-process worker threads.

-n, --processes: number of processes involved in the computation.

-p, --process: identity of this process; from 0 to n-1.

-h, --hostfile: a text file whose lines are “hostname:port” in order of process identity. If not specified, localhost will be used, with port numbers increasing from 2101 (chosen arbitrarily).

This method is only available if the getopts feature is enabled, which it is by default.

§Examples

use timely::dataflow::operators::{ToStream, Inspect};

// execute a timely dataflow using command line parameters
timely::execute_from_args(std::env::args(), |worker| {
    worker.dataflow::<(),_,_>(|scope| {
        (0..10).to_stream(scope)
               .inspect(|x| println!("seen: {:?}", x));
    })
}).unwrap();
host0% cargo run -- -w 2 -n 4 -h hosts.txt -p 0
host1% cargo run -- -w 2 -n 4 -h hosts.txt -p 1
host2% cargo run -- -w 2 -n 4 -h hosts.txt -p 2
host3% cargo run -- -w 2 -n 4 -h hosts.txt -p 3
% cat hosts.txt
host0:port
host1:port
host2:port
host3:port