Welcome to the mini tutorial on how to use FUNCTORY. At the end of this tutorial you will be able
to start using the Functory and enjoy its advantages.
INSTALLATION
On downloading, you just need to issue the following commands from the Functory directory:
bash$ ./configure
bash$ make
bash$ sudo make install
USAGE
Let us take a very simple example and illustrate the usage of Functory.
Assume you want to apply a function map such as
let map x = x + 1
to some list of elements such as
[1;2;3;4;5]
and further, sum the results with a function fold such as
let fold = (+)
You can do that using function map_local_fold from Functory 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, for example) 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 +factory unix.cmxa factory.cmxa <your files...>
and then run as any usual OCaml program. In the network case, the same program needs to be run on
the three machines (the two workers being run on machines "mach1" and "mach2", respectively,
with environment variable WORKER being set).
(It is also possible to run different programs for master and workers: see documentation for details)