3 edited title

Out otof memory in a Do loop

2 edited body

I have the following code:

out = {};
f[x_, y_, z_] := f[x, y, z] = x^3 + y^3 + z^3
Do[SeedRandom[];
x = RandomInteger[{10^2, 10^3}];
y = -RandomInteger[{10^2, 10^3}];
z = RandomChoice[{-1, 1}] RandomInteger[{10^2, 10^3}];
sol = f[x, y, z];
If[3 <= sol <= 1000,{AppendTo[out, {sol, {x,y,z}}],Export["new_k.dat", out, "Table"], Continue[]}, Continue[]],10^6];
out


which does a conceptually simple task: it randomly choses a triple {x,y,z} and computes sol as the sum of cubes. If sol is small enough, I want it to AppendTo to a predefined list out and Export that list to a file. The code is supposed to run a given number of iterations regardless of the number of sol's found (in fact, there will be very few instances that pass my criteria).

The problem is that even with the 10^6 iterations it uses a few Gb of memory. When I wanted to do 10^7, my computer crashed.

The procedure is rather straightforward: it draws a few numbers, do some algebra and comparison, and IF it fulfills the condition, it gets to be stored in out. So I expected it will use almost none memory, as I don't need it to remember all the instances when sol didn't meet the condition. It goes like numbers-condition-store or not-if not then don't remember anything-continue for a given number of iterations.

My intention in writing this in such a way is to run it for e.g. 10^10 iterations, go away and see in the file new_k.txt after a few hours if maybe some triple {x,y,z,} was found without interferring with the still running computation. Writing directly to a file is in case of power shortage or something.

(The range of {x,y,z} is intended to be bit larger, those above are just for the code to give sometimes an output sometimes)

I have the following code:

out = {};
f[x_, y_, z_] := f[x, y, z] = x^3 + y^3 + z^3
Do[SeedRandom[];
x = RandomInteger[{10^2, 10^3}];
y = -RandomInteger[{10^2, 10^3}];
z = RandomChoice[{-1, 1}] RandomInteger[{10^2, 10^3}];
sol = f[x, y, z];
If[3 <= sol <= 1000,{AppendTo[out, {sol, {x,y,z}}],Export["new_k.dat", out, "Table"], Continue[]}, Continue[]],10^6];
out


which does a conceptually simple task: it randomly choses a triple {x,y,z} and computes sol as the sum of cubes. If sol is small enough, I want it to AppendTo to a predefined list out and Export that list to a file. The code is supposed to run a given number of iterations regardless of the number of sol's found (in fact, there will be very few instances that pass my criteria).

The problem is that even with the 10^6 iterations it uses a few Gb of memory. When I wanted to do 10^7, my computer crashed.

The procedure is rather straightforward: it draws a few numbers, do some algebra and comparison, and IF it fulfills the condition, it gets to be stored in out. So I expected it will use almost none memory, as I don't need it to remember all the instances when sol didn't meet the condition. It goes like numbers-condition-store or not-if not then don't remember anything-continue for a given number of iterations.

My intention in writing this in such a way is to run it for e.g. 10^10 iterations, go away and see in the file new_k.txt after a few hours if maybe some triple {x,y,z,} was found without interferring with the still running computation. Writing directly to a file is in case of power shortage or something.

(The range of {x,y,z} is intended to be bit larger, those above are just for the code to give sometimes an output)

I have the following code:

out = {};
f[x_, y_, z_] := f[x, y, z] = x^3 + y^3 + z^3
Do[SeedRandom[];
x = RandomInteger[{10^2, 10^3}];
y = -RandomInteger[{10^2, 10^3}];
z = RandomChoice[{-1, 1}] RandomInteger[{10^2, 10^3}];
sol = f[x, y, z];
If[3 <= sol <= 1000,{AppendTo[out, {sol, {x,y,z}}],Export["new_k.dat", out, "Table"], Continue[]}, Continue[]],10^6];
out


which does a conceptually simple task: it randomly choses a triple {x,y,z} and computes sol as the sum of cubes. If sol is small enough, I want it to AppendTo to a predefined list out and Export that list to a file. The code is supposed to run a given number of iterations regardless of the number of sol's found (in fact, there will be very few instances that pass my criteria).

The problem is that even with the 10^6 iterations it uses a few Gb of memory. When I wanted to do 10^7, my computer crashed.

The procedure is rather straightforward: it draws a few numbers, do some algebra and comparison, and IF it fulfills the condition, it gets to be stored in out. So I expected it will use almost none memory, as I don't need it to remember all the instances when sol didn't meet the condition. It goes like numbers-condition-store or not-if not then don't remember anything-continue for a given number of iterations.

My intention in writing this in such a way is to run it for e.g. 10^10 iterations, go away and see in the file new_k.txt after a few hours if maybe some triple {x,y,z,} was found without interferring with the still running computation. Writing directly to a file is in case of power shortage or something.

(The range of {x,y,z} is intended to be bit larger, those above are just for the code to give an output sometimes)

1

Out ot memory in a Do loop

I have the following code:

out = {};
f[x_, y_, z_] := f[x, y, z] = x^3 + y^3 + z^3
Do[SeedRandom[];
x = RandomInteger[{10^2, 10^3}];
y = -RandomInteger[{10^2, 10^3}];
z = RandomChoice[{-1, 1}] RandomInteger[{10^2, 10^3}];
sol = f[x, y, z];
If[3 <= sol <= 1000,{AppendTo[out, {sol, {x,y,z}}],Export["new_k.dat", out, "Table"], Continue[]}, Continue[]],10^6];
out


which does a conceptually simple task: it randomly choses a triple {x,y,z} and computes sol as the sum of cubes. If sol is small enough, I want it to AppendTo to a predefined list out and Export that list to a file. The code is supposed to run a given number of iterations regardless of the number of sol's found (in fact, there will be very few instances that pass my criteria).

The problem is that even with the 10^6 iterations it uses a few Gb of memory. When I wanted to do 10^7, my computer crashed.

The procedure is rather straightforward: it draws a few numbers, do some algebra and comparison, and IF it fulfills the condition, it gets to be stored in out. So I expected it will use almost none memory, as I don't need it to remember all the instances when sol didn't meet the condition. It goes like numbers-condition-store or not-if not then don't remember anything-continue for a given number of iterations.

My intention in writing this in such a way is to run it for e.g. 10^10 iterations, go away and see in the file new_k.txt after a few hours if maybe some triple {x,y,z,} was found without interferring with the still running computation. Writing directly to a file is in case of power shortage or something.

(The range of {x,y,z} is intended to be bit larger, those above are just for the code to give sometimes an output)