caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Roberto Di Cosmo <roberto@dicosmo.org>
To: caml-list@inria.fr
Cc: roberto@dicosmo.org, marcod@di.unipi.it
Subject: [Caml-list] [ANN]: Parmap
Date: Wed, 17 Aug 2011 19:10:35 +0200	[thread overview]
Message-ID: <20110817171035.GA8231@voyager> (raw)

Dear all,
       a few lines to announce the availability of a minimalistic library which
can be useful to exploit your multicore processor with minimal modifications to
your OCaml programs.

In a nutshell
-------------

If you want to use your many cores to accelerate an operation which happens to
be a map, fold or map/fold (map-reduce), just use Parmap's parmap, parfold and
parmapfold primitives in place of the standard List.map and friends, and specify
the number of subprocesses to use by the optional parameter ncores.

For example, in the classical Mandelbrot example present in the example directory,
the line 

	Parmap.parmap pixel tasks ~ncores:i

allows to spawn i separate processes, each working on 1/ith of the list tasks.

Rationale
---------

The principle of Parmap is very simple: when you call one of the three available
primitives, map, fold, and  mapfold , your OCaml  sequential program forks  in n
subprocesses (you choose the n), and each subprocess performs the computation on
the  1/n of the data, returing  the results through a  shared memory area to the
parent process, that resumes  execution once all  the children  have terminated,
and the data has been recollected.

This means that you *must* run your program on a *single* multicore machine.
Repeat after us: Parmap is not meant to run on a cluster, see one of the many
available (re)implementations of the map-reduce schema for that.

By forking the parent process  on a sigle  machine, the children get access, for
free, to all the data structures already built, even the imperative ones, and as
far as your computation  inside the map/fold  does not produce side effects that
need  to be  preserved, the  final result will   be the same  as  performing the
sequential operation, the only difference is that you might get it faster.

Of course, if you happen  to have open  channels, or files, or other connections
that should only be  used by the parent  process, your program  may behave in  a
very wierd way: as an example, *do  not* open a  graphic window before calling a
Parmap primitive, and   *do   not*  use  this  library   if  your  program    is
multi-threaded!

The OCaml code is quite simple and does not rely on any  external C library: all
the magic is done by your operating system's fork and memory mapping mechanisms.
One could gain some speed by implementing a marshal/unmarshal operation directly
on bigarrays, but we did not do this yet.


How to get it
-------------

Project home: https://gitorious.org/parmap

To compile and install:

 git clone git://gitorious.org/parmap/parmap.git
 make
 make install

Enjoy

-- Marco Danelutto and Roberto Di Cosmo

P.S.: special thanks to Pierre Chambart for useful discussions on this code






             reply	other threads:[~2011-08-17 17:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-17 17:10 Roberto Di Cosmo [this message]
2011-08-17 19:25 ` Ashish Agarwal
2011-08-18 10:16   ` Roberto Di Cosmo

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=20110817171035.GA8231@voyager \
    --to=roberto@dicosmo.org \
    --cc=caml-list@inria.fr \
    --cc=marcod@di.unipi.it \
    /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).