PETSc vs Matlab Performance
Sh.M
shma7099 at student.uu.se
Thu May 18 11:09:12 CDT 2006
Hi,
Matlab interpretates your code when it runs it and does not compile it to
machine code. So there is another program in the background that parses thru
your code and translates to quadruples(some form of assembly code that is
not CPU specifik), then it runs that interpreted code in a high leven
language written interpretator. In C however the quadruples are converted to
assembly code specifik to the target platform and then converted to machine
code by an assembler.
Are you using loops(for; while;) or do you so to speak "vectorize" your
data? Looping is quite slow in matlab. I naively used a for loop to extract
the first block of a triblock diagonal matrix and it took several minutes
until it finished, and I just wanted to extract 4000x4000 elements from it.
In C it took less than a second to do it, a lot thanks to fast memory
addressing.
Other than that I believe that you are using indirect addressing, something
as far as I know is hard to optimize? Thus tight loops are hard to optimize
and you are left with a good chunk of the code being unoptimized by matlab.
I am sure some other peoples can extend what I have said and not said.
With best regards, Shaman Mahmoudi
----- Original Message -----
From: "Joshua L. Adelman" <jadelman at OCF.Berkeley.EDU>
To: <petsc-users at mcs.anl.gov>
Sent: Thursday, May 18, 2006 5:31 PM
Subject: PETSc vs Matlab Performance
> Having just finished writing my first modest PETSc-based application,
> I was amazed how much faster the code was than my Matlab prototype,
> even running in sequentially on a single processor. The code
> basically involves propagating a time series using Backward Euler,
> where the rate matrix K, is static. Granted I might be doing
> something horribly inefficient in my Matlab code, since I had code
> the Backward Euler, but given that the bulk of the time is spent in
> the matlab solver (either qmr or gmres), it seems that seems
> unlikely. Running with a single processor, the actual solver part of
> my PETSc code runs 15-25x faster than the equivalent part in my
> matlab code, and this is without using any optimization flags on the
> compiler and having compiled PETSc with debugger options on (the -
> log_summary output says that that would slow things down by a factor
> of 2-3x). I had always been told that for doing any sort of Linear
> Algebra sort of stuff, like inverting a matrix, Matlab's algorithms
> were as fast as anything you could hand code in C or Fortran
> (although when they say 'you', they might mean 'me' specifically and
> not the people who write PETSc).
>
> Have there been any official benchmarks, pitting PETSc again Matlab?
> And for the CS novice, what is the underlying reason for the difference?
>
> Thanks,
> Josh
>
>
> ------------------------------------------------------------------------
> ------------------------------
> Joshua L. Adelman
> Biophysics Graduate Group Lab: 510.643.2159
> 218 Wellman Hall Fax: 510.642.7428
> University of California, Berkeley http://www.ocf.berkeley.edu/
> ~jadelman
> Berkeley, CA 94720 USA jadelman at ocf.berkeley.edu
> ------------------------------------------------------------------------
> ------------------------------
>
>
>
More information about the petsc-users
mailing list