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: 103376,edda2b296e2577cf X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe12.iad.POSTED!00000000!not-for-mail From: Brad Moore User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: GNAT's Protected Objects References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4T2Ho.48575$3f.30870@newsfe12.iad> NNTP-Posting-Host: 68.145.218.234 X-Complaints-To: internet.abuse@sjrb.ca X-Trace: newsfe12.iad 1290582592 68.145.218.234 (Wed, 24 Nov 2010 07:09:52 UTC) NNTP-Posting-Date: Wed, 24 Nov 2010 07:09:52 UTC Date: Wed, 24 Nov 2010 00:08:54 -0700 Xref: g2news1.google.com comp.lang.ada:15643 Date: 2010-11-24T00:08:54-07:00 List-Id: On 08/11/2010 1:34 PM, Jeffrey Carter wrote: > I was trying to decide the "optimal" number of tasks for concurrent > problems on my 2-core system, so I wrote a little program to do matrix > multiplication with multiple tasks. > In my paper that was presented at the recent 2010 SigAda conference (Parallelism Generics for Ada 2005 and Beyond) a few weeks ago, I describe an algorithm for determining the optimal number of tasks for iterative parallelism. The algorithm is; if iterations count is significant relative to the processor count then if iteration count >= processor count then select worker count that is the smallest factor of the iteration count that is >= the number of processors else use Iteration count end if else use processor count end if Incidentally, your code compiled on my system, an ASUS notebook running on Windows on a dual core atom processor, and 4 threads, using index ranges of 1 .. 250, instead of 1 .. 500 (to prevent Storage_Error exceptions being raised) produced the following output. Num processors 4 1 7.216035603 2 5.227005507 3 4.427877415 4 3.636320293 5 3.638031600 6 3.560718135 7 3.623521965 8 3.482307103 9 3.442896474 10 3.512802807 After applying my parallel generics to the code, this resulted in the following output; Num processors 4 1 3.490789402 2 1.307300640 3 1.072091225 4 0.888874454 5 1.009769300 6 0.977095744 7 0.921706085 8 0.966491909 9 0.910645945 10 0.961553821 ... with Parallel.Iterate; procedure MP_Mult_PO_Generic is subtype Index_Value is Integer range 1 .. 250; procedure Matrix_Iterate is new Parallel.Iterate (Iteration_Index_Type => Index_Value); type Matrix is array (Index_Value, Index_Value) of Float; function Mult (Left : Matrix; Right : Matrix; Num_Tasks : Parallel.Worker_Count_Type) return Matrix -- Perform a concurrent multiplication of Left * Right -- using Num_Tasks tasks is Result : Matrix; procedure Matrix_Multiply (Start, Finish : Index_Value) is Temp_Result : Float; begin for Row in Start .. Finish loop for Col in Index_Value loop Temp_Result := 0.0; for K in Index_Value loop Temp_Result := Temp_Result + Left (Row, K) * Right (K, Col); end loop; Result (Row, Col) := Temp_Result; end loop; end loop; end Matrix_Multiply; begin -- Mult Matrix_Iterate (Worker_Count => Num_Tasks, Process => Matrix_Multiply'Access); return Result; end Mult; ... The generics allow the code to be written more closely to the sequential form. The worker tasks are hidden in the generic. Brad Moore