2
$\begingroup$

I'm using

13.0.0 for Microsoft Windows (64-bit) (December 3, 2021)

When I repeatedly run the command

ClearAll[testset]
testset = {#} & /@ Range[0.1, 1000, 0.0001];

I notice that the memory usage of mathematica in task manager keeps increasing, altough I would expect it to stay constant. Is this a bug or am I missing something? I also observed that if I use

ClearAll[testset]
testset = {#} & /@ Range[0.1, 1000, 0.0001];// AbsoluteTiming

instead, It behaves as expected and the memory usage does not keep increasing with repeated evaluations.

Now, let's try to use this list in the compiled function:

test[x_] := {x, x^2, x^3};
testvars = {x};
ctest = With[{varsC = testvars, fun = test[testvars]},
   Compile[{{X, _Complex, 1}},
    Block[varsC, varsC = X; fun],
    RuntimeAttributes -> {Listable},
    Parallelization -> True,
    RuntimeOptions -> "Speed"]];

When I evaulate

{#, #^2, #^3} & /@ Range[0.1, 1000, 0.0001];

or

ctest[#] & /@ testset;

then there is no problem with the memory usage. Buuuut, when I run the listable version of the compiled function

ctest[testset];

It eats a huge chunk of memory again (and the //AbsoluteTiming does not help here either). Note, that I don't even save the result of the computation to a variable. Is this a bug or am I missing something? If it is a bug then is there a workaround to use the listable version of the compiled function without the memory problem?

$\endgroup$
2
  • 1
    $\begingroup$ Did you try it with $HistoryLength=0? $\endgroup$ Jun 13, 2023 at 17:34
  • 1
    $\begingroup$ Yes, it does solve my first question. Thanks, I missed this. However, the listable version of the compiled function still eats more memory with each subsequent run and the memory is not reclaimed. $\endgroup$
    – dzsoga
    Jun 14, 2023 at 8:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.