Question: Huge memory usage

I am faced by the problem where I used Grid:-Seq()---locally---to do some long time computation and I am faced by the exhaustion of memory problem. I think the problem itself is related to the memory management in maple.

So the problematic function is

# Procedure: ComputeEventsCTypeGrid
#   Compute events such that three quadrics intersects in a point.
#
# Parameters:
#   Q          - a set of quadrics
#
# Output:
#   Indexes of quadrics which intersect in a point.
# TODO:
#  - Memory
#  - Cleanups
ComputeEventsCTypeGrid := proc( Q )
  local s, cType, i, j, k, rootNb, univ, sys;
  s := proc (i, j, k)
    sys := [ Q[i], Q[j], Q[k] ];
    univ := PolynomialIdeals[UnivariatePolynomial]( indets( sys )[1], sys );
    if not type( univ, constant ) then
      rootNb := nops(select(proc(x)op(x)[2]>0;end proc,RootFinding:-Isolate( univ, [ op( indets(univ ) ) ] )) ):
      if rootNb > 0 then
        return [ univ, rootNb, sys ];
      end if:
    end if:
  end proc;
  cType := [Grid:-Seq(seq(seq(s(i,j,k),k=j+1..nops(Q)),j=i+1..nops(Q)),i=1..nops(Q))];
  return cType;
end proc:

A dump from top after calling ComputeEventsCTypeGrid for some data(total amount of memory on this machine is 251G + 48G swap)

VIRT    RES    SHR S  %CPU %MEM     TIME+

33.007g 0.031t   3676 S   0.0 12.5   2606:20
31.137g 0.029t   3436 S   0.0 11.7   2274:34
8645756 4.984g   2840 S   0.0  2.0  32:06.40
28.798g 0.026t   1968 S   0.0 10.7   1821:16
26.650g 0.024t   1968 S   0.0  9.8   1520:54
25.346g 0.023t   1968 S   0.0  9.2   1236:44
23.296g 0.021t   1968 S   0.0  8.4   1004:52
20.498g 0.018t   1968 S   0.0  7.4 790:30.81
16.799g 0.014t   1968 S   0.0  5.9 625:28.12
15.011g 0.013t   1968 S   0.0  5.2 469:36.27
7678444 4.149g   1968 S   0.0  1.6 104:34.22
6734804 623904   1968 S   0.0  0.2  73:13.13
4327420 132516   1968 S   0.0  0.1  24:11.51
3420712 111336   1968 S   0.0  0.0  11:26.16
13.671g 0.011t   1964 S   0.0  4.6 380:15.13
11.771g 9.831g   1964 S   0.0  3.9 274:25.59
9936056 7.769g   1964 S   0.0  3.1 201:13.94
8805512 3.394g   1964 S   0.0  1.3 148:09.53
5077056 1.500g   1964 S   0.0  0.6  42:19.29
2384784  82040   1832 S   0.0  0.0   3:56.57

Size of output data calculated with

> length(sprintf("%m", eval(cType)));

> 326260610

Also, I called gc() at the end of the computations but memory allocated by instances of mserver were not released. Does it mean gc() should be called from each instance separately? My final point is that I have to run some other calculations for different and bigger dataset (It will probably take 2 days to finish -- Q has around 700 polynomials of degree 2) and for this moment I cannot do this because I've gotten an error about not enough amount of memory.

Please Wait...