comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Large number of tasks slows down my program (using debian) - any fix?
Date: Fri, 6 Apr 2018 17:48:29 +0200
Date: 2018-04-06T17:48:29+02:00	[thread overview]
Message-ID: <pa84sd$trh$1@dont-email.me> (raw)
In-Reply-To: <10e74e0c-119a-4d86-8a12-c05101f744f1@googlegroups.com>

On 04/05/2018 04:07 PM, Brad Moore wrote:
> 
> https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/threadring-gnat-6.html

The code as presented here doesn't compile: Create_Lightweight_Thread is called 
before the body is elaborated.

Correcting that, the code ran in about 25.3 s on a 4 GHz Core i7 (8 virtual 
processors). About a factor of 1.9 from the results presented.

I then made what seemed to me like fairly minor changes to the code. To my 
surprise, the result ran in about 7.6 s. Applying the factor of 1.9 would put 
this result in 3rd place.

Functionally the 2 seem equivalent. Probably the most significant change is that 
the protected entry became a protected procedure.

function Execute_Threadring (Number_Of_Tokens : Positive) return Positive is
    subtype Token_Number is Natural range 0 .. Number_Of_Tokens;

    Threadring_Size : constant := 503;

    type Thread_Index is mod Threadring_Size;
    type Thread_Id is range 1 .. Threadring_Size;

    Next_Name : Thread_Id'Base := 1;

    type Thread_Info is record
       Name  : Thread_Id    := Thread_Id'First;
       Index : Thread_Index := Thread_Index'First;
    end record;

    function New_Thread return Thread_Info;

    function New_Thread return Thread_Info is
    begin
       return Thread : constant Thread_Info :=
          (Name  => Next_Name, Index => Thread_Index (Next_Name - 1) )
       do
          Next_Name := Next_Name + 1;
       end return;
    end New_Thread;

    type Thread_List is array (Thread_Index) of Thread_Info;

    protected Token_Passer is
       procedure Wait_For_Baton (Done : in out Boolean);

       function Get_Result return Thread_Id;
    private
       Token          : Token_Number := Number_Of_Tokens;
       Current_Thread : Thread_Index := 0;
       Result         : Thread_Id    := 1;
       Thread         : Thread_List   := (others => New_Thread);
    end Token_Passer;

    protected body Token_Passer is
       function Get_Result return Thread_Id is
       begin
          return Result;
       end Get_Result;

       procedure Wait_For_Baton (Done : in out Boolean) is
       begin
          if Token = 0 then
             Result := Thread (Current_Thread).Name;
             Done := True;
          else
             Token := Token - 1;
             Current_Thread := Thread (Current_Thread).Index + 1;
          end if;
       end Wait_For_Baton;
    end Token_Passer;

    task type OS_Thread;

    task body OS_Thread
    is
       All_Done : Boolean := False;
    begin
       Pass_All : loop
          Token_Passer.Wait_For_Baton (Done => All_Done);

          exit Pass_All when All_Done;
       end loop Pass_All;
    end OS_Thread;
begin
    -- Wait for workers to complete before returning result
    declare
       Number_Of_Workers : constant := 503;

       type Worker_List is array (1 .. Number_Of_Workers) of OS_Thread;

       pragma Warnings (Off, "*Worker_Pool* is not referenced");

       Worker_Pool : Worker_List;

       pragma Warnings (On, "*Worker_Pool* is not referenced");
    begin
       null;
    end;

    return Positive (Token_Passer.Get_Result);
end Execute_Threadring;


-- 
Jeff Carter
"It's all right, Taggart. Just a man and a horse being hung out there."
Blazing Saddles
34


  parent reply	other threads:[~2018-04-06 15:48 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 18:06 Large number of tasks slows down my program (using debian) - any fix? reinert
2018-03-28 18:49 ` Dennis Lee Bieber
2018-03-28 19:06 ` Paul Rubin
2018-03-28 19:21 ` Dmitry A. Kazakov
2018-03-28 20:17   ` reinert
2018-03-29  8:46     ` reinert
2018-03-29  9:18       ` Dmitry A. Kazakov
2018-03-29 15:39       ` Jeffrey R. Carter
2018-04-15  5:20         ` reinert
2018-03-29 22:33 ` Shark8
2018-03-30  9:04   ` Dmitry A. Kazakov
2018-03-30 20:46     ` Paul Rubin
2018-03-31  0:09       ` Randy Brukardt
2018-03-31  6:00         ` Paul Rubin
2018-03-31  9:37           ` Jacob Sparre Andersen
2018-03-31 10:44             ` Dmitry A. Kazakov
2018-04-02  3:35           ` Randy Brukardt
2018-04-02  6:23     ` alby.gamper
2018-04-02  7:12       ` alby.gamper
2018-04-05 14:07       ` Brad Moore
2018-04-05 15:09         ` Dmitry A. Kazakov
2018-04-07  4:16           ` Brad Moore
2018-04-05 15:30         ` Jeffrey R. Carter
2018-04-05 19:33           ` Spiros Bousbouras
2018-04-05 19:44           ` Simon Wright
2018-04-05 20:25             ` Jeffrey R. Carter
2018-04-06  5:58         ` Benchmarks Game: Thread ring (Was: Large number of tasks slows down my program (using debian) - any fix?) Jacob Sparre Andersen
2018-04-07  4:28           ` Brad Moore
2018-04-06 15:48         ` Jeffrey R. Carter [this message]
2018-04-07  4:39           ` Large number of tasks slows down my program (using debian) - any fix? Brad Moore
2018-04-07  8:15             ` Jeffrey R. Carter
2018-04-07 16:28               ` Brad Moore
2018-04-07 18:41                 ` Jeffrey R. Carter
2018-04-08  0:29                   ` Brad Moore
2018-04-08  8:25                     ` Jeffrey R. Carter
2018-04-08  0:06                 ` Robert I. Eachus
2018-04-07 16:51               ` Brad Moore
2018-04-07 12:21         ` Simon Wright
2018-04-07 16:57           ` Brad Moore
replies disabled

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