* Re: [Caml-list] Multiprocessor support in OCaml
2007-04-22 7:42 Multiprocessor support in OCaml Jason Ganetsky
@ 2007-04-22 8:44 ` Richard Jones
2007-04-22 10:30 ` Xavier Leroy
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Richard Jones @ 2007-04-22 8:44 UTC (permalink / raw)
To: Jason Ganetsky; +Cc: caml-list
On Sun, Apr 22, 2007 at 03:42:09AM -0400, Jason Ganetsky wrote:
> I'm new to this list, and new to OCaml (although, have some experience with
> SML).
There's a beginner's list:
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Anyway, I have recently written an OCaml thread pool implementation, on top
> of the Thread and Event modules. I did this for the purpose of exploiting an
> SMP system I have, and was a disappointed to read today that OCaml doesn't
> support multiprocessor systems.
>
> I played around with it a little, and discovered that by liberally calling
> Thread.yield, I do cajole my threads into running on multiple processors. Is
> this behavior normal, or have I discovered a problem with the Thread module?
> I'm certainly happy that I can get it to use my SMP... but I will stop it at
> once if you tell me that this is unsafe.
The garbage collector doesn't support concurrency, so there's a big
global lock around all OCaml code.
http://caml.inria.fr/pub/ml-archives/caml-list/2002/11/64c14acb90cb14bedb2cacb73338fb15.en.html
Rich.
--
Richard Jones
Red Hat
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] Multiprocessor support in OCaml
2007-04-22 7:42 Multiprocessor support in OCaml Jason Ganetsky
2007-04-22 8:44 ` [Caml-list] " Richard Jones
@ 2007-04-22 10:30 ` Xavier Leroy
2007-04-22 11:55 ` Don Syme
2007-04-22 10:58 ` Erik de Castro Lopo
2007-04-22 17:32 ` Zheng Li
3 siblings, 1 reply; 9+ messages in thread
From: Xavier Leroy @ 2007-04-22 10:30 UTC (permalink / raw)
To: Jason Ganetsky; +Cc: caml-list
> Anyway, I have recently written an OCaml thread pool implementation, on
> top of the Thread and Event modules. I did this for the purpose of
> exploiting an SMP system I have, and was a disappointed to read today
> that OCaml doesn't support multiprocessor systems.
You are correct that OCaml *threads* do not exploit multiprocessing.
Basically, only one OCaml thread can run at a time.
You can still get parallelism in several ways. First, external C
libraries called from OCaml can run in parallel with OCaml code
provided the OCaml/C interface for these libraries makes uses of the
"blocking section" mechanism. Second, process-level parallelism works
very well with programs written in message-passing style, using e.g.
OcamlMPI or OCamlP3L.
> I played around with it a little, and discovered that by liberally
> calling Thread.yield, I do cajole my threads into running on multiple
> processors.
This is an illusion. Thread.yield gives more opportunities to the OS
scheduler to reschedule a Caml thread on a different processor, but
you're not gaining parallelism this way and you might actually lose
performance (because of cache ping-pong effects and the like).
- Xavier Leroy
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [Caml-list] Multiprocessor support in OCaml
2007-04-22 10:30 ` Xavier Leroy
@ 2007-04-22 11:55 ` Don Syme
0 siblings, 0 replies; 9+ messages in thread
From: Don Syme @ 2007-04-22 11:55 UTC (permalink / raw)
To: Xavier Leroy, Jason Ganetsky; +Cc: caml-list
Just to mention there is a way of getting multiple concurrently executing OCaml threads in a program, which I discovered a while back: you can statically link multiple independent copies of the OCaml runtime, each into its own DLL (on Windows). This allows multiple independent OCaml threads to run concurrently.
I presume this technique works well enough for SMP up to 2-4 processors, though have never done any serious performance testing.
The OCaml programs must not, of course, trade OCaml values, but can communicate in-process by other means (e.g. shared C memory or some other message passing technique).
Regards,
Don
P.S. I've only used this technique on Windows.
-----Original Message-----
From: caml-list-bounces@yquem.inria.fr [mailto:caml-list-bounces@yquem.inria.fr] On Behalf Of Xavier Leroy
Sent: 22 April 2007 11:30
To: Jason Ganetsky
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Multiprocessor support in OCaml
> Anyway, I have recently written an OCaml thread pool implementation, on
> top of the Thread and Event modules. I did this for the purpose of
> exploiting an SMP system I have, and was a disappointed to read today
> that OCaml doesn't support multiprocessor systems.
You are correct that OCaml *threads* do not exploit multiprocessing.
Basically, only one OCaml thread can run at a time.
You can still get parallelism in several ways. First, external C
libraries called from OCaml can run in parallel with OCaml code
provided the OCaml/C interface for these libraries makes uses of the
"blocking section" mechanism. Second, process-level parallelism works
very well with programs written in message-passing style, using e.g.
OcamlMPI or OCamlP3L.
> I played around with it a little, and discovered that by liberally
> calling Thread.yield, I do cajole my threads into running on multiple
> processors.
This is an illusion. Thread.yield gives more opportunities to the OS
scheduler to reschedule a Caml thread on a different processor, but
you're not gaining parallelism this way and you might actually lose
performance (because of cache ping-pong effects and the like).
- Xavier Leroy
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Caml-list] Multiprocessor support in OCaml
2007-04-22 7:42 Multiprocessor support in OCaml Jason Ganetsky
2007-04-22 8:44 ` [Caml-list] " Richard Jones
2007-04-22 10:30 ` Xavier Leroy
@ 2007-04-22 10:58 ` Erik de Castro Lopo
2007-04-22 13:23 ` Jon Harrop
2007-04-22 17:32 ` Zheng Li
3 siblings, 1 reply; 9+ messages in thread
From: Erik de Castro Lopo @ 2007-04-22 10:58 UTC (permalink / raw)
To: caml-list
Jason Ganetsky wrote:
> Hi all,
>
> I'm new to this list, and new to OCaml (although, have some experience with
> SML).
>
> Anyway, I have recently written an OCaml thread pool implementation, on top
> of the Thread and Event modules. I did this for the purpose of exploiting an
> SMP system I have, and was a disappointed to read today that OCaml doesn't
> support multiprocessor systems.
For real multi-procesor parallelism, have a look at this:
http://www.pps.jussieu.fr/~dicosmo/ocamlp3l/
Haven't tried it myself, but its on my todo list.
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
"life is too long to be an expert at harmful things, including
such evilness as C++ and perl." -- Erik Naggum
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Multiprocessor support in OCaml
2007-04-22 7:42 Multiprocessor support in OCaml Jason Ganetsky
` (2 preceding siblings ...)
2007-04-22 10:58 ` Erik de Castro Lopo
@ 2007-04-22 17:32 ` Zheng Li
[not found] ` <ab351c020704221052v50ce66b6maec299889a2c1f1f@mail.gmail.com>
3 siblings, 1 reply; 9+ messages in thread
From: Zheng Li @ 2007-04-22 17:32 UTC (permalink / raw)
To: caml-list
Hi,
I'm working on a process back-end of STM library. It's now supported by Google
SOC and expected to release after the summer (and maybe earlier). With it, you
will be able to do shared-memory (supposing that's the style your want)
parallel programming based on processes, which in turn gives you speedup.
If interested, you can have a taste first through the (vm)thread back-end
currently available (check my homepage below), though it won't really speed up
your program because of the well-known global lock of OCaml threads.
"Jason Ganetsky" <jason.ganetsky@gmail.com> writes:
> Hi all,
> I'm new to this list, and new to OCaml (although, have some experience with
> SML).Anyway, I have recently written an OCaml thread pool implementation, on
> top of the Thread and Event modules. I did this for the purpose of exploiting
> an SMP system I have, and was a disappointed to read today that OCaml doesn't
> support multiprocessor systems.
>
> -Jason
--
Zheng Li
http://www.pps.jussieu.fr/~li
^ permalink raw reply [flat|nested] 9+ messages in thread