Re: Redirecting output to file
- To: mathgroup@smc.vnet.net
- Subject: [mg12360] Re: [mg12284] Redirecting output to file
- From: Daniel Lichtblau <danl@wolfram.com>
- Date: Sun, 10 May 1998 02:04:43 -0400
- References: <199805072251.SAA00872@smc.vnet.net.>
V. Nandagopal wrote:
>
> Hello,
>
> I am doing some computations which I want to be written to a file. The
> usual (>> or >>) is not sufficient as Mathematica waits for the entire
> computation to be over before writing to the file. Is there any way I
> can make Mathematica write to a file dynamically?
>
> The computation I attempted was the following:
>
> <<combinatorica.m
>
> e={{-1, -1, 0, 0, 2}, {-1, -1, 0, 2, 0}, {-1, -1, 2, 0, 0}, {-1, 0, -1,
> 0, 2},
> {-1, 0, -1, 2, 0}, {-1, 0, 0, -1, 2}, {-1, 0, 0, 2, -1}, {-1, 0, 2,
> -1, 0},
> {-1, 0, 2, 0, -1}, {-1, 2, -1, 0, 0}, {-1, 2, 0, -1, 0}, {-1, 2, 0, 0,
> -1},
> {0, -1, -1, 0, 2}, {0, -1, -1, 2, 0}, {0, -1, 0, -1, 2}, {0, -1, 0, 2,
> -1},
> {0, -1, 2, -1, 0}, {0, -1, 2, 0, -1}, {0, 0, -1, -1, 2}, {0, 0, -1, 2,
> -1},
> {0, 0, 2, -1, -1}, {0, 2, -1, -1, 0}, {0, 2, -1, 0, -1}, {0, 2, 0, -1,
> -1},
> {2, -1, -1, 0, 0}, {2, -1, 0, -1, 0}, {2, -1, 0, 0, -1}, {2, 0, -1,
> -1, 0},
> {2, 0, -1, 0, -1}, {2, 0, 0, -1, -1}, {-1, -1, 0, 1, 1}, {-1, -1, 1,
> 0, 1}, {-1, -1, 1, 1, 0}, {-1, 0, -1, 1, 1},
> {-1, 0, 1, -1, 1}, {-1, 0, 1, 1, -1}, {-1, 1, -1, 0, 1}, {-1, 1, -1,
> 1, 0},
> {-1, 1, 0, -1, 1}, {-1, 1, 0, 1, -1}, {-1, 1, 1, -1, 0}, {-1, 1, 1, 0,
> -1},
> {0, -1, -1, 1, 1}, {0, -1, 1, -1, 1}, {0, -1, 1, 1, -1}, {0, 1, -1,
> -1, 1},
> {0, 1, -1, 1, -1}, {0, 1, 1, -1, -1}, {1, -1, -1, 0, 1}, {1, -1, -1,
> 1, 0},
> {1, -1, 0, -1, 1}, {1, -1, 0, 1, -1}, {1, -1, 1, -1, 0}, {1, -1, 1, 0,
> -1},
> {1, 0, -1, -1, 1}, {1, 0, -1, 1, -1}, {1, 0, 1, -1, -1}, {1, 1, -1,
> -1, 0},
> {1, 1, -1, 0, -1}, {1, 1, 0, -1, -1}, {-1, 0, 0, 0, 1}, {-1, 0, 0, 1,
> 0}, {-1, 0, 1, 0, 0}, {-1, 1, 0, 0, 0},
> {0, -1, 0, 0, 1}, {0, -1, 0, 1, 0}, {0, -1, 1, 0, 0}, {0, 0, -1, 0,
> 1},
> {0, 0, -1, 1, 0}, {0, 0, 0, -1, 1}, {0, 0, 0, 1, -1}, {0, 0, 1, -1,
> 0},
> {0, 0, 1, 0, -1}, {0, 1, -1, 0, 0}, {0, 1, 0, -1, 0}, {0, 1, 0, 0,
> -1},
> {1, -1, 0, 0, 0}, {1, 0, -1, 0, 0}, {1, 0, 0, -1, 0}, {1, 0, 0, 0,
> -1}}; KSubsets[e,4] >> result.out
>
> I am running Mathematica 3.0 for Digital Alpha workstation
> (Alpha@433MHz, with 128MB RAM and oodles of hard disk space. But
> Mathematica exits on the above saying "Out of Memory".
>
> Thanks in advance,
>
> V. Nandagopal
> School of Mathematics
> Tata Institute of Fundamental Research
> Colaba, Bombay 400 005, India
> e-mail: nandgopa@math.tifr.res.in
In[2]:= Length[e]
Out[2]= 80
So let's see how many elements your result will have.
In[4]:= Binomial[80,4]
Out[4]= 1581580
Each element is in effect a matrix: a list of four lists of five
integers. So above and beyond the list overhead we'll need to store
twenty integers. How much space does an integer occupy?
In[5]:= ByteCount[Range[100]]
Out[5]= 1620
Probably 16 bytes, with the remaining 20 for list overhead. Let's
double-check.
In[6]:= ByteCount[Range[200]]
Out[6]= 3220
16 bytes per integer it is. Do we save anything when the lists contain
the same integers?
In[7]:= ByteCount[Table[1, {100}]]
Out[7]= 1620
No such luck. So storage for your result will be larger than
(16 bytes-per-integer) * (20 integers-per-element) * (1.5Meg elements)
Actually the product of the first two, 320, can be replaced by 416:
In[8]:= ByteCount[Table[i+j, {i,4}, {j,5}]] Out[8]= 416
So you will need around 600 M to contain the result. I do not know
whether this size is cause for the behavior you saw, just thought I
would point out that you are trying to write a very large object to a
file. Possibly it produces the object but dies in formatting.
Daniel Lichtblau
Wolfram Research
- References:
- Redirecting output to file
- From: "V. Nandagopal" <nandgopa@math.tifr.res.in>
- Redirecting output to file