From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 81585BC69 for ; Sun, 22 Apr 2007 12:30:02 +0200 (CEST) Received: from smtp6-g19.free.fr (smtp6-g19.free.fr [212.27.42.36]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3MAU2Wd031718 for ; Sun, 22 Apr 2007 12:30:02 +0200 Received: from [192.168.1.2] (che78-2-82-237-71-191.fbx.proxad.net [82.237.71.191]) by smtp6-g19.free.fr (Postfix) with ESMTP id DB4626D482; Sun, 22 Apr 2007 12:30:01 +0200 (CEST) Message-ID: <462B3929.9080608@inria.fr> Date: Sun, 22 Apr 2007 12:30:01 +0200 From: Xavier Leroy User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jason Ganetsky Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Multiprocessor support in OCaml References: In-Reply-To: X-Enigmail-Version: 0.91.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 462B392A.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 threads:01 parallelism:01 parallelism:01 ocamlmpi:01 threads:01 scheduler:01 reschedule:98 caml-list:01 modules:02 caml:02 external:02 blocking:04 processors:04 > 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