From: "Dr. Michael Paus" <paus@ib-paus.com>
Subject: Re: Making a package safe for use by multiple tasks
Date: Fri, 07 Jun 2002 15:31:31 +0200
Date: 2002-06-07T13:31:32+00:00 [thread overview]
Message-ID: <3D00B5B3.9090409@ib-paus.com> (raw)
In-Reply-To: adq0le$2np$1@nets3.rz.RWTH-Aachen.DE
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
next prev parent reply other threads:[~2002-06-07 13:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-07 10:07 Making a package safe for use by multiple tasks Alexander Boucke
2002-06-07 11:11 ` Marc A. Criley
2002-06-07 11:47 ` Alexander Boucke
2002-06-07 13:31 ` Dr. Michael Paus [this message]
2002-06-07 13:44 ` Making a package safe for use by multiple tasks (Correction) Dr. Michael Paus
2002-06-07 15:00 ` Making a package safe for use by multiple tasks Ted Dennison
2002-06-07 16:37 ` Georg Bauhaus
2002-06-07 21:16 ` Jeffrey Carter
2002-06-08 13:14 ` Craig Carey
2002-06-08 13:39 ` Dr. Michael Paus
-- strict thread matches above, loose matches on Subject: below --
2002-06-07 10:14 Grein, Christoph
2002-06-07 10:29 ` Alexander Boucke
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox