From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 15 Sep 93 15:17:04 GMT From: cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland. reston.ans.net!vixen.cso.uiuc.edu!sdd.hp.com!col.hp.com!csn!news.den.mmc.com!ip lmail!alcyone!rgilbert@ucbvax. (Bob Gilbert) Subject: Re: Tasking in Ada Message-ID: <1993Sep15.151704.2790@iplmail.orl.mmc.com> List-Id: 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