Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!hp4nl!charon!dik From: dik@cwi.nl (Dik T. Winter) Newsgroups: comp.lang.fortran Subject: Re: matrix multiplication Keywords: parameters, pass-by-value, pass-by-reference Message-ID: <3444@charon.cwi.nl> Date: 5 May 91 00:58:41 GMT References: <1991May04.170203.22222@ariel.unm.edu> Sender: news@cwi.nl Organization: CWI, Amsterdam Lines: 41 In article <1991May04.170203.22222@ariel.unm.edu> scavo@cie.uoregon.edu (Tom Scavo) writes: > A robust algorithm will also handle the special case > X = Y X (1) > mxn mxm mxn > where the result is to replace one of the matrices being > multiplied. Not in Fortran. > On the other hand, pass-by-value can be > simulated using a local array (for the lhs) declared within the > matrix multiplication routine. Unfortunately, the dimensions of > this local array put an operational limit on the size of the input > matrices. Still your routine will not be conforming to the Fortran standard. > > How would I write a *general* matrix multiplication routine that > handles tricky computations such as those in (1), and accomodates > matrices of arbitrary size? If you are thinking about portrable Fortran you must forget it. It is not permitted. To give an example of the problem, suppose the following (simple) routine: SUBROUTINE ADD(A, B, C) A = B + C RETURN END The following calls are illegal: CALL ADD(P, P, Q) CALL ADD(P, Q, P) The reason is that *if* one of the parameters changes value within the routine that parameter may not be aliased to another on the call side. Some compilers allow this, but some choke on a number of cases. > Also, does anyone know of a Fortran > compiler that implements pass-by-value-result, a kind of delayed > pass-by-reference where the actual parameters are updated at the > point of return? Or is this non-standard? This is certainly non-standard in general. For simple variables it is implemented on a large number of compilers (IBM amongst them). -- dik t. winter, cwi, amsterdam, nederland dik@cwi.nl