Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!news-server.csri.toronto.edu!torsqnt!jtsv16!itcyyz!yrloc!rbe
From: rbe@yrloc.ipsa.reuter.COM (Robert Bernecky)
Subject: Re: APL execution efficiency revisited
Message-ID: <1992Mar30.203818.15221@yrloc.ipsa.reuter.COM>
Reply-To: rbe@yrloc.ipsa.reuter.COM (Robert Bernecky)
Organization: Snake Island Research Inc, Toronto
References: <ROCKWELL.92Mar23224842@socrates.umd.edu> <756@kepler1.rentec.com> <1992Mar26.163242.5298@yrloc.ipsa.reuter.COM> <771@kepler1.rentec.com>
Date: Mon, 30 Mar 92 20:38:18 GMT

>I were, I could compute any answer in one operation: 'return 0'.
>
>
>Now for the particular case  of +.x / (A B C D ...) you will be able to
>do something, but only in the case where you know about all of the matrices
>A, B, C, ... before you do the products. If I hand you the matrices one
>at a time, it is much harder to optimize the product, since you do it
>'pairwise'.

So, if you hand ne the matrices one at a time, the whole question 
of ordering is moot. This is like trying to nail Jello to a tree.
Can we please stick with one problem at a time, please?

-----------------------------------------------------------------

My point about precision loss is that the loss in precision depends on
the ordering of the matrix product, which is DATA-sensitive, and is,
I suspect, a much harder problem to solve than the how-do-I-reduce-
the-number-of-mulitplies problem. 


>
>Note that optimizing the product of two matrices is almost irrelevant
>to the case of optimizing a product of N>2 matrices. The concerns in
>the N > 2 case involve how to associate the matrices, i.e. how to group
>the parentheses, A +.x (B +.x C) vs. (A +.x B) +.x C, but the N=2 case
>involves only issues like going along rows or columns to get nice machine
>specific performance. It goes without saying that I _assume_ the pairwise
>products are optimized for memory throughput. However, you can quickly
>convince yourself that the number of floating point multiplications is
>not affected if you rearrange the calculations.
>
>You can see by the simple example where A is NxN, B is NxN, and C is Nx1,
>that the number of multiplications required is:
>
>	Product Order  			# Multiplications
>	---------------			-----------------
>	A +.x (B +.x C) 		       2N^2
>	(A +.x B) +.x C			    N^3 + N^2
>

This was, I thought, the original point of this thread. My point, 
which you seem to be missing, is that IF I know that I have 
M arrays, and IF I know their shape, than I can DYNAMICALLY decide
the best (in the sense of minimizing multiplies) ordering for the
operation. Now, let's see you do the same in Fortran. No cheating now:
Array sizes are to be determined at run time. 



Robert Bernecky      rbe@yrloc.ipsa.reuter.com  bernecky@itrchq.itrc.on.ca 
Snake Island Research Inc  (416) 368-6944   FAX: (416) 360-4694 
18 Fifth Street, Ward's Island
Toronto, Ontario M5J 2B9 
Canada
