MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Redirecting output to file



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



  • Prev by Date: What Algorhythm(s) Do(es) 'Rationalize[]' Use?
  • Next by Date: Re: Determinant
  • Prev by thread: Redirecting output to file
  • Next by thread: Re: Redirecting output to file