Skip to content

backtracking/functory

Repository files navigation

Functory: a distributed computing library for OCaml

Copyright (C) 2010- Jean-Christophe Filliatre and Kalyan Krishnamani

Installation

./configure

make

sudo make install

If you are using ocamlfind, you can also want to run

sudo make ocamlfind-install

Mini tutorial

Assume you want to apply a function "map" such as

let map x = x+1

to some list elements such as

[1;2;3;4;5]

and sum the results with a function "fold" such as

let fold = (+)

You can do that using function "map_local_fold" from the library, as follows:

let () = Printf.printf "%d@." (map_local_fold ~map ~fold 0 [1;2;3;4;5])

The Functory library allows you to perform this computation in three different ways: either sequentially, or using several cores on the same machine, or using a network of different machines.

To use the sequential implementation, you simply use the following line of code

open Functory.Sequential

To use several cores (say 4) on a single machine, you should add instead

open Functory.Cores
let () = set_number_of_cores 4

Finally, to use a network of, say 2 cores on machine "mach1" and 4 cores on machine "mach2", you should add instead

open Functory.Network
let () = declare_workers ~n:2 "mach1"
let () = declare_workers ~n:4 "mach2"

Your program is compiled in the following way (in any case):

ocamlopt -I +functory unix.cmxa functory.cmxa <your files...>

and then run as usual. In the network case, the same program should be run on the three machines, that are the two workers and the master. (It is also possible to run different programs for master and workers; see the documentation).