https://iridia.ulb.ac.be/w/index.php?title=How_to_run_your_code_for_2_CPU-seconds&feed=atom&action=history
How to run your code for 2 CPU-seconds - Revision history
2024-03-29T16:00:33Z
Revision history for this page on the wiki
MediaWiki 1.35.4
https://iridia.ulb.ac.be/w/index.php?title=How_to_run_your_code_for_2_CPU-seconds&diff=5980&oldid=prev
Mascia at 19:20, 19 March 2012
2012-03-19T19:20:30Z
<p></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 19:20, 19 March 2012</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td>
</tr>
<tr>
<td class="diff-marker">−</td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Registering an alarm with SIGALRM allows to stop the execution after the specified amount of seconds (wall-clock time). <del class="diffchange diffchange-inline">To stop after a given amount of CPU-seconds you should use SIGPROF instead.</del></div></td>
<td class="diff-marker">+</td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Registering an alarm with SIGALRM allows to stop the execution after the specified amount of seconds (<ins class="diffchange diffchange-inline">'''</ins>wall-clock time<ins class="diffchange diffchange-inline">'''</ins>). </div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty"> </td>
<td class="diff-marker">+</td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"></td>
</tr>
<tr>
<td colspan="2" class="diff-empty"> </td>
<td class="diff-marker">+</td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>To stop after a given amount of '''CPU-seconds''' you should use SIGPROF.</div></td>
</tr>
<tr>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td>
</tr>
<tr>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Copy the following example in 'test.c':</div></td>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Copy the following example in 'test.c':</div></td>
</tr>
</table>
Mascia
https://iridia.ulb.ac.be/w/index.php?title=How_to_run_your_code_for_2_CPU-seconds&diff=5977&oldid=prev
Mascia: How to run your code for 10 CPU-seconds moved to How to run your code for 2 CPU-seconds
2012-03-19T19:19:20Z
<p><a href="/wiki/How_to_run_your_code_for_10_CPU-seconds" class="mw-redirect" title="How to run your code for 10 CPU-seconds">How to run your code for 10 CPU-seconds</a> moved to <a href="/wiki/How_to_run_your_code_for_2_CPU-seconds" title="How to run your code for 2 CPU-seconds">How to run your code for 2 CPU-seconds</a></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 19:19, 19 March 2012</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
Mascia
https://iridia.ulb.ac.be/w/index.php?title=How_to_run_your_code_for_2_CPU-seconds&diff=5976&oldid=prev
Mascia: New page: Registering an alarm with SIGALRM allows to stop the execution after the specified amount of seconds (wall-clock time). To stop after a given amount of CPU-seconds you should use SIGPROF i...
2012-03-19T19:18:53Z
<p>New page: Registering an alarm with SIGALRM allows to stop the execution after the specified amount of seconds (wall-clock time). To stop after a given amount of CPU-seconds you should use SIGPROF i...</p>
<p><b>New page</b></p><div>Registering an alarm with SIGALRM allows to stop the execution after the specified amount of seconds (wall-clock time). To stop after a given amount of CPU-seconds you should use SIGPROF instead.<br />
<br />
Copy the following example in 'test.c':<br />
<pre><br />
#include <signal.h><br />
#include <stdlib.h><br />
#include <stdio.h><br />
#include <sys/time.h><br />
#include <time.h><br />
<br />
int run;<br />
<br />
static void stop(int _)<br />
{<br />
run = 0;<br />
}<br />
<br />
float do_something() {<br />
/* some random computation, this example comes from http://www.cplusplus.com/forum/beginner/1149/ */<br />
unsigned int decP;<br />
unsigned int denom=3;<br />
float ourPi=4.0f;<br />
int addFlop=1;<br />
int i = 1;<br />
<br />
run = 1;<br />
while (run) {<br />
if (addFlop) {<br />
ourPi -= (4.0/denom);<br />
addFlop = 0;<br />
denom += 2;<br />
} else {<br />
ourPi += (4.0/denom);<br />
addFlop = 1;<br />
denom += 2;<br />
}<br />
i++;<br />
}<br />
<br />
return ourPi;<br />
}<br />
<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
time_t t = time(NULL);<br />
struct itimerval timer;<br />
<br />
int max_time = 2; /* two seconds */<br />
<br />
timer.it_value.tv_sec = max_time;<br />
timer.it_value.tv_usec = 0;<br />
timer.it_interval.tv_sec = 0;<br />
timer.it_interval.tv_usec = 0;<br />
<br />
signal(SIGPROF, stop);<br />
signal(SIGINT, stop);<br />
if (setitimer (ITIMER_PROF, &timer, NULL) != 0) {<br />
printf("error in setitimer\n");<br />
exit(10);<br />
}<br />
<br />
clock_t t1 = clock();<br />
float res = do_something();<br />
clock_t t2 = clock();<br />
<br />
printf("Result is %.12f.\n", res);<br />
printf("Simulation lasted %f CPU-seconds.\n", (((double)t2 - t1) / CLOCKS_PER_SEC));<br />
<br />
return 0;<br />
}<br />
</pre><br />
<br />
Compilation and test:<br />
<pre><br />
$ make test<br />
cc test.c -o test<br />
$ ./test <br />
Result is 3.141596794128.<br />
Simulation lasted 2.002495 CPU-seconds.<br />
</pre></div>
Mascia