2009-08-17 5 views

Répondre

3

Actuellement, la seule façon de le faire est avec MPI, et vous pouvez trouver des liaisons ocaml pour cela sur Xavier Leroy's website.

+2

ocaml4multicore est disponible (avec limitation), voir: http://www.algo-prog.info/ocmc/web/ – nlucaroni

8

Utilisez la invoke combinateur pour appliquer une fonction à une valeur dans un autre processus (fourchue), puis bloquer en attendant le résultat lorsque la valeur () est appliquée suivant:

let invoke (f : 'a -> 'b) x : unit -> 'b = 
    let input, output = Unix.pipe() in 
    match Unix.fork() with 
    | -1 -> (let v = f x in fun() -> v) 
    | 0 -> 
     Unix.close input; 
     let output = Unix.out_channel_of_descr output in 
     Marshal.to_channel output (try `Res(f x) with e -> `Exn e) []; 
     close_out output; 
     exit 0 
    | pid -> 
     Unix.close output; 
     let input = Unix.in_channel_of_descr input in 
     fun() -> 
      let v = Marshal.from_channel input in 
      ignore (Unix.waitpid [] pid); 
      close_in input; 
      match v with 
      | `Res x -> x 
      | `Exn e -> raise e 
Questions connexes