9

Ocaml プロセスは 1 つのコアしか使用できず、複数のコアを使用するには複数のプロセスを実行する必要があります。

モンテカルロ シミュレーションを並列化するために使用する Ocaml フレームワークはありますか?

4

2 に答える 2

8

次のコンビネータを使用して、別の(フォークされた)プロセスの値に関数を適用し、値が適用されinvokeたときにその結果の待機をブロックします。()

  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
于 2009-10-18T22:19:10.837 に答える
3

現在、それを行う唯一の方法はMPIを使用することであり、XavierLeroyのWebサイトでそのocamlバインディングを見つけることができます。

于 2009-08-17T13:52:07.523 に答える