Out of Memory error

21 visualizzazioni (ultimi 30 giorni)
Neil
Neil il 23 Ago 2022
Commentato: John D'Errico il 23 Ago 2022
Hi, The "maximum possible array" is much lower than the physical memory leading to out-of-memory error. Is there any way I can increase the max possible array? Thanks
>> memory
Maximum possible array: 5176 MB (5.427e+09 bytes) *
Memory available for all arrays: 5176 MB (5.427e+09 bytes) *
Memory used by MATLAB: 2040 MB (2.139e+09 bytes)
Physical Memory (RAM): 32768 MB (3.436e+10 bytes)
* Limited by System Memory (physical + swap file) available.

Risposta accettata

Rik
Rik il 23 Ago 2022
Matlab stores arrays in contiguous blocks of memory. I have always interpreted that to mean it cannot cross RAM-sticks (so if you have multiple 16GB sticks you can only have 16GB for each array). I don't know whether that interpretation is correct (probably not).
You can see some advice in the documentation here.
  2 Commenti
Neil
Neil il 23 Ago 2022
Thanks Rik, I'll have to take up with my systems support but think that's the answer that makes sense.
John D'Errico
John D'Errico il 23 Ago 2022
I don't think that is at least completely true. Say you have only 8GB of RAM.
1 - Create a double precision variable (V1) that uses 5GB of RAM.
2 - Create a scalar double precision variable (V2)
At this point, you have two variables in memory.. The memory map will have that little scalar sitting out in the wees. but where can it go?
3 - Next, clear V1
V2 does not change its location in memory. You now have two blocks of contiguous memory to be found, so even though you have 8 GB of RAM, you have only a maximum block of 5GB of contiguous memory. Clearing V2 will remove that limitation, or performing a pack command can help.
help pack
PACK Consolidate workspace memory. PACK performs memory garbage collection. Extended MATLAB sessions may cause memory to become fragmented, preventing large variables from being stored. PACK is a command that saves all variables on disk, clears the memory, and then reloads the variables. If you run out of memory often, here are some additional system specific tips: Windows: Increase virtual memory using the control panel. Unix: Ask your system manager to increase your Swap Space. You should cd to a directory where you have "write" permission to execute this command successfully. The following lines of code will help you accomplish the consolidation of workspace memory. cwd = pwd; cd(tempdir); pack cd(cwd) See also MEMORY, SAVE, LOAD, CLEAR. Documentation for pack doc pack
You can of course get some information about the memory available to you using the memory conmmand, (but only on Windoze systems.)
help memory
MEMORY Memory information. See 'doc memory' for more information on how to make the best use of memory when running MATLAB. MEMORY when called without an output argument displays information about how much memory is available and how much is currently being used by MATLAB. All values are double precision and in units of bytes. USERVIEW = MEMORY returns information about how much memory is available and how much is currently being used by MATLAB. USERVIEW is a structure that contains the following fields: MaxPossibleArrayBytes -- The largest contiguous free memory block. It is an upper bound on the largest single array that MATLAB can currently create. This field is the smaller of these two values: a) The largest contiguous memory block found in the MATLAB virtual address space, or b) The total available system memory. To find the number of elements, divide MaxPossibleArrayBytes by the size of each element in bytes. For example, divide by eight for a double matrix. The actual number of elements that that can be created is always less than this number. MemAvailableAllArrays -- The total amount of memory available for data. This field is the smaller of these two values: a) The total available MATLAB virtual address space, or b) The total available system memory. The amount of memory available is guaranteed to be at least as large as this field. MemUsedMATLAB -- The total amount of system memory reserved for the MATLAB process. This is the sum of the physical memory and potential swap file usage. [USERVIEW, SYSTEMVIEW] = MEMORY returns additional, and more detailed information about the current state of memory usage. SYSTEMVIEW is a structure containing the following: VirtualAddressSpace -- A 2-field structure that contains the amount of available memory and the total amount of virtual memory for the MATLAB process. SystemMemory -- A 1-field structure that contains the amount of available system memory. This number includes the amount of available physical memory and the amount of available swap file space on the computer running MATLAB. PhysicalMemory -- A 2-field structure that contains the amount of available physical memory and the total amount of physical memory on the computer running MATLAB. It can be useful as a measure of how much data can be accessed quickly. The MEMORY function is currently available on PCWIN and PCWIN64 only. Results will vary depending on the computer running MATLAB, the load on the computer, and what MATLAB is doing at the time. Example 1: Run the MEMORY command on a 32-bit Windows system: >> memory Maximum possible array: 677 MB (7.101e+008 bytes) * Memory available for all arrays: 1602 MB (1.680e+009 bytes) ** Memory used by MATLAB: 327 MB (3.425e+008 bytes) Physical Memory (RAM): 3327 MB (3.489e+009 bytes) * Limited by contiguous virtual address space available. ** Limited by virtual address space available. >> Example 2: Run the MEMORY command on a 64-bit Windows system: >> memory Maximum possible array: 4577 MB (4.800e+009 bytes) * Memory available for all arrays: 4577 MB (4.800e+009 bytes) * Memory used by MATLAB: 330 MB (3.458e+008 bytes) Physical Memory (RAM): 3503 MB (3.674e+009 bytes) * Limited by System Memory (physical + swap file) available. >> Example 3: Run the MEMORY command with two outputs on a 32-bit Windows system: >> [uV sV] = memory uV = MaxPossibleArrayBytes: 710127616 MemAvailableAllArrays: 1.6797e+009 MemUsedMATLAB: 345354240 sV = VirtualAddressSpace: [1x1 struct] SystemMemory: [1x1 struct] PhysicalMemory: [1x1 struct] >> sV.VirtualAddressSpace ans = Available: 1.6797e+009 Total: 2.1474e+009 >> sV.SystemMemory ans = Available: 4.4288e+009 >> sV.PhysicalMemory ans = Available: 2.5376e+009 Total: 3.4889e+009 Documentation for memory doc memory

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 23 Ago 2022
Modificato: Image Analyst il 23 Ago 2022
You have 32 GB of physical RAM but how much swap space have you set up? Why don't you just increase the amount of swap space?

Categorie

Scopri di più su Performance and Memory in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by