aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2016-09-19 12:55:41 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2016-09-19 12:55:41 +1200
commitf96e46f931ec81436f31ef3bcffbad34f11b9d58 (patch)
tree9da67f2f604f1bbe712c1abd753e5889f1699cbc
parentfcc7c9dce8410bb14d9fe546d66010a01eee365e (diff)
downloadfractal-gen-f96e46f931ec81436f31ef3bcffbad34f11b9d58.tar.xz
Add very rough multi-core efficiency output
-rw-r--r--fractal-gen.c30
-rw-r--r--fractal-gen.h8
2 files changed, 35 insertions, 3 deletions
diff --git a/fractal-gen.c b/fractal-gen.c
index 0a09c41..fbe7958 100644
--- a/fractal-gen.c
+++ b/fractal-gen.c
@@ -56,6 +56,15 @@ defaultsd(double *who, double def)
*who = def;
}
+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 +116,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 +155,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 +184,20 @@ main(int argc, char **argv)
kill(child, SIGKILL);
+ clock_gettime(CLOCK_REALTIME, &time_end);
+
+ long time_wall = time_end.tv_sec - time_start.tv_sec;
+ long time_ch = 0;
+ for (i = 0; i < cores; i++) {
+ time_ch += sections[i].time_end.tv_sec - sections[i].time_start.tv_sec;
+ }
+
+ fprintf(stderr,
+ "Wall-clock time: %ld\n"
+ "Worker time: %ld\n"
+ "Multi-core efficiency: %.2f%%\n"
+ , time_wall, time_ch, 100*((double)(time_wall*cores))/time_ch);
+
/* Output PGM Header */
printf("P5\n%d\n%d\n255\n",size,size/clust_total);
diff --git a/fractal-gen.h b/fractal-gen.h
index 210d50f..8dcd167 100644
--- a/fractal-gen.h
+++ b/fractal-gen.h
@@ -28,16 +28,21 @@
#include <stdbool.h>
#include <pthread.h>
+typedef void* (*generator_func)(void *);
+
struct frame {
double x;
double y;
double scale;
};
-typedef struct {
+typedef struct data_section_s {
volatile unsigned long idx;
+ generator_func generator;
struct frame parent_frame;
unsigned long core;
+ struct timespec time_start;
+ struct timespec time_end;
unsigned long width;
unsigned long datasize;
char* data;
@@ -53,7 +58,6 @@ double power;
double thread_mult; /* number to multiply available cores by to get thread count */
char *argv0;
-typedef void* (*generator_func)(void *);
void defaultsd(double*, double);
int parse_args(int argc, char **argv);