Search code examples
shellunixtimemaple

Calling Maple in Unix-shell without shell time overwriting


I have a question: I want to time some calculations using the UNIX-time command and I figured out that Maple (I use version 16) on Ubuntu 12.04 LTS (and some other machines I tested, including Macs) has some odd properties.

calling

time maple < testCalc.txt

where testCalc.txt contains the following code:

with(DETools):
DFactor(mult(x^5*d^5 + 6*x*d +1,x^5*d^5 + x^2*d^2 +7,[d,x]),[d,x]);

results in the following output:

memory used=65.5MB, alloc=72.9MB, time=0.69
memory used=199.6MB, alloc=149.9MB, time=1.84
memory used=312.4MB, alloc=149.9MB, time=2.97
memory used=592.3MB, alloc=312.4MB, time=5.63
memory used=854.7MB, alloc=312.4MB, time=9.80
["The Result (long)"]
memory used=1132.9MB, alloc=312.4MB, time=13.06

But the additional three lines of "time" say

real         0m47.872s
user         0m0.016s
sys          0m0.000s

Clearly, the user and sys time is wrong, as maple spend 13 seconds according to its own time measurement.

It seems to me that maple uses the same sources as the time command and resets the timer every time it uses it, such that the unix-time command only captures the time since the last call of maple to this source.

This is very inconvenient, and I would like to "forbid" maple doing that. Does anyone know how to do that? Is there some flag for calling maple that lets maple not measure the timestamps on its own?

Thanks in advance for an answer.

Albert


Solution

  • Ugly hack coming up.

    As I said in my comment, the problem is that Maple is launching a sub-process to do all of the computations. So, I created a shell script called "mserver" in my bin that looks like

    #!/bin/sh
    /usr/bin/time "REPLACE WITH PATH TO MSERVER ON YOUR MACHINE/mserver" $* 2> log
    

    I then invoked Maple as

    maple --kernel-binary=/Users/me/bin/mserver
    

    At the end of a run, the file log contains the correct "time" output for the computation.

    Edit: I should point out that if the Maple protocols use stderr for anything, then this will eventually cause Maple to break. I haven't seen any sign of it but I've only just played with this now.