TimHopkins

10 Reputation

One Badge

7 years, 299 days

MaplePrimes Activity


These are questions asked by TimHopkins

I have been using CodeTools::Usage with Maple 17 to compare timings of a couple of matrix inversion routines against each other and against the Maple library routines LinearAlgebra::MatrixInverse and LinearAlgebra::Determinant.

The small section of code that I use to collect the cpu times for each method is:

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

udata := Usage(invTest(x,y,z,delta,mu), output=['cputime', 'bytesused'],
              iterations=nRepeats, quiet);
dat[1]:=udata[1]; dat[2]:=udata[2];

----------------------------------------
nRepeats has been set to 25.

In order to get the timings as accurate as possible, I only open a couple of terminal windows on my laptop so as to run the tests with as low a loaded machine as I can get. (I'm running Ubuntu 14.04 on an 8 core Intel (R) Core i7-3840QM, 2.8GHz CPU with 16Gb of memory.)

A test run consists of a sequence of test matrices each of which is run for an increasing sequence of matrix orders. I either time an implementation on its own or I time both an implementation and the Maple library routines. In the later case for each test matrix and order of matrix, I use Usage to first time the Maple routines and then the times for one of the implementations:

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

if compMaple then
udata := Usage(MatrixInverse(A), output=['cputime', 'bytesused'],
              iterations=nRepeats, quiet);
mdat[1]:=udata[1]; mdat[2]:=udata[2];

udata := Usage(Determinant(A), output=[cputime, bytesused],
              iterations=nRepeats, quiet);
mdat[1]:=mdat[1]+udata[1];
mdat[2]:=mdat[2]+udata[2];
else
  mdat[1..2] := 0:
end if:

udata := Usage(invTest(x,y,z,delta,mu), output=['cputime', 'bytesused'],
              iterations=nRepeats, quiet);
dat[1]:=udata[1]; dat[2]:=udata[2];

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

I have noticed the following:

a) If I time both Maple and an implementation, and the same implementation on its own I can get timings that vary up to a factor of 2 or more,

b) Changes in timings for the same test run and as close to the same environment as I can get (i.e., just the two user terminal windows open) can generate timing differences of up to 50%.

c) Sometimes `chaotic' timings are generated, for example,

    n = 150, t = 3 (secs)
    n = 200, t = 24 (secs)
    n = 250, t = 18 (secs)

which cannot be reflecting the times required to perform the calculations. This type of behaviour always seems to occur when the reported memory bytecount is increasing from ~0.25* 10^9 to over 10^9.

Is there anything I can be doing here to get more consistent timings?

I want to use the timings from these tests in a journal article so it would be good to have the same test run under very similar conditions to return timings within a few percent difference of one another. I certainly get this sort of tolerances (<10%) if I use the Fortran cpu_time intrinsic to time Fortran code.

Any advice would be gratefully received.

I have been looking at a method for computing the inverse of a periodic, tridiagonal, matrix (tridiagonal with non-zero elements in (1,n) and (n,1), where n is the order of the matrix).

Using test matrices with rational elements I get a good improvement in execution time compared to Maple's MatrixInverse procedure from LinearAlgebra. However when I use algebraic elements I get faster times with small orders but from around
n=25 (for a particular example matrix) my method is running slower than MatrixInverse.

If I look at the element (1,1) of the inverse returned by both procedures I see that the Maple inverse is quite compact while the value returned by my procedure is very complex (on printing Maple extracts 17 subexpressions of varying complexity). I
have a check in the test rig to determine if the two inverses are the same; this uses

evalb(simplify(AinvMaple[i,j]-Ainv[i,j])==0)

and all the elements do agree.

The Maple MatrixInverse appears to be able to simplify the elements of the inverse; is this a feature of the algorithm that's being used or is there some mechanism I should be using to achieve this?

The source code of the procedure I've written (first 100 odd lines) and the test rig are attached. The file is set up to run the algebraic test (Test4) for n=20 and to print the (1,1) inverse elements generated by both the Maple and my procedures.

Any help in improving my code to produce simplified forms of the elements would be greatfully received.

Maple source as text file: KilicInv.txt

Page 1 of 1