comp.lang.ada
 help / color / mirror / Atom feed
From: Brian Drummond <brian_drummond@btconnect.com>
Subject: Re: Need some light on using Ada or not
Date: Sun, 20 Feb 2011 14:34:35 +0000
Date: 2011-02-20T14:34:35+00:00	[thread overview]
Message-ID: <eh82m6db82blahcgpmm4ufi192ok1tuikt@4ax.com> (raw)
In-Reply-To: kf10m69ihv8g49n8j5pemnu8fajo1r8l6k@4ax.com

On Sat, 19 Feb 2011 18:25:44 +0000, Brian Drummond
<brian_drummond@btconnect.com> wrote:

>On Sat, 19 Feb 2011 15:36:45 +0100, Georg Bauhaus
><rm-host.bauhaus@maps.futureapps.de> wrote:
>
>>On 2/19/11 2:07 PM, Brian Drummond wrote:
>>> On 18 Feb 2011 22:52:38 GMT, "Luis P. Mendes"<luislupeXXX@gmailXXX.com>  wrote:
>>
>>>> I have some questions, however, that I'd like to be answered:
>>>> 1. If Ada is more type safe and restricted than C++, how can it be
>>>> significantly slower?
>>> Two possible reasons; both come down to the relative number of people developing
>>> for both languages.

[using tasking for the binary_trees benchmark, which currently uses a single
task...]
>>I vaguely remember that it has been tried before, but so far there
>>is no better solution.

