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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,edda2b296e2577cf X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!newsfeed.straub-nv.de!news.mixmin.net!news.tornevall.net!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: GNAT's Protected Objects Date: Mon, 08 Nov 2010 15:32:29 -0700 Organization: TornevallNET - http://news.tornevall.net Message-ID: References: <4af1a5f4-7bf3-47ee-af67-db50e589e7a8@n32g2000pre.googlegroups.com> NNTP-Posting-Host: 79ff3d6800975be6ca3048a029deab15 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: c31bef799068988450780d866509958e X-Complaints-To: abuse@tornevall.net User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101027 Thunderbird/3.0.10 X-Complaints-Language: Spoken language is english or swedish - NOT ITALIAN, FRENCH, GERMAN OR ANY OTHER LANGUAGE! In-Reply-To: <4af1a5f4-7bf3-47ee-af67-db50e589e7a8@n32g2000pre.googlegroups.com> X-UserIDNumber: 1738 X-Validate-Post: http://news.tornevall.net/validate.php?trace=c31bef799068988450780d866509958e X-Complaints-Italiano: Non abbiamo padronanza della lingua italiana - se mandate una email scrivete solo in Inglese, grazie X-Posting-User: 0243687135df8c4b260dd4a9a93c79bd Xref: g2news2.google.com comp.lang.ada:16360 Date: 2010-11-08T15:32:29-07:00 List-Id: On 11/08/2010 02:38 PM, Anh Vo wrote: > > How may tasks used, two or four, when slowness was observed when > compared to simple task? I will be supprised if the answer is two. It > is logically expected that two tasks should perform better than single > task. However, when it comes to four or greater task, the result may > not be true due to task switching cost. That's what I expected. However, any number of tasks > 1 took longer than a single task. > I would be glad to test it on my two core CPU mahine if the your > little program is posted. I have appended the code to this message. Watch for line wrapping. -- Jeff Carter "Sir Robin the not-quite-so-brave-as-Sir-Lancelot, who had nearly fought the Dragon of Angnor, who nearly stood up to the vicious Chicken of Bristol, and who had personally wet himself at the Battle of Badon Hill." Monty Python & the Holy Grail 68 with Ada.Exceptions; with Ada.Numerics.Float_Random; with Ada.Real_Time; with Ada.Text_IO; with System.Task_Info; procedure MP_Mult_PO is Num_Processors : constant Positive := System.Task_Info.Number_Of_Processors; subtype Index_Value is Integer range 1 .. 500; type Matrix is array (Index_Value, Index_Value) of Float; function Mult (Left : in Matrix; Right : in Matrix; Num_Tasks : in Positive) return Matrix; -- Perform a concurrent multiplication of Left * Right using Num_Tasks tasks function Mult (Left : in Matrix; Right : in Matrix; Num_Tasks : in Positive) return Matrix is task type Calc_One; protected Control is procedure Get (Row : out Natural; Col : out Natural); -- Returns the row and column of a result to calculate. -- Returns zero for both when there are no more results to calculate. private -- Control Next_Row : Positive := 1; Next_Col : Positive := 1; Done : Boolean := False; end Control; Result : Matrix; task body Calc_One is Row : Natural; Col : Natural; begin -- Calc_One All_Results : loop Control.Get (Row => Row, Col => Col); exit All_Results when Row = 0; Result (Row, Col) := 0.0; Sum : for K in Index_Value loop Result (Row, Col) := Result (Row, Col) + Left (Row, K) * Right (K, Col); end loop Sum; end loop All_Results; exception -- Calc_One when E : others => Ada.Text_IO.Put_Line (Item => "Calc_One " & Ada.Exceptions.Exception_Information (E) ); end Calc_One; protected body Control is procedure Get (Row : out Natural; Col : out Natural) is begin -- Get if Done then Row := 0; Col := 0; return; end if; Row := Next_Row; Col := Next_Col; if Next_Col < Index_Value'Last then Next_Col := Next_Col + 1; return; end if; Next_Col := 1; Next_Row := Next_Row + 1; Done := Next_Row > Index_Value'Last; end Get; end Control; begin -- Mult Create_Tasks : declare type Task_List is array (1 .. Num_Tasks) of Calc_One; Tasks : Task_List; begin -- Create_Tasks null; -- Wait for all tasks to complete end Create_Tasks; return Result; exception -- Mult when E : others => Ada.Text_IO.Put_Line (Item => "Mult " & Ada.Exceptions.Exception_Information (E) ); raise; end Mult; function Random return Float; Gen : Ada.Numerics.Float_Random.Generator; function Random return Float is begin -- Random return 200.0 * Ada.Numerics.Float_Random.Random (Gen) - 100.0; -- -100 .. 100. end Random; A : constant Matrix := Matrix'(others => (others => Random) ); B : constant Matrix := Matrix'(others => (others => Random) ); C : Matrix; Elapsed : Duration; Prev : Duration := Duration'Last; Start : Ada.Real_Time.Time; Num_Tasks : Positive := 1; use type Ada.Real_Time.Time; begin -- MP_Mult_PO Ada.Text_IO.Put_Line (Item => "Num processors" & Integer'Image (Num_Processors) ); All_Calls : loop Start := Ada.Real_Time.Clock; C := Mult (A, B, Num_Tasks); Elapsed := Ada.Real_Time.To_Duration (Ada.Real_Time.Clock - Start); Ada.Text_IO.Put_Line (Item => Integer'Image (Num_Tasks) & ' ' & Duration'Image (Elapsed) ); exit All_Calls when Num_Tasks > 2 * Num_Processors and Elapsed > Prev; Prev := Elapsed; Num_Tasks := Num_Tasks + 1; end loop All_Calls; exception -- MP_Mult_PO when E : others => Ada.Text_IO.Put_Line (Item => "MP_Mult_PO " & Ada.Exceptions.Exception_Information (E) ); end MP_Mult_PO;