[m-rev.] for review: smaller stacks for parallel conjuncts

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Oct 2 12:26:50 AEST 2006


On Fri, 29 Sep 2006, Peter Wang wrote:

> Estimated hours taken: 6
> Branches: main
>
> A common way to use parallel conjunction can cause a lot of Mercury contexts
> to be allocated, e.g.
>
>    map([], []).
>    map([H0|T0], [H|T]) :-
> 	( p(H0, H)	% contains no parallel conjunctions
> 	& map(T0, T)
> 	).
>
> When the left parallel conjunct completes, the engine that was executing it
> must suspend the context in which it was run, waiting for the right conjunct
> to finish.  The engine is then idle and will attempt to find further work to
> execute in a _new_ context.  To avoid excessive memory consumption due to
> contexts we currently limit the number of contexts we allocate.  However,
> that severely limits the parallelism we can exploit in this example (and
> similar patterns of work distribution).  There are a lot of contexts
> allocated but most of them are simply suspended.
>
> Assuming that most parallel conjuncts contain small sub-computations, we can
> allow many contexts to be allocated without excessive memory consumption by
> just giving them smaller stacks.  This patch creates a simple variant of a
> MR_Context structure which has smaller stacks than the initial MR_Context
> structure and executes parallel conjuncts in the smaller contexts if
> larger contexts are unavailable.

Presumably you've measured the performance impact of this on parallel
conjucts?

> Index: doc/user_guide.texi
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/doc/user_guide.texi,v
> retrieving revision 1.493
> diff -u -r1.493 user_guide.texi
> --- doc/user_guide.texi	25 Sep 2006 08:00:38 -0000	1.493
> +++ doc/user_guide.texi	28 Sep 2006 05:31:03 -0000
> @@ -8537,6 +8537,36 @@
> multiplied by the word size in bytes.
>
> @sp 1
> + at item --small-detstack-size @var{size}
> + at findex --small-detstack-size (runtime option)
> +Sets the size of the det stack used for executing parallel conjunctions
> +to @var{size} kilobytes.
> +The regular det stack size should be equal or greater to avoid surprises.

The initialisation code in the runtime should check that this is the case and
abort (with a suitable error message) if not.  The documention here should say
that is the case rather than some vague mention of surprises.  (Similarly for
the nondet stack etc.)

The rest looks okay.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list