[Macaulay2] how to track time and repetition

80 views
Skip to first unread message

Yi

unread,
May 3, 2010, 8:58:58 PM5/3/10
to Macaulay2
I need to program some time consuming codes. I usually set a counter
for the loops, for example "i=1; while p list x do (i=i+1; ...)", then
after one or two days, I press Ctrl+C to stop it, check how many loops
it works, then resume. To do this, I always need to set several new
variables to store the status of each step. And I have to write down
the initial time myself.

Is there anyway to track the number of repetition and track the time
consumed automatically, without interrupting the running? For example,
can we ask the program to print the time whenever it passes 1 hour or
1 day, or print the number of repetition whenever it does 10^6 times?

Thank you very much for your time and help.

--
You received this message because you are subscribed to the Google Groups "Macaulay2" group.
To post to this group, send email to maca...@googlegroups.com.
To unsubscribe from this group, send email to macaulay2+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/macaulay2?hl=en.

Message has been deleted

brandon...@gmail.com

unread,
May 3, 2010, 11:23:30 PM5/3/10
to Macaulay2
Hi Yi,

You may want to look at currentTime:
http://www.math.uiuc.edu/Macaulay2/doc/Macaulay2-1.3.1/share/doc/Macaulay2/Macaulay2Doc/html/_current__Time.html

and to only show every one million iterations something like:
if i % 10^6 == 0 then << i*10^6 << " iterations have elapsed." <<
endl;

zhan...@umn.edu

unread,
May 4, 2010, 12:03:18 AM5/4/10
to maca...@googlegroups.com
Dear Brandon,

Thank you very much for your help.

The command currentTime is great.

To count the repetition, is there a way not to define a new counter i and
make i=i+1 every time? Can we refer to an internal counter, like the
command currentTime? Am I asking for something impossible? :)

Thanks again and have a nice evening.

Sincerely,
Yi

brandon...@gmail.com

unread,
May 4, 2010, 12:11:03 AM5/4/10
to Macaulay2
If I understand correctly, the answer depends on the type of loop you
are using. For a while loop, you would need to explicitly put in a
counter, but a for loop using an iterator variable automatically
updates the iterator variable, so you have one for free (in the sense
of not having to type out the code "i=i+1"). In a while loop, I don't
think there is an internal counter since it makes no sense for there
to be one; the terminating condition is typically not in terms of
number of iterations, but some other condition.


On May 4, 12:03 am, zhang...@umn.edu wrote:
> Dear Brandon,
>
> Thank you very much for your help.
>
> The command currentTime is great.
>
> To count the repetition, is there a way not to define a new counter i and
> make i=i+1 every time? Can we refer to an internal counter, like the
> command currentTime? Am I asking for something impossible? :)
>
> Thanks again and have a nice evening.
>
> Sincerely,
> Yi
>
> On May 3 2010, Brandon.Bar...@gmail.com wrote:
>
>
>
>
>
> >Hi Yi,
>
> >You may want to look at currentTime:
>
> >http://www.math.uiuc.edu/Macaulay2/doc/Macaulay2-1.3.1/share/doc/Maca...

Dan Grayson

unread,
May 4, 2010, 9:19:04 AM5/4/10
to Macaulay2
There is also the function "cpuTime", which gives the amount of cpu
time consumed so far:

http://www.math.uiuc.edu/Macaulay2/doc/Macaulay2-1.3.1/share/doc/Macaulay2/Macaulay2Doc/html/_cpu__Time.html

Yi Zhang

unread,
May 4, 2010, 3:29:38 PM5/4/10
to maca...@googlegroups.com
Dear Professor Grayson and Brandon,

Thank you very much for your time and help. Have a nice day.

Sincerely,
Yi
Reply all
Reply to author
Forward
0 new messages