From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 3CF0EBB91 for ; Fri, 17 Dec 2004 03:50:46 +0100 (CET) Received: from demos.bsdclusters.com (demos.bsdclusters.com [69.55.225.36]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iBH2oihd024251 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 17 Dec 2004 03:50:45 +0100 Received: from demos.bsdclusters.com (demos [69.55.225.36]) by demos.bsdclusters.com (8.12.8p1/8.12.8) with ESMTP id iBH2ofl5091452; Thu, 16 Dec 2004 18:50:41 -0800 (PST) (envelope-from kmacy@fsmware.com) Received: from localhost (kmacy@localhost) by demos.bsdclusters.com (8.12.8p1/8.12.8/Submit) with ESMTP id iBH2ofRE091442; Thu, 16 Dec 2004 18:50:41 -0800 (PST) X-Authentication-Warning: demos.bsdclusters.com: kmacy owned process doing -bs Date: Thu, 16 Dec 2004 18:50:40 -0800 (PST) From: Kip Macy X-X-Sender: kmacy@demos.bsdclusters.com To: Julian Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Threaded ocaml code, native threads, and linux SMP In-Reply-To: Message-ID: <20041216184900.B90399@demos.bsdclusters.com> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 41C24984.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 threads:01 garbage:01 ocaml:01 threads:01 wrote:01 wrote:01 rec:01 ocamlopt:01 -thread:01 cmxa:01 cmxa:01 incorrectly:01 caml-list:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: MT garbage collection is both complex and fairly high in overhead. Ocaml only supports user level threads. If you want to use both processors you need to use multiple processes. -Kip On Fri, 17 Dec 2004, Julian wrote: > I wrote the following CPU-bound function in order to test the > Thread module in ocaml: > > let rec loop pair = match pair with > (100000, 50000) -> () > | ( i, 50000) -> loop (i+1, 0) > | ( i, j) -> loop (i, j+1) ;; > > This function was used in two test programs: > > * Version 1 * > > let t1, t2 = Thread.create loop (0,0), > Thread.create loop (0,0) ;; > > Thread.join t1;; > Thread.join t2;; > > > * Version 2 * > > loop (0,0); > loop (0,0);; > > > The test programs were each compiled with the following command: > (ocaml 3.08, debian sid, linux kernel 2.6): > > ocamlopt -thread -o unix.cmxa threads.cmxa .ml > > > I then tried running the two versions on an SMP machine. I found that > whereas I expected version 1 to run roughly twice as fast, they actually > took the same amount of time. > > Closer inspection using "ps" revealed that only one processor was being > used. When I wrote a similar test program in C, calling the pthread > functions directly, the threads were run on separate CPUs as expected. > > The "ldd" command reveals that the C version and the ocaml version were > relying on the same native pthread library. > > So why doesn't the ocaml version use 2 processors? > Is it a flaw with my program? > Did I compile the program incorrectly? > > > Thanks for any help you can give, > Julian > > _______________________________________________ > 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 >