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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,10d1a90a699d6cfc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Ada tasking question Date: Wed, 18 Apr 2007 22:50:21 +0300 Message-ID: <58nb3uF2gtp0vU1@mid.individual.net> References: <20070418201307.18a85fd9@cube.tz.axivion.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: individual.net /N1D5DSgd9kSyJGx+ZEMCQG8cyl6VOUxqIlgkjt+Ar4R9w0No= User-Agent: KNode/0.10.4 Xref: g2news1.google.com comp.lang.ada:15102 Date: 2007-04-18T22:50:21+03:00 List-Id: Stefan Bellon wrote: > Hi all! > > Although I am quite familiar with Ada, tasking is quite new to me, so > please bear with me with my question. ;-) > > I have a set of buckets where I do have to do some processing on them. > This processing can be done in parallel for each bucket. The results > of the processing however are accumulated into another data structure. > > At present I have task types for the processing of the buckets, an > access type to the task type and basically just do: > > declare > type Task_Access is access all Task_Type; > My_Task : Task_Access; > begin > for I in Buckets'Range loop > My_Task := new Task_Type'(Buckets (I)); Be aware that this causes heap consumption. That is, a finished task doesn't just vanishes, it has some heap used for task context that is not automatically released. To properly free a task access you must ensure that the task is terminated (My_Task'Terminated) before doing an Unchecked_Deallocation. If you try to free an unfinished task, the call won't fail but the task context memory won't be freed... I have only GNAT experience though. > end loop; > end; > > The result data structure is a protected object with an entry Add that > adds the processing result to the container and which is called by the > task body. > > All is well so far. > > However the number of buckets may be quite large and I have the feeling > that the context switching which is needed for say 1000 or more tasks > eats up the gain of the parallelism. At least in my test cases I do not > gain anything at all on a Core Duo system. > > Therefore I have the idea of just starting N tasks in parallel (where N > can be specified by the user e.g. according to the number of CPU cores > of the machine) instead of tasks for all buckets at once. > > Starting N tasks, then waiting for them to get all finished and only > then starting the next N tasks is not difficult. But how would I do it, > so that there are always N tasks running (apart of course when > everything has been processed) and that a new tasks is starting on the > next bucket as soon as a task on a previous bucket has finished? > > Any ideas are very welcome! >