aboutsummaryrefslogtreecommitdiff
path: root/fractal-gen.c
diff options
context:
space:
mode:
Diffstat (limited to 'fractal-gen.c')
-rw-r--r--fractal-gen.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/fractal-gen.c b/fractal-gen.c
index 7f4e326..c5930c9 100644
--- a/fractal-gen.c
+++ b/fractal-gen.c
@@ -56,6 +56,24 @@ defaultsd(double *who, double def)
*who = def;
}
+double
+timespec_diff(struct timespec start, struct timespec end) {
+ long weight = 1000000000;
+ time_t s = (end.tv_sec - start.tv_sec);
+ long ns = (end.tv_nsec - start.tv_nsec) % weight;
+
+ return s + ((double)ns)/weight;
+}
+
+void
+*generate(void *section) {
+ data_section *s = (data_section*)section;
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(s->time_start));
+ (s->generator)(s);
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(s->time_end));
+ return NULL;
+}
+
int
main(int argc, char **argv)
{
@@ -107,6 +125,10 @@ main(int argc, char **argv)
ram_nice /= 1024;
}
+ /* FIXME clean up */
+ struct timespec time_start, time_end;
+ clock_gettime(CLOCK_REALTIME, &time_start);
+
fprintf(stderr,
"Forecast resource use:\n"
" Threads: %d\n"
@@ -142,10 +164,11 @@ main(int argc, char **argv)
sections[i].width = width;
sections[i].parent_frame.y = f.y;
sections[i].parent_frame.x = f.x;
+ sections[i].generator = generator;
sections[i].parent_frame.scale = f.scale;
sections[i].datasize = toalloc;
fprintf(stderr, " -> Thread %lu\r", i);
- pthread_create(&sections[i].thread, NULL, generator, &(sections[i]));
+ pthread_create(&sections[i].thread, NULL, generate, &(sections[i]));
}
s = &(sections[cores-1]);
@@ -170,6 +193,24 @@ main(int argc, char **argv)
kill(child, SIGKILL);
+ clock_gettime(CLOCK_REALTIME, &time_end);
+
+ fprintf(stderr, "\nDone\n");
+
+ double time_wall = timespec_diff(time_start, time_end);
+ double time_ch = 0;
+
+ for (i = 0; i < cores; i++) {
+ data_section *s = &(sections[i]);
+ time_ch += (timespec_diff(s->time_start, s->time_end)) / cores;
+ }
+
+ fprintf(stderr,
+ "Wall-clock time: %.2f seconds\n"
+ "Average worker time: %.2f seconds\n"
+ "Multi-core efficiency: %.2f%%\n"
+ , time_wall, time_ch, 100*(time_ch)/time_wall);
+
/* Output PGM Header */
printf("P5\n%d\n%d\n255\n",size,size/clust_total);
@@ -182,7 +223,6 @@ main(int argc, char **argv)
putchar(s->data[y*(s->width) + x/cores]);
}
}
- fprintf(stderr, "\nDone\n");
/* Free the memory we allocated for point data */
for (i = 0; i < cores; i++)