How to solve "out of memory error" caused by bsxfun?

1 visualizzazione (ultimi 30 giorni)
Glazio
Glazio il 5 Ago 2017
Modificato: Glazio il 29 Ago 2017
If I try to enlarge the base sample size of 10000 by 500 samples (in the context wie a Sensitivity Analysis) the following error message occurs:
Error using bsxfun
Out of memory. Type HELP MEMORY for your options.
Error in ipdm>distcomp (line 1008)
d = bsxfun(@minus,set1(:,1),set2(:,1)').^2;
Error in ipdm (line 364)
d = distcomp(data1,data1,params);
Error in lhcube_extend (line 89)
dd=(ipdm(Xi,'metric',2)); dd=min(dd(dd>0));
Error in AAT_sampling_extend (line 125)
Uext = lhcube_extend(U,Next,nrep) ;
The script AAT_sampling_extend produces the error. AAT_sampling_extend is integrated in the SAFE-Toolbox (and has already been used several times).
I started this with the following command:
Xext = AAT_sampling_extend(X,DistrFun,DistrPar,2*(N+N2))
with
  • N = base sample size (N = 10.000)
  • N2 = extended sample size (N2 = 500)
  • X = Matrix of size 10.000 * 31
  • DistrFun = Latin hyper cube sampling
  • DistrPar = Parameters and their range
How can you solve the problem (without changing the source code too much)?
  1 Commento
Glazio
Glazio il 28 Ago 2017
I have upgraded the RAM (from 4 GB to 12 GB) and the same error message appears.
I have increased the virtual memory to the recommended value (18430 MB).
I have closed other applications (processes), cleaned unused large variables and pre-allocated arrays.
At the time of program-crash, more than 4 GB of RAM were still free. Currently I have no idea what the problem could be.
Does anyone have an idea (RAM, CPU aren't the problem)?

Accedi per commentare.

Risposte (2)

Jan
Jan il 5 Ago 2017
A 10000 by 500 array of type double requires 40MB only. If your computer does not have enough memory to allocate such a small array, then the best idea is to install more RAM. Other ideas:
  • Close other applications
  • Increase the virtual memory
  • Use the type single if precision is sufficient
  • Clean unused (large!) variables
  • Pre-allocate arrays (this might not necessarily help, but is a good programming practice in every case)
  • But nothing will beat real hardware RAM, so install more.
  10 Commenti
Jan
Jan il 28 Ago 2017
Sorry, the question is still not clear. Please stop Matlab when the problem occurs:
dbstop if error
Then tell us the dimensions of the variables "set1" and "set2". Formerly you mentioned a 10000 by 500 matrix, which needs 40 MB only. If you have 4GB of free memory, this cannot be the problem. If bsxfun tries to create a 10'000 x 10'000 matrix, this requires 800MB of RAM.
I hesitate to install the mentioned toolbox only to reproduce the problem, if you can find out the source of the problem so fast. Please check how much memory is required in the failing command.
Finally remember, that some problems demand for a huge RAM. If a code works with 500 samples, the required computation time can explode to millions of years for 1000 samples.
Glazio
Glazio il 28 Ago 2017
Modificato: Glazio il 28 Ago 2017
@ Jan Simon: Thanks for your answer,
the input-matrix has a dimension of 10000 x 31.
If I extend it by 10000 samples there are generated three matrices:
XA with 5000 x 31, XB with 5000 x 31 and XC with 155000 x 31.
If I extend it by 500 samples there are generated three matrices:
XA with 200 x 31, XB with 200 x 31, XC with 620 x 31
dbstop if error gives the following result:
Error using .^
Out of memory. Type HELP MEMORY for your options.
Error in ipdm>distcomp (line 1015)
d = d + bsxfun(@minus,set1(:,i),set2(:,i)').^2;
Error in ipdm (line 364)
d = distcomp(data1,data1,params);
Error in lhcube (line 88)
dk=(ipdm(Xk,'metric',2)); dk=min(dk(dk>0));
Error in lhcube_extend (line 86)
Xext=lhcube(N_new-N,M);
Error in AAT_sampling_extend (line 125)
Uext = lhcube_extend(U,Next,nrep) ;
Error in extended_sample (line 76)
Xext = AAT_sampling_extend(X,DistrFun,DistrPar,(N+N2)) ; % extended sample

Accedi per commentare.


Steven Lord
Steven Lord il 28 Ago 2017
Are you using a 32-bit or 64-bit version of MATLAB and version of your operating system? If you're using a 32-bit system, upgrade to a 64-bit system.
It seems like the function you're using calls this File Exchange submission or something similar and creates a 10000-by-10000 inter-point distance matrix during the course of its execution. That would require a contiguous block of memory about 750 MB in size. Anything you do that requires a new copy of that matrix may require another contiguous block of that same size.
  5 Commenti
Jan
Jan il 29 Ago 2017
Modificato: Jan il 29 Ago 2017
Then buy an Apple computer. Sorry, just kidding.
Perhaps the student versions have been limited to 32 bit. Contacting the support directly can clear this directly. Simply use the "Contact us" button on this page.
Glazio
Glazio il 29 Ago 2017
Modificato: Glazio il 29 Ago 2017
@ Jan Simon: Thanks for your answer. I would prefer Linux as a operating system ;-)
2012a is not available for 64-bit Windows system. This means that a new license must be purchased.

Accedi per commentare.

Categorie

Scopri di più su Install Products 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