From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 8D7EDBC57 for ; Sat, 20 Nov 2010 21:57:54 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AokDACfF50zZSMDdX2dsb2JhbACiZQsXCQYGBRMDH7oShUsEjWw X-IronPort-AV: E=Sophos;i="4.59,229,1288566000"; d="scan'208";a="67596309" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail3-smtp-sop.national.inria.fr with ESMTP; 20 Nov 2010 21:57:54 +0100 Received: from smtp03.web.de ( [172.20.0.65]) by fmmailgate01.web.de (Postfix) with ESMTP id 7BDC017ACF56A; Sat, 20 Nov 2010 21:57:53 +0100 (CET) Received: from [78.43.204.177] (helo=frosties.localdomain) by smtp03.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #24) id 1PJuVN-0008Ff-00; Sat, 20 Nov 2010 21:57:53 +0100 Received: from mrvn by frosties.localdomain with local (Exim 4.72) (envelope-from ) id 1PJuVM-0007ZB-PM; Sat, 20 Nov 2010 21:57:52 +0100 From: Goswin von Brederlow To: Jon Harrop Cc: "'Goswin von Brederlow'" , Subject: Re: [Caml-list] SMP multithreading References: <8762vwdx09.fsf@frosties.localnet> <4CE46063.5080703@univ-savoie.fr> <20101119.100131.1002056833324939968.Christophe.Troestler+ocaml@umons.ac.be> <87pqu1l305.fsf@frosties.localnet> <04be01cb88a9$d2df4810$789dd830$@com> Date: Sat, 20 Nov 2010 21:57:52 +0100 In-Reply-To: <04be01cb88a9$d2df4810$789dd830$@com> (Jon Harrop's message of "Sat, 20 Nov 2010 11:55:26 -0000") Message-ID: <87hbfb3e7j.fsf@frosties.localnet> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1/ZXx4aDFCrxOOk6FgydeOavjypCwZCFYslm4Gw ItxwFSUziHaAHjwL3veTZyQR6YojHML1QbxUY9Uqjr4Q8L7gG1 Myqaa1Bps= X-Spam: no; 0.00; ocaml:01 parallelism:01 cheers:01 parallelism:01 ocaml:01 bigarray:01 mfg:98 threads:01 rewrite:01 caml-list:01 writes:01 data:02 data:02 restrict:02 string:02 Jon Harrop writes: >> This is actually a quick way to use multiple cores with ocaml. Find a >> often called function that takes considerable time and offload it to C > > Or HLVM, F#, Scala, Clojure or any of the other languages that permit shared > memory parallelism. C is particularly poor in this regard so I would not > just restrict yourself to C... > > Cheers, > Jon. I'm not talking about any shared memory parallelism here. The parallelism is completly restricted to the ocaml side. You just find some single threaded job that takes long, rewrite it as external function and release the ocaml lock while it is running. For example in my code I compute the sha256 sum of a block of data. Since I use a C library for sha256 anyway the function is already external. All I had to do was switch the interface from using string to Bigarray and add enter/leave_blocking_section(). After that multiple threads can compute the sha256 sum for blocks of data in parallel and my code run 3.7 times faster with 4 cores. MfG Goswin