Question: Can I write a shell script that executes a maple code beginning with "restart"?

Hello,

I've written a code that I'd ultimately like to process in parallel over a grid of parameters, but before I can even think of doing that, I need to find a workaround for the memory allocation issues I'm having. Probably due to the way that it's written, Maple's built in garbage collection isn't working very well (if at all), and the code allocates another 100 MB or so every 10,000 iterations. Even if I content myself with running it for say 200,000 iterations, which is about my lower limit, it therefore uses up 2 GB of memory. Manual garbage collection doesn't completely help, since memory allocation still goes up a few MB every 10^4 iterations, and the code slows down by an order of magnitude or two.

As I said, I'd like to run the code over a grid (of, say, at least 100 sets of parameter values). The outputs over this grid are independent, so I could do this with a restart for each set of parameters, and have Maple output my results to a new file each time; but I'd rather not have to execute it manually for each parameter set. My question is, can I include a restart in the first line of the code, and then run it from somewhere else? Can I run a shell script that will execute the code for multiple sets of parameters in parallel, so that I only need to hit return once and utilise all of my processors?

I know Maple's GUI won't "read" a file that begins with "restart", but can I get past this issue by executing through cmaple? I'm running Mac OS X 10.8, so I think a shell script is what I'd need to write if this is possible, but to be honest, my knowledge of computing is very limited.

In order to illustrate the kind of thing I'm wanting to do, I've written something simple that executes a process in series. 

> x := proc (a, b) local i, j; global A, B, n;

restart;

for i to n do for j to n do A[i, j] := a*i*j; B[i, j] := b*i*j end do end do;

return A+B

end proc:


> n := 1000; A := Array(1 .. n, 1 .. n); B := Array(1 .. n, 1 .. n);

for a from 0 by .1 to 1 do for b from 0 by .1 to 1 do

C := x(a, b);

print(add(i, `in`(i, C)));

end do end do;

 

Here's the output:


Warning, the restart command only works at the top level. It cannot be executed within a procedure, or from a file being read by the read statement.


0

Warning, the restart command only works at the top level. It cannot be executed within a procedure, or from a file being read by the read statement.

2.505002538 10^10 

Warning, the restart command only works at the top level. It cannot be executed within a procedure, or from a file being read by the read statement.

5.010005242 10^10 

Warning, the restart command only works at the top level. It cannot be executed within a procedure, or from a file being read by the read statement.

7.515007391 10^10

Warning, the restart command only works at the top level. It cannot be executed within a procedure, or from a file being read by the read statement.

1.002001000 10^11 

Warning, the restart command only works at the top level. It cannot be executed within a procedure, or from a file being read by the read statement.

1.252501088 10^11 

Warning, the restart command only works at the top level. It cannot be executed within a procedure, or from a file being read by the read statement.
Warning, computation interrupted

 

At this point, my memory usage is already up to 464.77M. Adding gc() after the print statement gets it down to 262.59M at the same point. Any help with this would be very much appreciated. It seems like I've got to be able to write something that will say, put these two numbers into that code and execute; and then put these two numbers in and execute; etc.; where each execution begins by wiping the slate clean. Do I need to write that something in another programme and execute the Maple code using OpenMaple? It seems like it would be better to run through Terminal.

Thanks in advance.

Daryl

Please Wait...