>I have broken down and finally started to learn Ada's tasking. So far I have
>gone from 56s (CPU) 56s (elapsed) with one task, to 120s (CPU), 64s(elapsed)
>with multiple tasks (on a smallish 2-core laptop)... 
>
>Disappointing.
>
>(If anybody's interested, I am using 9 tasks, one per "Depth" value in the main
>while loop. 

Further odd results. I re-structured the tasking so that I could modify the
number of tasks, from 1, 2, 4, etc. The "CPU" utilisation remains virtually
identical, at 2 minutes; the elapsed time is 2 minutes with 1 task, or 1 minute
with 2 or more (on a 2-core laptop. I'll report on a 4-core later).

Moving from GCC4.5.0 (FSF) to Adacore Libre 2010 makes no significant
difference. (OpenSuse 11.3, 64-bit, 2-core laptop)

Doubling the CPU time with a single task is suspicious, so I tried the following
experiment : source code below - main program only. For the rest, and the
original version, see
http://shootout.alioth.debian.org/u64q/performance.php?test=binarytrees

I removed virtually the entire body of the program into a single task.
This change alone doubles the "CPU" time. There appears to be a 100% penalty
associated simply with running the original program from within a second task.

Anyone see what I'm doing wrong?
Any pitfalls to using tasking that I may have missed?

I suspect storage [de]allocation since that's under stress in this test, and
other benchmarks (e.g. Mandelbrot) don't see this penalty.
Should the task have its own separate storage pool, to avoid difficulties
synchronising with the main pool (even though the main program no longer uses
it?


----------------------------------------------------------------
-- BinaryTrees experimental version
--
-- Ada 95 (GNAT)
--
-- Contributed by Jim Rogers
-- Tasking experiment:  Brian Drummond
----------------------------------------------------------------
with Treenodes; use Treenodes;
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;

procedure Binarytrees_tasktest is

   N : Natural := 1;

   task the_work is
      entry Start(Count :in Natural);
      entry Complete;
   end the_work;

   task body the_work is
      Min_Depth : constant Positive := 4;
      Stretch_Tree : TreeNode;
      Long_Lived_Tree : TreeNode;
      Short_Lived_Tree_1 : TreeNode;
      Short_Lived_Tree_2 : TreeNode;
      Max_Depth : Positive;
      Stretch_Depth : Positive;
      Check : Integer;
      Sum : Integer;
      Depth : Natural;
      Iterations : Positive;
   begin

      accept Start(Count :in Natural) do
         N := Count;
      end Start;

      Max_Depth := Positive'Max(Min_Depth + 2, N);
      Stretch_Depth := Max_Depth + 1;
      Stretch_Tree := Bottom_Up_Tree(0, Stretch_Depth);
      Item_Check(Stretch_Tree, Check);
      Put("stretch tree of depth ");
      Put(Item => Stretch_Depth, Width => 1);
      Put(Ht & " check: ");
      Put(Item => Check, Width => 1);
      New_Line;
   
      Long_Lived_Tree := Bottom_Up_Tree(0, Max_Depth);
   
      Depth := Min_Depth;
      while Depth <= Max_Depth loop
         Iterations := 2**(Max_Depth - Depth + Min_Depth);
         Check := 0;
         for I in 1..Iterations loop
            Short_Lived_Tree_1 := Bottom_Up_Tree(Item => I, Depth => Depth);
            Short_Lived_Tree_2 := Bottom_Up_Tree(Item =>-I, Depth => Depth);
            Item_Check(Short_Lived_Tree_1, Sum);
            Check := check + Sum;
            Item_Check(Short_Lived_Tree_2, Sum);
            Check := Check + Sum;
         end loop;
         Put(Item => Iterations * 2, Width => 0);
         Put(Ht & " trees of depth ");
         Put(Item => Depth, Width => 0);
         Put(Ht & " check: ");
         Put(Item => Check, Width => 0);
         New_Line;
         Depth := Depth + 2;
      end loop;
      Put("long lived tree of depth ");
      Put(Item => Max_Depth, Width => 0);
      Put(Ht & " check: ");
      Item_Check(Long_Lived_Tree, Check);
      Put(Item => Check, Width => 0);
      New_Line;
      accept Complete;
   end the_work;

begin
   if Argument_Count > 0 then
      N := Positive'Value(Argument(1));
   end if;
   the_work.start(N);
   the_work.complete;
end BinaryTrees_tasktest;

------------------------------------------------------



  reply	other threads:[~2011-02-20 14:34 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18 22:52 Need some light on using Ada or not Luis P. Mendes
2011-02-18 23:58 ` Georg Bauhaus
2011-02-19 14:25   ` Simon Wright
2011-02-19  0:20 ` Edward Fish
2011-02-20  0:13   ` Luis P. Mendes
2011-02-20  1:36     ` Marc A. Criley
2011-02-20  9:59     ` mockturtle
2011-02-20 10:37     ` Brian Drummond
2011-02-20 11:08     ` Ludovic Brenta
2011-03-01  8:10     ` Adrian Hoe
2011-03-01  8:29       ` Thomas Løcke
2011-03-04 13:34         ` Adrian Hoe
2011-02-19  8:43 ` Vadim Godunko
2011-02-19 13:07 ` Brian Drummond
2011-02-19 14:17   ` Simon Wright
2011-02-19 18:02     ` Brian Drummond
2011-02-19 18:07       ` Bill Findlay
2011-02-20 10:42         ` Brian Drummond
2011-02-19 14:36   ` Georg Bauhaus
2011-02-19 18:25     ` Brian Drummond
2011-02-20 14:34       ` Brian Drummond [this message]
2011-02-20 15:45         ` jonathan
2011-02-20 16:18           ` Brian Drummond
2011-02-20 19:49           ` Pascal Obry
2011-02-20 19:57             ` Brian Drummond
2011-02-20 20:10               ` jonathan
2011-02-20 21:15                 ` Pascal Obry
2011-02-20 21:26                   ` Vinzent Hoefler
2011-02-20 21:33                     ` Vinzent Hoefler
2011-02-20 21:36                     ` Pascal Obry
2011-02-20 21:50                       ` Vinzent Hoefler
2011-02-20 22:18                   ` jonathan
2011-02-20 22:47               ` Simon Wright
2011-02-21 12:52                 ` Brian Drummond
2011-02-21 13:44                   ` Simon Wright
2011-02-24  0:19                     ` Brian Drummond
2011-02-24  7:41                       ` Jacob Sparre Andersen
2011-02-22  2:15                   ` Shark8
2011-02-20 16:42       ` jonathan
2011-02-20 20:02         ` Brian Drummond
2011-02-20  0:20   ` Luis P. Mendes
2011-02-20 10:50     ` Brian Drummond
2011-02-20 19:54     ` Brian Drummond
2011-02-23 22:19       ` Luis P. Mendes
2011-02-24 17:06         ` Brian Drummond
2011-02-27 17:51           ` Luis P. Mendes
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox