caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Ekstrand <michael@elehack.net>
To: caml-list@inria.fr
Subject: Re: OCaml runtime lock does not seem pathological
Date: Mon, 29 Jun 2009 20:31:51 -0500	[thread overview]
Message-ID: <87ocs6zeuw.fsf@jehiel.elehack.net> (raw)
In-Reply-To: <874otz0xz2.fsf@jehiel.elehack.net>

[-- Attachment #1: Type: text/plain, Size: 1758 bytes --]

Michael Ekstrand <michael+ocaml@elehack.net> writes:
> The basic test which demonstrated this problem was a simple loop
> counting down from 100000000.  On Python, if two such loops are run in
> parallel using threads on a multicore machine, the program takes
> substantially longer to finish if the loops are run sequentially.
> Disabling one core speeds the program up, but it doesn't recover all of
> its original speed.
>
> I duplicated this test with the following code:
>
> let rec count n =
>     if n <= 0 then ()
>     else count (pred n)
> ;;
>
> (* count 100000000;; *)
> (* count 100000000;; *)
>
> let t1 = Thread.create count 100000000;;
> let t2 = Thread.create count 100000000;;
> Thread.join t1;;
> Thread.join t2;;

Philippe Wang kindly told me that this isn't accurately measuring the
potential problem as it is not allocating any memory and thus not
triggering thread switching.  I have therefore modified it to use
Int64's and also to allocate an array of 32 ints in each iteration of
the loop.  The resulting program runs at equivalent speed both
sequentially and in parallel with both cores enabled (perhaps slightly
slower in parallel, but not significantly at all).  Running the
parallelized version with one core disabled does result in a noticeable
slowdown (runtime goes from 8.86s to 9.63s, but still not on the scale
reported for Python.  So it does seem that, unless I am still not doing
sufficient tests to detect a problem, OCaml has avoided Python's
problem.

- Michael

-- 
mouse, n: A device for pointing at the xterm in which you want to type.
Confused by the strange files?  I cryptographically sign my messages.
For more information see <http://www.elehack.net/resources/gpg>.

[-- Attachment #2: Type: application/pgp-signature, Size: 196 bytes --]

      reply	other threads:[~2009-06-30  1:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-29 17:08 Michael Ekstrand
2009-06-30  1:31 ` Michael Ekstrand [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ocs6zeuw.fsf@jehiel.elehack.net \
    --to=michael@elehack.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).