From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Large number of tasks slows down my program (using debian) - any fix? Date: Fri, 6 Apr 2018 17:48:29 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <1aa8f536-250d-4bef-9392-4d936f916e5f@googlegroups.com> <9377f941-31d0-4260-818a-8e189aac8c19@googlegroups.com> <10e74e0c-119a-4d86-8a12-c05101f744f1@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 6 Apr 2018 15:48:29 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="92a0854d0e40fd419ab917a855d3b722"; logging-data="30577"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BSSBrXKYTE5eF89ikhpwmCjxPb1StQHU=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 In-Reply-To: <10e74e0c-119a-4d86-8a12-c05101f744f1@googlegroups.com> Content-Language: en-US Cancel-Lock: sha1:toSW2fHWwakwTh9+pmFiqGH7E+E= Xref: reader02.eternal-september.org comp.lang.ada:51358 Date: 2018-04-06T17:48:29+02:00 List-Id: 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