| MATLAB Central > MATLAB Newsreader > Preallocation in MATLAB R2009a |
|
|
|
It's known that to use a matrix variable "a" with changeless size m,n,we should preallocate memory for the variable to achieve good performance.Usually,We use "a= zeros(m,n)" to preallocate. |
|
"rocwoods" <rocwoods@yeah.net> wrote in message <h5c475$639$1@fred.mathworks.com>... |
|
Subject: Preallocation in MATLAB R2009a From: Oleg Komarov Date: 5 Aug, 2009 16:08:02 Message: 3 of 29 |
|
"rocwoods" <rocwoods@yeah.net> wrote in message <h5c475$639$1@fred.mathworks.com>... |
|
"Oleg Komarov" <oleg.komarov@hotmail.it> wrote in message <h5cap2$6e9$1@fred.mathworks.com>... |
|
"Oleg Komarov" <oleg.komarov@hotmail.it> wrote in message <h5cap2$6e9$1@fred.mathworks.com>... |
|
Subject: Preallocation in MATLAB R2009a From: Oleg Komarov Date: 5 Aug, 2009 17:32:18 Message: 6 of 29 |
|
"someone" <someone@somewhere.net> wrote in message <h5cekt$3nt$1@fred.mathworks.com>... |
|
Subject: Preallocation in MATLAB R2009a From: Steven Lord Date: 5 Aug, 2009 17:33:24 Message: 7 of 29 |
|
|
|
Subject: Preallocation in MATLAB R2009a From: Steven Lord Date: 5 Aug, 2009 17:36:42 Message: 8 of 29 |
|
|
|
Subject: Preallocation in MATLAB R2009a From: Oleg Komarov Date: 5 Aug, 2009 17:41:03 Message: 9 of 29 |
|
"Steven Lord" <slord@mathworks.com> wrote in message <h5cfv8$hl$1@fred.mathworks.com>... |
|
"qooroo " <qooroo@gmail.com> wrote in message <h5c9nq$fsm$1@fred.mathworks.com>... |
|
Subject: Preallocation in MATLAB R2009a From: Bruno Luong Date: 5 Aug, 2009 18:08:04 Message: 11 of 29 |
|
|
|
"Steven Lord" <slord@mathworks.com> wrote in message <h5cfp2$hes$1@fred.mathworks.com>... |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h5chq4$3nt$1@fred.mathworks.com>... |
|
"us " |
|
Subject: Preallocation in MATLAB R2009a From: Bruno Luong Date: 5 Aug, 2009 18:47:03 Message: 15 of 29 |
|
"us " <us@neurol.unizh.ch> wrote in message <h5cikr$jh$1@fred.mathworks.com>... |
|
Subject: Preallocation in MATLAB R2009a From: Yair Altman Date: 5 Aug, 2009 19:20:04 Message: 16 of 29 |
|
BTW, this is also the case in older Matlab versions, not just 2009a or 2008b. |
|
"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <h5cm14$i3d$1@fred.mathworks.com>... |
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <h5cmv3$lb5$1@fred.mathworks.com>... |
|
"us " <us@neurol.unizh.ch> wrote in message <h5cnt2$n8p$1@fred.mathworks.com>... |
|
Subject: Preallocation in MATLAB R2009a From: James Tursa Date: 5 Aug, 2009 20:32:03 Message: 20 of 29 |
|
I just ran some tests on WinXP R2006a through R2009a, and the difference first shows up in R2008b. I recalled that some time ago I compared building a zero matrix from scratch in a C-mex file vs the MATLAB intrinsic zeros function and got essentially the same timing result. That was back in R2007a. But now when I run the same test in R2009a I get the same huge speed difference that is showing up with the a(10000,11000)=0 method. The C-mex routine used mxCalloc to get the memory. I also tried mxMalloc and got essentially the same result. So the underlying methods used for mxMalloc and mxCalloc appear to have changed from R2008a to R2008b. Maybe MATLAB now keeps better track of which memory is already zeroed out, so calls to mxCalloc or the like don't always have to do this work because it has already been done previously. Just a guess. Seems like the zeros function is not taking advantage |
|
On Aug 5, 12:36 pm, "Matt Fig" <spama...@yahoo.com> wrote: |
|
Subject: Preallocation in MATLAB R2009a From: James Tursa Date: 5 Aug, 2009 20:43:03 Message: 22 of 29 |
|
On a related note, I previously had tested the following (R2007a??) in a C-mex routine: |
|
Subject: Preallocation in MATLAB R2009a From: Bruno Luong Date: 5 Aug, 2009 20:58:03 Message: 23 of 29 |
|
"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <h5cq83$7o$1@fred.mathworks.com>... |
|
"us " <us@neurol.unizh.ch> wrote in message <h5cnt2$n8p$1@fred.mathworks.com>... |
|
Subject: Preallocation in MATLAB R2009a From: Yair Altman Date: 5 Aug, 2009 21:14:02 Message: 25 of 29 |
|
Nathan <ngreco32@gmail.com> wrote ... |
|
"us " <us@neurol.unizh.ch> wrote in message <h5crqp$elm$1@fred.mathworks.com>... |
|
Subject: Preallocation in MATLAB R2009a From: James Tursa Date: 6 Aug, 2009 00:20:18 Message: 27 of 29 |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h5cror$ar2$1@fred.mathworks.com>... |
|
Thanks to all the people who are concerned about this ! |
|
clear all |
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.
| Tag Activity for This Thread | ||
|---|---|---|
| Tag | Applied By | Date/Time |
| timing | us | 6 Aug, 2009 17:04:47 |
| humor | us | 5 Aug, 2009 17:04:06 |
| code | us | 5 Aug, 2009 14:24:04 |
| undocumented | Oleg Komarov | 5 Aug, 2009 13:34:09 |
| preallocation | rocwoods | 5 Aug, 2009 10:19:02 |
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.
Contact us at files@mathworks.com