[m-users.] Parallel Mercury

Eduardo Costa edu500ac at gmail.com
Tue Nov 29 07:03:02 AEDT 2016


A few years ago, I tested Mercury for parallel programming. It worked very
well. In fact, with 8 CPUs, Mercury could beat a C program. Recently, I
tested the very same programs again, but this time Mercury refused to
parallelize the process. Gnome System Monitor shows a single CPU doing all
the work. Here is the program I borrowed from Paul Bone's thesis:

:- module fibgc.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.

:- import_module float,integer.
:- import_module solutions, io, int.
:- import_module string, char, list.

:- func fib(int, int) = int.

fib(N, Depth)= F :-
    ( N<2 -> F=1
     ;
     (Depth > 0 ->
          ( F1= fib(N-1, Depth - 1)
                   &
                   F2= fib(N-2, Depth-1) & F= F1+F2)
      ;
      F1= fib(N-1, 0), F2= fib(N-2,0), F= F1+F2)).

main(!S) :- command_line_arguments(Args, !S),
   ( to_int(head(Args), N),
     to_int(head(tail(Args)), D) ->
    F= fib(N, D),
    print(F, !S)
   print("Usage: ./fibo.x 5", !S)),
  nl(!S).

%% ~/mercuryTutor/mybook$ mmc --parallel \
%%     --high-level-code -j8 \
%%     --grade=hlc.par.gc fibgc.m -o fib.x

I wonder whether somebody in this list could tell me what is going on. By
the way, I tried the above program with NAIL Prolog, and it is able to
perform the parallelization. I mean, NAIL Prolog does the parallelization,
not Mercury.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20161128/74b11c3e/attachment.html>


More information about the users mailing list