From: "R. Stegers" <rstegers@cs.vu.nl>
Subject: Re: Parallel Merge Sort
Date: Sat, 16 Feb 2002 12:09:18 +0100
Date: 2002-02-16T12:09:18+01:00 [thread overview]
Message-ID: <a4lenu$i9$1@star.cs.vu.nl> (raw)
In-Reply-To: 0sgb8.36$hk2.28284109@newssvr14.news.prodigy.com
Thanks a lot, this is exactly what I needed to know!
<tmoran@acm.org> schreef in bericht
news:0sgb8.36$hk2.28284109@newssvr14.news.prodigy.com...
> > - How can I dynamicaly allocate a temporary array (for which i don't
know
> > the size in advance?) It seems inpossible to me.
> > - How to create tasks from within a task: The subTask1 en subTask2
> > declarations generate errors: "Task type cannot be used as type mark
within
> > its own body"
>
> Consider what would happen if you created an object of type
MergeSortTask
> where:
> > task body MergeSortTask is
> > subTask1 : MergeSortTask;
> > subTask2 : MergeSortTask;
> > begin
> > ...
> That object will require creation of two more MergeSortTasks, each of
> which will create two more ..., all before you've even found out if
there's
> any data to sort. So you will have to create the subtasks dynamically.
> type Pointer_To_MergeSortTask is access MergeSortTask;
> task body MergeSortTask is
> subTask1 : Pointer_To_MergeSortTask;
> subTask2 : Pointer_To_MergeSortTask;
> begin
> ...
> if (**array size > 1 element**)
> -- Actually sort the array here
> subTask1 := new MergeSortTask;
> subTask2 := new MergeSortTask;
> subTask1.doSort(**<1st half>**);
> subTask2.doSort(**<2nd half>**);
>
> -- Wait till both sub-task have finished sorting
> subTask1.awaitResult;
> subTask2.awaitResult;
>
>
> > 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".
> You can't create the copy on the stack "Copy : element_array := InArray;"
> since of course the stack is cut back at "end doSort", so you'll have
> to create the copy on the heap and manually free it.
> type Pointer_To_Element_Array is access Element_Array;
> ...
> -- then inside the task body:
> My_Data : Pointer_To_Element_Array;
> ...
> accept doSort(InArray : in out element_array) do
> -- Create a local copy of InArray on the heap
> My_Data := new Element_Array'(InArray);
> -- Synchronize with the caller but return control
> end doSort;
>
> But this is not what you want, of course, since it does not sort
> InArray, but only a copy of it. In particular, the code
> baseTask.doSort(InArray);
> won't sort InArray - it will merely start up, and not wait for, a
> set of tasks that will sort a copy of InArray. One possible solution
> is to make
> entry doSort (InArray : in element_array);
> entry awaitResult(InArray : out element_array);
> and return the sorted result at awaitResult time.
next prev parent reply other threads:[~2002-02-16 11:09 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 [this message]
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
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