comp.lang.ada
 help / color / mirror / Atom feed
* Problems with Ada.Real_Time on GNAT?
@ 2002-05-16 19:33 file13
  2002-05-16 20:18 ` Florian Weimer
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: file13 @ 2002-05-16 19:33 UTC (permalink / raw)


Hi guys.  There was a silly little contest on a web BBS where people
were asked to write a program in any language (rules in the source). 
I decided to represent for us Ada folks and produced this on GNAT 3.14
on Windows 2000

http://www.qlippoth.com/shuffle.adb

It works fine under Windows 2000 but on Linux under both 3.13 and 3.14
I (and the guy who is testing all the programs) keep getting
segmentation faults when run.  I've compiled it safetly (without the
-gnatp) but still the same seg fault.

So I have 2 questions:

1.  Is there an error in the program itself (am I doing something
wrong--is that the correct way to time a part of a program)?
2.  Is there a problem with the Real_Time annex under Linux or is this
caused by something else?

On Linux I'm using the GNU Ada RPMS's for 3.13 and the Linux bin from
ACT for 3.14 under Mandrake 8.0 (2.4.3).

Thanks in advance!

file13
http://www.qlippoth.com/



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Problems with Ada.Real_Time on GNAT?
  2002-05-16 19:33 Problems with Ada.Real_Time on GNAT? file13
@ 2002-05-16 20:18 ` Florian Weimer
  2002-05-16 20:53   ` David C. Hoos
  2002-05-17  4:36 ` Per Sandbergs
  2002-05-27  2:42 ` Robert I. Eachus
  2 siblings, 1 reply; 10+ messages in thread
From: Florian Weimer @ 2002-05-16 20:18 UTC (permalink / raw)


file13@qlippoth.zzn.com (file13) writes:

> http://www.qlippoth.com/shuffle.adb
>
> It works fine under Windows 2000 but on Linux under both 3.13 and 3.14
> I (and the guy who is testing all the programs) keep getting
> segmentation faults when run.

You are hitting the 2 MB stack size limit.  You should allocate the
large array using an allocator.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Problems with Ada.Real_Time on GNAT?
  2002-05-16 20:18 ` Florian Weimer
@ 2002-05-16 20:53   ` David C. Hoos
  2002-05-17  6:57     ` Florian Weimer
  0 siblings, 1 reply; 10+ messages in thread
From: David C. Hoos @ 2002-05-16 20:53 UTC (permalink / raw)



----- Original Message -----
From: "Florian Weimer" <fw@deneb.enyo.de>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Thursday, May 16, 2002 3:18 PM
Subject: Re: Problems with Ada.Real_Time on GNAT?


> file13@qlippoth.zzn.com (file13) writes:
>
> > http://www.qlippoth.com/shuffle.adb
> >
> > It works fine under Windows 2000 but on Linux under both 3.13 and 3.14
> > I (and the guy who is testing all the programs) keep getting
> > segmentation faults when run.
>
> You are hitting the 2 MB stack size limit.  You should allocate the
> large array using an allocator.

With all due respect, I submit that the problem is _not_ the stack limit,
but, rather the fact that to use the real-time annex, one must compile and
link
with the FSU threads run-time, instead of the Linux-native threads run-time.

One disadvantage of running under the FSU run-time, is that processes must
run with root privileges -- e.g., by means of setuid permissions and root
ownership of the executable.

Instead, I chose to use the facilities of Ada.Calendar, and I also took the
liberty
of showing a better way to define the types, and cleaning up the output by
limiting the number of values on a line to ten.

Here is the modified code -- it should run correctly under either run-time:

with Ada.Calendar;
with Ada.Numerics.Discrete_Random;
with Ada.Text_IO;
procedure Shuffle is

   subtype Index is Integer range 1 .. 1000000;

   --  Regular vars
   List   : array (Index) of Integer;
   X, Tmp : Integer;

   --  Timing stuff
   Start  : Ada.Calendar.Time;
   Finish : Ada.Calendar.Time;

   --  Random integer stuff
   package Rand is new Ada.Numerics.Discrete_Random (Index);
   Seed : Rand.Generator;
   use type Ada.Calendar.Time;
