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,9bc0262607f781e9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-07 06:31:33 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!colt.net!newsfeed00.sul.t-online.de!t-online.de!blackbush.xlink.net!blackbush.de.kpnqwest.net!rz.uni-karlsruhe.de!schlund.de!news.online.de!not-for-mail From: "Dr. Michael Paus" Newsgroups: comp.lang.ada Subject: Re: Making a package safe for use by multiple tasks Date: Fri, 07 Jun 2002 15:31:31 +0200 Organization: 1&1 Internet AG Message-ID: <3D00B5B3.9090409@ib-paus.com> References: NNTP-Posting-Host: p50830174.dip0.t-ipconnect.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.online.de 1023456692 1246 80.131.1.116 (7 Jun 2002 13:31:32 GMT) X-Complaints-To: abuse@online.de NNTP-Posting-Date: 7 Jun 2002 13:31:32 GMT User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0rc1) Gecko/20020417 X-Accept-Language: en-us, en Xref: archiver1.google.com comp.lang.ada:25451 Date: 2002-06-07T13:31:32+00:00 List-Id: Alexander Boucke wrote: > I am just playing with the idea to use multiple tasks in a programm doing > linear algebra. The problem lies in my vector-algebra package, that uses > some global tmp-object to optimize memory use and reuse. To give you the > idea, some not necessarily correct code snippets what this is doing: I do not see how the approach you have shown in you example contributes to your goals to optimize memory use and reuse. What's the problem with the following modification to your code? function "+" (left, right : vector) return vector is tmp_vec : vector; begin for i in tmp_vec'range loop tmp_vec(i) := left(i) + right(i); end loop; return tmp_vec; end "+"; Making tmp_vec a local variable has the following advantages: - You don't have any problems with tasking (of course the stack size must be big enough to hold this array). - You don't have any problems with recursive calls (this is no problem here but is a general problem with static variables). - You do not have to consider special cases, e.g. what actually happens if you do this? x := a + (b + c); The first call to "+" will pass the access values a and b to the function which will place its result into the memory where tmp_vec points to. In the second call to "+" the left argument will be a and the right one will be tmp_vec. Now in this specific example the result will be correct but try to figure out what happens if you write a function which computes the cross product of the two vectors according to the same scheme. Your code will fail! Generally, using access types in linear algebra packages like this is VERY dangerous. - The performance should be the same or even better than in the original example (cpu cache). - Memory usage is actually better here because tmp_vec will be put on the stack and so this memory can be used for other things when the function has been finished. In the other case the memory for tmp_vec is occupied for the whole runtime of the program. Imagine you have 10 packages which use the same scheme. The memory for all these temporary variables will be occupied the whole time although you may be using only one of the packages at the same time. So all in all I think that your solution is actually counter productive with respect to the goals you have stated. Michael