MATLAB - how to increase memory?

In summary, the problem is that the code is using too much memory and there is not enough memory to store the results of the code.
  • #1
mikeph
1,235
18
Hello,

I have a problem with my code, it uses too much memory. Aside from optimisation of the code (which I am constantly working on), how can I increase the memory which is available to MATLAB?

Code:
>> memory
Maximum possible array:             435 MB (4.564e+008 bytes) *
Memory available for all arrays:    902 MB (9.463e+008 bytes) **
Memory used by MATLAB:              820 MB (8.601e+008 bytes)
Physical Memory (RAM):             1980 MB (2.076e+009 bytes)

*  Limited by contiguous virtual address space available.
** Limited by virtual address space available.

I understand why RAM is limited, but I can't understand in the help file how I can increase the memory used by MATLAB.

I have three matrices in my workspace, two are about 1 MB and the third is huge (it is a sparse double matrix with 30 million elements), about 255 MB. I am trying to implement an algorithm which uses this matrix, and its transpose, and the code always fails when it needs to use the transpose, presumably because it needs another 255 MB to store the result.

But the memory for all arrays is 920 MB , and I have no array which is larger than 435 MB, so I don't understand what is taking up so much space.

Is there a MATLAB command that I can do which effectively says "ok you are allowed to use 1.5 GB of my 1.98 GB physical memory so do whatever you want? Or if this fails, and I buy more RAM, (and apparently you can use a windows switch to increase the max for anyone program from 2 to 3 GB), will it even help my problem?


Thanks for any help,
 
Physics news on Phys.org
  • #3
Wrichik Basu said:
Use the Parallel Computing Toolbox of Matlab. You'll be able to partition the array into different computers, thereby sharing the memory space.
I'm not sure that this would work. From what I understand of the way Matlab is parallelized, all data will still need to fit on the main node.

Without changing anything to the code, I see two possibilities. The best is to increase the memory on the computer. If that is not possible, it might be possible to increase the amount of virtual memory. The latter would most probably result in a much slower execution, however.
 
  • #4
The transpose doesn't have any additional information so there isn't really a need to create that second copy of your matrix. Can you rewrite the algorithm to work with just the original matrix, reference A(j,i) when you want the (i,j)-th element of A'?
 
  • Like
Likes Wrichik Basu
  • #5
DrClaude said:
I'm not sure that this would work. From what I understand of the way Matlab is parallelized, all data will still need to fit on the main node.
It can be done; I had seen someone parallelizing a huge matrix and it's transpose without saving it on the client. But I don't remember how he did it. Very limited resources exist on the net regarding the parallel computing toolbox. I'll try to get hold of the exact code by posting in matlab's community forums.
 

What is the maximum amount of memory that MATLAB can use?

The maximum amount of memory that MATLAB can use depends on the operating system and the version of MATLAB being used. In general, 32-bit versions of MATLAB have a maximum limit of 4GB of RAM, while 64-bit versions can use much more. The specific limit for your version of MATLAB can be found in the documentation or by using the memory function in the command window.

How can I increase the memory limit for MATLAB?

To increase the memory limit for MATLAB, you can use the memory function in the command window to check the current limit, and then use the maxSize option to set a new limit. You can also use the maxNumCompThreads function to increase the number of computational threads, which can also improve memory usage. Additionally, you can optimize your code to use memory more efficiently, such as preallocating arrays and avoiding unnecessary copies of data.

Can I use external memory sources with MATLAB?

Yes, MATLAB has the ability to use external memory sources, such as hard drives or solid state drives, to store and access data. This can be useful for working with large datasets that exceed the available RAM on your computer. To use external memory in MATLAB, you can use the matfile function to create a file handle that allows you to access data on the external memory source.

How can I free up memory in MATLAB?

To free up memory in MATLAB, you can use the clear function to remove variables from the workspace. You can also use the pack function to compact the memory and reduce fragmentation. Additionally, you can use the close function to close any open figures or other graphical objects that may be using memory.

What should I do if I am still running out of memory in MATLAB?

If you are still running out of memory in MATLAB, you may need to consider optimizing your code or increasing the amount of physical RAM on your computer. You can also try using the memory function to check for memory leaks or excessive memory usage by specific variables. If all else fails, you can try breaking your code into smaller chunks and processing them separately, or using external memory sources as mentioned earlier.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • Programming and Computer Science
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
Back
Top