begin

   Rand.Reset (Seed);

   --  Populate List
   Ada.Text_IO.Put_Line
     ("Populating collection list...");
   for I in List'Range loop
      List (I) := I;
   end loop;

   --  Shuffle
   Ada.Text_IO.Put_Line
     ("Randomizing collection list.  Starting timer:");
   Start := Ada.Calendar.Clock;

   for I in List'Range loop
      X := Rand.Random (Seed);
      Tmp := List (I);
      List (I) := List (X);
      List (X) := Tmp;
   end loop;

   Finish := Ada.Calendar.Clock;
   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line
     ("Time to shuffle in seconds:" & Duration'Image (Finish - Start));

   --  Print 1st 100 of List
   Ada.Text_IO.New_Line;
   for I in 1 .. 100 loop
      Ada.Text_IO.Put (Integer'Image (List (I)));
      if I mod 10 = 0 then
         Ada.Text_IO.New_Line;
      end if;
   end loop;

end Shuffle;





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Problems with Ada.Real_Time on GNAT?
  2002-05-16 19:33 Problems with Ada.Real_Time on GNAT? file13
  2002-05-16 20:18 ` Florian Weimer
@ 2002-05-17  4:36 ` Per Sandbergs
  2002-05-27  2:42 ` Robert I. Eachus
  2 siblings, 0 replies; 10+ messages in thread
From: Per Sandbergs @ 2002-05-17  4:36 UTC (permalink / raw)


Runs fine under
    Win2K as you said
    Linux RH71 & GCC3.1

/Per Sandberg

"file13" <file13@qlippoth.zzn.com> wrote in message
news:28d8936a.0205161133.3c9064b7@posting.google.com...
> Hi guys.  There was a silly little contest on a web BBS where people
> were asked to write a program in any language (rules in the source).
> I decided to represent for us Ada folks and produced this on GNAT 3.14
> on Windows 2000
>
> http://www.qlippoth.com/shuffle.adb
>
> It works fine under Windows 2000 but on Linux under both 3.13 and 3.14
> I (and the guy who is testing all the programs) keep getting
> segmentation faults when run.  I've compiled it safetly (without the
> -gnatp) but still the same seg fault.
>
> So I have 2 questions:
>
> 1.  Is there an error in the program itself (am I doing something
> wrong--is that the correct way to time a part of a program)?
> 2.  Is there a problem with the Real_Time annex under Linux or is this
> caused by something else?
>
> On Linux I'm using the GNU Ada RPMS's for 3.13 and the Linux bin from
> ACT for 3.14 under Mandrake 8.0 (2.4.3).
>
> Thanks in advance!
>
> file13
> http://www.qlippoth.com/





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Problems with Ada.Real_Time on GNAT?
  2002-05-16 20:53   ` David C. Hoos
@ 2002-05-17  6:57     ` Florian Weimer
  2002-05-17  9:57       ` Robert Dewar
  0 siblings, 1 reply; 10+ messages in thread
From: Florian Weimer @ 2002-05-17  6:57 UTC (permalink / raw)


"David C. Hoos" <david.c.hoos.sr@ada95.com> writes:

>> You are hitting the 2 MB stack size limit.  You should allocate the
>> large array using an allocator.
>
> With all due respect, I submit that the problem is _not_ the stack
> limit, but,

Well, the program does run if you follow my advice.

> rather the fact that to use the real-time annex, one must compile
> and link with the FSU threads run-time, instead of the Linux-native
> threads run-time.

Why do you think this is necessary?  It's certainly unneeded if you
want to use just the timing facilities from Ada.Real_Time.

(It's true that the FSU threads run-time library implements more
requirements of the real-time annex at the moment, but you'll never
reach full conformance on top of ordinary Linux anyway.)



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Problems with Ada.Real_Time on GNAT?
  2002-05-17  6:57     ` Florian Weimer
@ 2002-05-17  9:57       ` Robert Dewar
  2002-05-17 18:38         ` Florian Weimer
  2002-05-17 19:49         ` file13
  0 siblings, 2 replies; 10+ messages in thread
From: Robert Dewar @ 2002-05-17  9:57 UTC (permalink / raw)


Florian Weimer <fw@deneb.enyo.de> wrote in message news:<873cwr45xy.fsf@deneb.enyo.de>...

> Why do you think this is necessary?  It's certainly unneeded if you
> want to use just the timing facilities from Ada.Real_Time.

That's good advice, indeed there is no requirement to run in root or
anything else to use the facilities needed by this program. And there
is no need to use FSU threads for this program.

> (It's true that the FSU threads run-time library implements more
> requirements of the real-time annex at the moment, but you'll never
> reach full conformance on top of ordinary Linux anyway.)

That's false, GNAT is fully compliant with all requirements of Annex
D when running on any GNU/Linux version using FSU threads. Please 
don't make casual claims of non-compliance unless you have very
specific knowledge of a non-compliant case (in which case please
report the bug :-)



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Problems with Ada.Real_Time on GNAT?
  2002-05-17  9:57       ` Robert Dewar
@ 2002-05-17 18:38         ` Florian Weimer
  2002-05-18  2:49           ` Robert Dewar
  2002-05-17 19:49         ` file13
  1 sibling, 1 reply; 10+ messages in thread
From: Florian Weimer @ 2002-05-17 18:38 UTC (permalink / raw)


dewar@gnat.com (Robert Dewar) writes:

>> (It's true that the FSU threads run-time library implements more
>> requirements of the real-time annex at the moment, but you'll never
>> reach full conformance on top of ordinary Linux anyway.)
>
> That's false, GNAT is fully compliant with all requirements of Annex
> D when running on any GNU/Linux version using FSU threads.

Even those requirements which are not testable, e.g. D.9(9) to to
D.9(13)?

Linux isn't a RTOS kernel, and it doesn't give you any such guarantees
about maximum running time, latency and so on.  Non-conformance
in such areas is certainly not GNAT's fault, but it's still
non-conformance.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Problems with Ada.Real_Time on GNAT?
  2002-05-17  9:57       ` Robert Dewar
  2002-05-17 18:38         ` Florian Weimer
@ 2002-05-17 19:49         ` file13
  1 sibling, 0 replies; 10+ messages in thread
From: file13 @ 2002-05-17 19:49 UTC (permalink / raw)


Off list someone pointed me to the correct place in the GNAT manuals. 
BTW: you ACT folks have great documentation!  cheers!  :)

Thanks to everyone for the help/input.

file13
http://www.qlippoth.com/



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Problems with Ada.Real_Time on GNAT?
  2002-05-17 18:38         ` Florian Weimer
@ 2002-05-18  2:49           ` Robert Dewar
  0 siblings, 0 replies; 10+ messages in thread
From: Robert Dewar @ 2002-05-18  2:49 UTC (permalink / raw)


Florian Weimer <fw@deneb.enyo.de> wrote in message news:<87adqy39i3.fsf@deneb.enyo.de>...
> dewar@gnat.com (Robert Dewar) writes:
> 
> >> (It's true that the FSU threads run-time library implements more
> >> requirements of the real-time annex at the moment, but you'll never
> >> reach full conformance on top of ordinary Linux anyway.)
> >
> > That's false, GNAT is fully compliant with all requirements of Annex
> > D when running on any GNU/Linux version using FSU threads.
> 
> Even those requirements which are not testable, e.g. D.9(9) to to
> D.9(13)?

Yes.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Problems with Ada.Real_Time on GNAT?
  2002-05-16 19:33 Problems with Ada.Real_Time on GNAT? file13
  2002-05-16 20:18 ` Florian Weimer
  2002-05-17  4:36 ` Per Sandbergs
@ 2002-05-27  2:42 ` Robert I. Eachus
  2 siblings, 0 replies; 10+ messages in thread
From: Robert I. Eachus @ 2002-05-27  2:42 UTC (permalink / raw)


file13 wrote:

> Hi guys.  There was a silly little contest on a web BBS where people
> were asked to write a program in any language (rules in the source). 
> I decided to represent for us Ada folks and produced this on GNAT 3.14
> on Windows 2000
> 
> http://www.qlippoth.com/shuffle.adb



Normally I would fault you on your approach.  Randomizing a list this 
way is biased.  This can easily be seen by the fact that if N=3, there 
are 3**3 = 27 possible random sequences, and 3! = 6 random permutations. 
  So some permutations must occur more often than others.  (In this 
case, the permutations 132, 213, and 231 will occur more often than 123, 
312, and 321.)  One million is a large enough sample that this won't be 
a problem.  (But notice that the bias is still there-- 1000000! does not 
evenly divide 1000000**1000000. ;-)

The way to avoid the problem for small arrays is to generate N random 
floats (or integers) do an index sort of that list, and use that as the 
result.  But at 1000000 values, float random variates over [0.0..1.0) 
don't have enough potential different values to avoid a significant 
number of collisions.  Using (32-bit) integer variates will help, but 
again the bias is probably not an issue for N > 100.  Just don't use the 
technique in this program to shuffle a deck of cards. ;-)

Incidently I did compare the two techniques in this case, and the 
sorting method was slower, but not significantly so.  (I used a 
quicksort, this is a case where a radix sort might be better.)




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2002-05-27  2:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-16 19:33 Problems with Ada.Real_Time on GNAT? file13
2002-05-16 20:18 ` Florian Weimer
2002-05-16 20:53   ` David C. Hoos
2002-05-17  6:57     ` Florian Weimer
2002-05-17  9:57       ` Robert Dewar
2002-05-17 18:38         ` Florian Weimer
2002-05-18  2:49           ` Robert Dewar
2002-05-17 19:49         ` file13
2002-05-17  4:36 ` Per Sandbergs
2002-05-27  2:42 ` Robert I. Eachus

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