Comment detail
分散関数呼び出し (Nested Flatten)
> それと、JoCaml では for 文が並行実行されるので、client.ml での price_string の呼び出しはおそらく直列には動いていません。
うっかりしてました。
この話はプロセスコンテキストでは正しいですが、投稿したコードの例では for は式コンテキストで使われているので、この場合は直列に動いているはずです。
この例で並行に動かすなら for の前に spawn を追加すれば良いと思います。(diff 参照)
その場合 for の内部はプロセスコンテキストになるので、price_string をプロセス扱いにするために空のプロセス 0 を付け足しています。
うっかりしてました。
この話はプロセスコンテキストでは正しいですが、投稿したコードの例では for は式コンテキストで使われているので、この場合は直列に動いているはずです。
この例で並行に動かすなら for の前に spawn を追加すれば良いと思います。(diff 参照)
その場合 for の内部はプロセスコンテキストになるので、price_string をプロセス扱いにするために空のプロセス 0 を付け足しています。
1 2 3 4 5 6 7 8 9 10 11 12 13 | --- client.ml.orig 2007-11-24 20:24:55.000000000 +0900
+++ client.ml 2007-11-24 20:31:51.000000000 +0900
@@ -9,8 +9,8 @@
let price_string : int * int -> string =
Join.Ns.lookup namespace "price_string"
in
- for i = 0 to 10000 do
- ignore (price_string (2000, 20))
+ spawn for i = 0 to 10000 do
+ (ignore (price_string (2000, 20)); 0)
done;
print_endline (price_string (2000, 20))
| _ ->
|




jijixi
#4375()
[
OCaml
]
Rating2/2=1.00
並行プログラミングと分散プログラミングがサポートされています。
server.ml を動かした状態で client.ml を動かすことで、サーバ側に定義されている price_string 関数が 10000 回実行されます。
サーバ:
Mac OS X 10.5 PPC G5/1.8GHz mem:1GB
クライアント:
FreeBSD 6.2R Pen3/550MHz mem:256MB
という環境でテストしました。
まずインタプリタで、
server% jocaml server.ml 10000
listening address 10.0.1.5
listening port 10000
client% time jocaml client.ml 10.0.1.5 10000
jocaml client.ml 10.0.1.5 10000 12.28s user 1.09s system 69% cpu 19.178 total
jocamlopt でネイティブコンパイルしたもので、
server% ./server 10000
client% time ./client 10.0.1.5 10000
./client 10.0.1.5 10000 4.84s user 1.17s system 60% cpu 9.930 total
といった感じでした。
実行される関数はサーバ側に定義されているので、実際の実行はサーバ側でされています。
それと、JoCaml では for 文が並行実行されるので、client.ml での price_string の呼び出しはおそらく直列には動いていません。
see: The JoCaml system
Rating2/2=1.00-0+
1 reply [ reply ]