Skip to content
Snippets Groups Projects
Commit 4654968d authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Use clock_gettime() to time steps

Simplest possible version. Still reports tick value for comparison.
parent 3cbee28a
No related branches found
No related tags found
1 merge request!136Master
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -1464,6 +1465,29 @@ void engine_init_particles(struct engine *e) { ...@@ -1464,6 +1465,29 @@ void engine_init_particles(struct engine *e) {
e->step = -1; e->step = -1;
} }
/**
* brief Get difference in milli-seconds between two timespecs.
*
* @param start the start time.
* @param end the end time.
*
* @return the difference in milli-secinds.
*/
static double time_diff(struct timespec start, struct timespec end)
{
struct timespec temp;
if ((end.tv_nsec-start.tv_nsec)<0) {
temp.tv_sec = end.tv_sec-start.tv_sec-1;
temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
} else {
temp.tv_sec = end.tv_sec-start.tv_sec;
temp.tv_nsec = end.tv_nsec-start.tv_nsec;
}
return (double)temp.tv_sec*1000.0 + (double)temp.tv_nsec*1.0E-6;
}
/** /**
* @brief Let the #engine loose to compute the forces. * @brief Let the #engine loose to compute the forces.
* *
...@@ -1482,6 +1506,9 @@ void engine_step(struct engine *e) { ...@@ -1482,6 +1506,9 @@ void engine_step(struct engine *e) {
TIMER_TIC2; TIMER_TIC2;
struct timespec time1, time2;
clock_gettime(CLOCK_REALTIME, &time1);
/* Collect the cell data. */ /* Collect the cell data. */
for (k = 0; k < s->nr_cells; k++) for (k = 0; k < s->nr_cells; k++)
if (s->cells[k].nodeID == e->nodeID) { if (s->cells[k].nodeID == e->nodeID) {
...@@ -1553,8 +1580,8 @@ void engine_step(struct engine *e) { ...@@ -1553,8 +1580,8 @@ void engine_step(struct engine *e) {
if (e->nodeID == 0) { if (e->nodeID == 0) {
/* Print some information to the screen */ /* Print some information to the screen */
printf("%d %e %e %d %.3f\n", e->step, e->time, e->timeStep, updates, printf("%d %e %e %d %.3f %.3f\n", e->step, e->time, e->timeStep, updates,
e->wallclock_time); e->wallclock_time, e->wallclock_time_ticks);
fflush(stdout); fflush(stdout);
/* Write some energy statistics */ /* Write some energy statistics */
...@@ -1620,7 +1647,11 @@ void engine_step(struct engine *e) { ...@@ -1620,7 +1647,11 @@ void engine_step(struct engine *e) {
TIMER_TOC2(timer_step); TIMER_TOC2(timer_step);
e->wallclock_time = ((double)timers[timer_count - 1]) / CPU_TPS * 1000; clock_gettime(CLOCK_REALTIME, &time2);
e->wallclock_time_ticks = ((double)timers[timer_count - 1]) / CPU_TPS * 1000;
e->wallclock_time = (float) time_diff(time1, time2);
// printParticle(e->s->parts, e->s->xparts,1000, e->s->nr_parts); // printParticle(e->s->parts, e->s->xparts,1000, e->s->nr_parts);
// printParticle(e->s->parts, e->s->xparts,515050, e->s->nr_parts); // printParticle(e->s->parts, e->s->xparts,515050, e->s->nr_parts);
} }
......
...@@ -147,6 +147,7 @@ struct engine { ...@@ -147,6 +147,7 @@ struct engine {
/* Wallclock time of the last time-step */ /* Wallclock time of the last time-step */
float wallclock_time; float wallclock_time;
float wallclock_time_ticks;
/* Force the engine to rebuild? */ /* Force the engine to rebuild? */
int forcerebuild; int forcerebuild;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment