From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,86cefd3e84a541f2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-19 13:46:53 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newspeer.monmouth.com!news.monmouth.com!shell.monmouth.com!not-for-mail From: ka@sorry.no.email (Kenneth Almquist) Newsgroups: comp.lang.ada Subject: Re: Parallel Merge Sort Date: 19 Feb 2002 16:46:42 -0500 Organization: A poorly-installed InterNetNews site Message-ID: References: <0sgb8.36$hk2.28284109@newssvr14.news.prodigy.com> NNTP-Posting-Host: shell.monmouth.com Xref: archiver1.google.com comp.lang.ada:20142 Date: 2002-02-19T16:46:42-05:00 List-Id: 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