The Computer Language
Benchmarks Game

thread-ring Ada 2005 GNAT #2 program

source code

-- The Computer Language Benchmarks Game
-- http://benchmarksgame.alioth.debian.org/
-- Contributed by Jacob Sparre Andersen (with help from Alex Mason)
--
-- Compile with:
--    gnatmake -gnat05 -gnatE -gnato -gnatv -gnati1 -gnatf -m -O3 -funroll-loops -funwind-tables -gnatn -fomit-frame-pointer -march=native thread_ring

with Ada.Text_IO;
with Ada.Command_line;

procedure ThreadRing is
   Ring_Size : constant := 503;
   type Ring_Index is mod Ring_Size;

   package Ring_Text_IO is new Ada.Text_IO.Modular_IO (Ring_Index);

   protected type Store is
      entry Put  (Item : in     Integer);
      entry Take (Item :    out Integer);
   private
      Value : Integer;
      Full  : Boolean := False;
   end Store;

   protected body Store is
      entry Put (Item : in     Integer) when not Full is
      begin
         Value := Item;
         Full := True;
      end Put;

      entry Take (Item :    out Integer) when Full is
      begin
         Item := Value;
         Full := False;
      end Take;
   end Store;

   type Store_Ring is array (Ring_Index) of Store;
   Stores : Store_Ring;

   task type Node is
      entry Initialize (Identifier  : in     Ring_Index);
   end Node;

   task body Node is
      ID    : Ring_Index;
      Token : Integer;
   begin
      accept Initialize (Identifier  : in     Ring_Index) do
         ID := Identifier;
      end Initialize;

      loop
         Stores (ID).Take (Token);

         if Token = 0 then
            Ring_Text_IO.Put (ID, Width => 0);
            Ada.Text_IO.New_Line;
         end if;

         Stores (ID + 1).Put (Token - 1);

         exit when Token < 0;
      end loop;
   end Node;

   type Node_Ring is array (Ring_Index) of Node;
   Nodes : Node_Ring;
begin
   for ID in Nodes'Range loop
      Nodes (ID).Initialize (Identifier => ID);
   end loop;

   Stores (1).Put (Integer'Value (Ada.Command_Line.Argument (1)));
end ThreadRing;
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
GNATMAKE 7.2.0
gcc (Ubuntu 7.2.0-8ubuntu3) 7.2.0



Thu, 26 Oct 2017 15:10:26 GMT

MAKE:
gnatchop -r -w threadring.gnat-2.gnat
splitting threadring.gnat-2.gnat into:
   threadring.adb
gnatmake -O3 -fomit-frame-pointer -march=native -msse3 -mfpmath=sse -gnatNp -f threadring.adb -o threadring.gnat-2.gnat_run 
gcc-7 -c -O3 -fomit-frame-pointer -march=native -msse3 -mfpmath=sse -gnatNp threadring.adb
gnatbind-7 -x threadring.ali
gnatlink-7 threadring.ali -O3 -fomit-frame-pointer -march=native -msse3 -mfpmath=sse -o threadring.gnat-2.gnat_run

0.62s to complete and log all make actions

COMMAND LINE:
./threadring.gnat-2.gnat_run 50000000

PROGRAM OUTPUT:
292