[m-users.] Parallel execution in Mercury?

Peter Wang novalazy at gmail.com
Sat Jan 12 10:43:54 AEDT 2019


On Fri, 11 Jan 2019 13:43:56 +0100, Matthias G├╝demann <matthias.guedemann at googlemail.com> wrote:
> Hi Volker,
> 
> > There are a large amount of papers on parallelism on http://mercurylang.org/
> > documentation/papers.html, but I couldn't find anything in the Language
> > Reference Manual, User's Guide, Library Reference Manual and the FAQ.
> 
> I wrote an article about parallelism in Mercury a while ago
> http://guedemann.org/articles/Mar-17-2015.html
> 
> Maybe that is useful for you. In short, you need a parallel grade and
> you use the `&` conjunction.

Specifically you need a low-level C .par grade. The & operator acts
like normal conjunction in high-level C grades.

> There is also the `thread` module in the library, but I haven't used this yet.

This is a practical approach if you can identify coarse-grained (mostly)
independent tasks in your program. Spin up a bunch of worker threads,
push the tasks to the workers via a channel, wait for the workers to
finish, and aggregate the results. Just be careful if there are any
shared resources needed for the tasks.

Peter


More information about the users mailing list