Re: why is Fortran A*B (for matrices) seem to be slow?



On 12/12/10 19:50, Nasser M. Abbasi wrote:

Platform:
mingw32, on windows 7 with gfortran 4.6 for fortran

On an Intel Core2 Duo T9400 cpu (a dual-core laptop, burdened with the usual bevy of bloated business software...), running 32 bit Windows XP, using Intel Visual Fortran Compiler XE for IA-32 version 12.1.127 with command line options "/warn:all /check:none /O3 /Qxhost /Qmkl:parallel", I compiled a slight modification of the source in your original post (removed mixed precision arithmetic and added system_clock timings) and get numbers like:

cpu_time for matmul: 43.4
system_clock for matmul: 43.5
cpu_time for dgemm: 22.7
system_clock for dgemm: 11.6

On the same platform with Matlab R2009B and your original script I get an typical second or subsequent run tic-toc time of 11.9 seconds (the first run after an edit was always about 0.5 seconds slower - which I take to be the time for the p-code generation or whatever they do these days).

For kicks I switched the Fortran to the F95 interface for the GEMM call and observed no difference in timings. The CALL statement involved quite a bit less typing though...

As a user of the Intel compiler, I see some very familiar DLL's in my Matlab's "bin" directory. As a result, bar interpreter overhead or differences in higher level optimiser cleverness(*), I'd wouldn't be expecting significant differences.

Later I looked at the relative memory usages of the two approaches. A typical working set requirement for the fortran program was 25 MB in the MATMUL bit, jumping to 30 MB in GEMM, while Matlab was approximately 60 MB (using a freshly started Matlab environment and emptying the working set for the Matlab process before each run of the script).

IanH


(*) I was half expecting the Intel compiler to pick that the variable "c" wasn't being used, and so remove the MATMULT and GEMM calls. But obviously it didn't.

.



Relevant Pages

  • Re: Fortran vs. Matlab on linear algebra
    ... matmul() with the speed of a matrix multiply in Matlab. ... To compare speed of Matlab and Fortran on matrix algebra ... time optimization ...
    (comp.lang.fortran)
  • Re: Fortran vs. Matlab on linear algebra
    ... matmul() with the speed of a matrix multiply in Matlab. ... To compare speed of Matlab and Fortran on matrix algebra ... I am running on a recent Intel quad core Windows PC. ...
    (comp.lang.fortran)
  • Re: Fortran vs. Matlab on linear algebra
    ... matmul() with the speed of a matrix multiply in Matlab. ... To compare speed of Matlab and Fortran on matrix algebra ...
    (comp.lang.fortran)
  • Re: Fortran vs. Matlab on linear algebra
    ... matmul() with the speed of a matrix multiply in Matlab. ... To compare speed of Matlab and Fortran on matrix algebra ...
    (comp.lang.fortran)
  • Re: Should anyone be using modern Fortran any more?
    ... sufficiently encompassing of typical University level ... Fortran's, and my definable subset of Fortran 95 would be close to F ... many "interpreted languages" actually compile to some ... Matlab does JIT compiling to an intermediary form and it has become quite impressively good over recent years, ...
    (comp.lang.fortran)