comp.lang.ada
 help / color / mirror / Atom feed
From: ka@sorry.no.email (Kenneth Almquist)
Subject: Re: Parallel Merge Sort
Date: 19 Feb 2002 16:46:42 -0500
Date: 2002-02-19T16:46:42-05:00	[thread overview]
Message-ID: <a4uh42$lv9$1@shell.monmouth.com> (raw)
In-Reply-To: 0sgb8.36$hk2.28284109@newssvr14.news.prodigy.com

tmoran@acm.org wrote:
>>   accept doSort(InArray : in out element_array) do
>>     ** How to get the InArray to be used outside the doSort?? **
>>     -- Synchronize with the caller but return control
>>   end doSort;
>   You'll have to copy InArray, since you only have access to it for
> the (short) time you are between the "accept" and the "end doSort".

The alternative is to have the task directly access the data to be sorted.

-- Sort the elements stored in array A.  The remaining parameters are
-- there to let us mimimize memory usage.  B is an array with the same
-- bounds as A, used for scratch storage.  If Store_In_B is true, then
-- the result will be placed in B rather than A.

procedure Parallel_Sort(A, B : in out Element_Array; Store_In_B : Boolean) is

    task type Sort_Task (First, Last : Positive) is
        -- no entries;
    end  Sort_Task;

    task body Sort_Task is
    begin
        Parallel_Sort(A(First .. Last), B(First .. Last), not Store_In_B);
    end Sort_Task;

    ...

begin
    ...

    -- Split the data into two halves and sort them recursively.
    Split := A'First + Size/2;
    declare
	Task_1 : Sort_Task(A'First, Split);
	Tast_2 : Sort_Task(Split + 1, A'Last);
    begin
	-- Nothing to do here except wait for the tasks to complete,
	-- and we don't have to write any code to do that.  In Ada,
	-- when a task goes out of scope we automaticly block until
	-- the task completes.
	null;
    end;

    -- Now merge the two halves.  If Store_In_B is true, then the
    -- two halves are stored in A; otherwise they are in B.
    ...

end Parallel_Sort;

				Kenneth Almquist



  parent reply	other threads:[~2002-02-19 21:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-15 21:34 Parallel Merge Sort R. Stegers
2002-02-15 21:46 ` Pat Rogers
2002-02-19  6:16   ` Adrian Hoe
2002-02-19  6:21   ` Adrian Hoe
2002-02-15 23:02 ` tmoran
2002-02-16 11:09   ` R. Stegers
2002-02-18 10:22     ` Peter Hermann
2002-02-18 20:41       ` R. Stegers
2002-02-18 21:02   ` R. Stegers
2002-02-18 22:29     ` Jeffrey Carter
2002-02-18 22:55     ` tmoran
2002-02-19 21:46   ` Kenneth Almquist [this message]
2002-02-24  3:22 ` Nick Roberts
2002-02-26 20:39   ` R. Stegers
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox