Path: news.mathworks.com!not-for-mail From: "Nike Dattani" <dattani.nike@gmail.com> Newsgroups: comp.soft-sys.matlab Subject: Re: New challenge! Minimizing the amount of 'unnecessary memory' ! Date: Mon, 14 Mar 2011 02:39:04 +0000 (UTC) Organization: Oxford University Lines: 37 Message-ID: <iljv48$pkf$1@fred.mathworks.com> References: <ilbujg$rbl$1@fred.mathworks.com> <ilj63l$kr6$1@fred.mathworks.com> Reply-To: "Nike Dattani" <dattani.nike@gmail.com> NNTP-Posting-Host: www-00-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1300070344 26255 172.30.248.45 (14 Mar 2011 02:39:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Mon, 14 Mar 2011 02:39:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2479384 Xref: news.mathworks.com comp.soft-sys.matlab:715589 "James Tursa" wrote in message <ilj63l$kr6$1@fred.mathworks.com>... > "Nike Dattani" <dattani.nike@gmail.com> wrote in message <ilbujg$rbl$1@fred.mathworks.com>... > > > > What's even stranger is that even if I define a new temprary variable: > > temp=((indices(:,end-j)-1)*4+indices(:,end),j+1); > > > > and now write down the total memory allocated to matlab, and then apply the command: > > A.*temp; > > > > the amount of memory used by matlab shoots up by more than 1GB during this computation, then goes back down. what it started as. Why would A.*temp require SO much more memory, which appears to be the amount of memory that A and temp themselves take ??? I thought the whole point of having them in memory is so that we can do basic operations like multiplication very easily without having to dubplicate them ! > > FYI, the A.*temp calculation requires that temp first be converted from uint8 to double, hence the big memory increase necessary for the calculation. > > James Tursa Hi James ! Wow !! Thanks so much for taking the time to write those MEX routines ! That's incredibly kind, and I really appreciate it ! I was actually about to try writing a MEX routine in FORTRAN since array slicing can be done in FORTRAN , and that way I could hopefully avoid the for loops and do something that more closesly resembles: A.*K((indices(:,end-j)-1)*4+indices(:,end),j+1) My intuition is that doing array multiplications is faster than doing forloops .. but I'm often wrong about these things. ============== Also, I made a crucial typo in both of my posts: temp=((indices(:,end-j)-1)*4+indices(:,end),j+1); should actually read: temp=K((indices(:,end-j)-1)*4+indices(:,end),j+1); so A.*temp is exactly what I'm calculating, which is: A.*K((indices(:,end-j)-1)*4+indices(:,end),j+1); So everything is already double precision. But now I'm not able to reproduce the behaviour I noticed before .. Maybe Matlab isn't using up so much more RAM than necessary after all!