Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Kip Macy <kmacy@fsmware.com>
To: Julian <chasm@rift.sytes.net>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Threaded ocaml code, native threads, and linux SMP
Date: Thu, 16 Dec 2004 18:50:40 -0800 (PST)	[thread overview]
Message-ID: <20041216184900.B90399@demos.bsdclusters.com> (raw)
In-Reply-To: <E1Cf7ZG-0001Vp-00@galileo.rift>

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 <name> unix.cmxa threads.cmxa <name>.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
>


      reply	other threads:[~2004-12-17  2:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-17  2:10 Julian
2004-12-17  2:50 ` Kip Macy [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=20041216184900.B90399@demos.bsdclusters.com \
    --to=kmacy@fsmware.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=chasm@rift.sytes.net \
    /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