From: Anonymous <nobody@remailer.paranoici.org>
Subject: begin/end reducing memory consumption?
Date: Fri, 22 Jun 2012 09:08:30 +0000 (UTC)
Date: 2012-06-22T09:08:30+00:00 [thread overview]
Message-ID: <f23f61a8c97862b4e94f337934edbdfd@remailer.paranoici.org> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3190 bytes --]
Hi all,
I'm currently evaluating Ada as an alternative to C++ for scientific programming. I have a simple test program that within its main loop repeatedly calls the following procedure:
procedure Propagate is
Access_Temp : constant Access_Probability_Field
:= Access_New_Field;
begin
Access_New_Field.all := (others => (others => (others => 0.0)));
for Nx in -Fringe_Index .. Fringe_Index loop
-- Fringe_Index = about 50
for Ny in -Fringe_Index .. Fringe_Index loop
for Ntheta in Angle_Index'Range loop
-- Range = 0 .. 199
begin -- why do I need this?
for W of Weight_Vectors (Ntheta) loop
-- Weight_Vectors (Ntheta) is a Vector of type Ada.Containers.Vectors
-- (Element_Type => Weight, Index_Type => Natural), where Weight is defined as
-- subtype Pixel_Offset is Integer range -Max_Offset .. Max_Offset;
-- type Weight is record
-- Nx, Ny : Pixel_Offset;
-- W : Long_Float;
-- end record;
for D_Index in Angular_Propagator'Range loop
Access_New_Field
(Nx + W.Nx, Ny + W.Ny, Ntheta + D_Index)
:= Access_New_Field -- (Nx, Ny + 1, Ntheta)
(Nx + W.Nx, Ny + W.Ny, Ntheta + D_Index)
+ Access_Old_Field (Nx, Ny, Ntheta) * W.W
* Angular_Propagator (D_Index);
end loop;
end loop;
end;
end loop;
end loop;
end loop;
Access_New_Field := Access_Old_Field;
Access_Old_Field := Access_Temp;
end Propagate;
Access_New_Field and Access_Old_Field are of type access Probability_Field, where
type Probability_Field is array
(Pixel_Index'Range, Pixel_Index'Range, Angle_Index'Range)
of Long_Float;
subtype Pixel_Index is Integer range
-(Fringe_Index + Max_Offset) .. (Fringe_Index + Max_Offset);
my main loop looks like this:
Access_New_Field := new Probability_Field;
Access_Old_Field := new Probability_Field;
for K in 1 .. No_Iterations loop
Put_Line ("Iteration " & Integer'Image (K));
Propagate;
end loop;
What I don't get is that if I comment out the above "begin/end" lines,
then memory usage increases with No_iterations and for No_iterations = 8
reaches about 550 MB. Including begin/end reduces memory usage to 37MB (then independent of No_iterations, as it should be). For what it's worth, I'm using the following compiler flags (with GNAT GPL 2011 on Mac OS X 10.7.4, 2010 MacBook Pro):
gnatmake -o Main Main -P"/Users/sebastian/Documents/Studium/Research/hard-disk-disorder/lattice-propagator/release.gpr" -g -cargs -gnatq -gnatQ -bargs -largs
gcc -c -gnatQ -O3 -gnatp -gnat2012 -g -gnatq -gnatQ -I- -gnatA [�]/Main.adb
gcc -c -gnatQ -O3 -gnatp -gnat2012 -g -gnatq -gnatQ -I- -gnatA [�]/lattice_propagator.adb
gcc -c -gnatQ -O3 -gnatp -gnat2012 -g -gnatq -gnatQ -I- -gnatA [�]/geometry.adb
gnatbind -E -static -I- -x [�]/obj/main.ali
gnatlink [�]/obj/main.ali -g -o [�]/build/Main
Is this expected behaviour? If yes, could someone please explain what's going on internally?
Best regards,
Sebastian
next reply other threads:[~2012-06-22 9:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-22 9:08 Anonymous [this message]
2012-06-22 11:10 ` begin/end reducing memory consumption? Georg Bauhaus
-- strict thread matches above, loose matches on Subject: below --
2012-06-24 13:57 Nomen Nescio
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox