Find file
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (36 sloc) 1.52 KB
(* Minimal example. *)
(* Compile:
ocamlfind ocamlc -package procord -linkpkg -o minimal
then run:
./minimal *)
(* First, let's write the function that we want to run in another process. *)
let rec fibo x =
if x <= 1 then 1 else fibo (x - 1) + fibo (x - 2)
(* Let's define a task for our function.
[fibo_worker] is for the worker process, [fibo_delegated] is for the
main program. *)
let fibo_worker, fibo_delegated =
Procord_task.make "fibo" fibo
(* Entry point. *)
let () =
(* We want our program to be able to act both as a worker (local or distant)
and as the main program. The easiest way to achieve this is to call
[] reads command-line arguments.
If [--procord-worker] or [--procord-server] is given,
[] starts the worker and never returns.
Else, [] returns immediately. *) [ Procord_worker.task fibo_worker ];
(* If we are past [] then it means we are the main program.
We start a process which will run in parallel to compute [fibo 10]. *)
let process = Procord_process.delegate fibo_delegated 10 in
(* We wait for the result. *)
let result = process in
(* Finally, we print the result. *)
Printf.printf "%d\n%!" result
(* You can experiment with the command-line options:
./minimal --help
Try to run a server:
./minimal --procord-server
and connect to it:
./minimal --procord-hostname localhost *)