From: cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland.
Subject: Re: Tasking in Ada
Date: 15 Sep 93 15:17:04 GMT [thread overview]
Message-ID: <1993Sep15.151704.2790@iplmail.orl.mmc.com> (raw)
In article 17841@rat.csc.calpoly.edu, kgatlin@galaxy.csc.calpoly.edu (Kang Su G
atlin) writes:
>Hello, I am currently working on a senior project in parallel algorithms but
>I am also going to implement some of them. One of the langueages that I'm
>using is Ada.
>
>I have hit a snag with Ada. I need to create dynamic tasks that know which
>task they are.
>
>For example I create n tasks. Task 1 knows it is task 1 and that there are
>n total tasks. Task 2 knows it is task 2 and that are n total tasks. Task
>n knows it is task n and that there are n total tasks.
>
>I can't seem to find a way to pass information to tasks efficiently. I want
>all the tasks to run simultaneously so that the creation and execution of
>the tasks can be done in t(1) time.
>
>The only way I can think of how to do it is to loop through and create the
>tasks but that is O(n) time. Or I can create an array of tasks (if that is
>possible) but then how do I get information to the tasks with using the
>rendezvous mechanism (again O(n)).
>
>All help is greatly appreciated, and methods used will be fully cited, so
>include all information you would like printed.
>
>Kang Su Gatlin
>
The following will create an array of n tasks:
task type Sample_Task;
task body Sample_Task is
begin
...
end Sample_Task;
type TASK_ARRAY is array (1 .. n) of Sample_Task;
Task_List : TASK_ARRAY;
Unfortunately each task, Task_List(i), does not know which task it is. You
can modify the task type to have an entry call to start the task and provide
a parameter such as a task ID. But this might not fit in with your desire to
have tasks elaborate simultaniously (assuming a true parallel environment exist
s
to accomplish this).
Another way to get each task assigned an unique ID would be to create a task to
assign IDs. As each of your tasks in the array begin execution, they could eac
h
rendezvous with this server task to get an unique ID. Example:
task ID_Manager is
entry Get_ID(ID : out INTEGER);
end ID_Manager;
task body ID_Manager is
Current_ID : INTEGER := 0;
begin
loop
accept Get_ID(ID : out INTEGER) do
ID := Current_ID;
Current_ID := Current_ID + 1;
end Get_ID;
end loop;
end ID_Manager;
task type Sample_Task;
task body Sample_Task is
ID : INTEGER;
begin
ID_Manager.Get_ID(ID);
...
end Sample_Task;
type TASK_ARRAY is array (1 .. n) of Sample_Task;
Task_List : TASK_ARRAY;
Now the above does not guarantee that the index of the task array will match th
e
ID each task receives, but it will guarantee unique IDs for each task.
If you need to create the tasks dynamically, you then create an access type of
the
task type. You could then create an array of these access objects if desired.
Example:
task type Sample_Task is ...
type SAMPLE_TASK_ACCESS is access Sample_Task;
type SAMPLE_TASK_ACCESS_LIST is array (1 .. n) of SAMPLE_TASK_ACCESS;
My_Task : SAMPLE_TASK_ACCESS_LIST;
begin
My_Task(i) := new Sample_Task; -- task object is created here.
if My_Task(i)'callable then -- make sure task is available befo
re
... -- any attempt to rendezvous.
Hope the above examples help or give you some ideas. Good luck.
Bob
next reply other threads:[~1993-09-15 15:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1993-09-15 15:17 cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland. [this message]
-- strict thread matches above, loose matches on Subject: below --
1993-09-17 14:37 Tasking in Ada Wes Groleau x1240 C73-8
1993-09-16 17:11 Wes Groleau x1240 C73-8
1993-09-15 18:51 Raymond Blaak
1993-09-15 17:34 Robert Kitzberger
1993-09-15 17:32 Mark A Biggar
1993-09-15 13:47 howland.reston.ans.net!wupost!cs.utexas.edu!utnut!utcsri!csri.toronto.edu
1993-09-15 4:16 Kang Su Gatlin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox