aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2015-06-06 22:23:07 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2015-06-06 22:23:07 +1200
commite4eb7d51b4d8d7cff6374cc42d2e5eef41792e5c (patch)
tree2c08ad78d729be7afb22e373f2bb938c8e8754b0
parent7bf6246b44be7539a65cee3ee3a5b9232b3fc608 (diff)
downloadfractal-gen-e4eb7d51b4d8d7cff6374cc42d2e5eef41792e5c.tar.xz
Tweaks, comments and to-dos
-rw-r--r--README.md2
-rw-r--r--mbrot-gen.c21
2 files changed, 13 insertions, 10 deletions
diff --git a/README.md b/README.md
index 53dc179..0832dbd 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ Notes
-----
1. This has your CPU over a barrel.
- It spawns twice as many threads as you have cores, so have fun with that.
+ It spawns as many threads as you have cores, so have fun with that.
I'm looking at adding an option to override the number of threads.
diff --git a/mbrot-gen.c b/mbrot-gen.c
index 08e438d..53be6d6 100644
--- a/mbrot-gen.c
+++ b/mbrot-gen.c
@@ -36,17 +36,17 @@ int main(int argc, char **argv)
iterat = atoi(argv[2]);
power = atof(argv[3]);
+
// Fetch number of cores available on machine, so we can use lots of them to speed things up
cores = sysconf (_SC_NPROCESSORS_ONLN);
// cores = 8;
-
- fprintf(stderr, "Found %d cores. I'll spawn as many threads and let the scheduler sort it out.\n", cores);
-
-
+ // TO DO: assertions for size, iterat, power and cores
+ fprintf(stderr, "Found %d cores. I'll spawn as many threads and let the scheduler sort it out.\n", cores);
+ // TO DO: move to top of function
int x,y,s;
data_section* sections = malloc(sizeof(data_section)*cores);
@@ -55,6 +55,7 @@ int main(int argc, char **argv)
// Spawn all the threads! Something something interlacing
for (i = 0; i < cores; i++)
{
+ // Has to be a better way
sections[i].core = i;
sections[i].cores = cores;
sections[i].size = size;
@@ -65,17 +66,17 @@ int main(int argc, char **argv)
pthread_create(&sections[i].thread, NULL, &generate_section, &(sections[i]));
}
-
+ // Wait for each thread to complete
for (i = 0; i < cores; i++)
pthread_join(sections[i].thread, NULL);
-
-
+ // Vomit the data segments back onto the screen, deinterlacing
+ // TO DO: look at fwrite performance benefits over putchar
for (y = 0; y < size; y++)
for (x = 0; x < size; x++)
- printf("%c", sections[y%cores].data[(y/cores)*size + x]);
-
+ putchar(sections[y%cores].data[(y/cores)*size + x]);
+ // Free the memory we allocated for point data
for (s = 0; s < cores; s++)
free(sections[s].data);
@@ -94,6 +95,8 @@ void *generate_section(void *section)
int idx = 0;
+ // TO DO: assert malloc succeeded
+
for (y = d->core, b = (d->core*(3.5f/d->size)-1.75f); y < d->size; b+=((d->cores*3.5f)/d->size), y+=d->cores)
{
for (x = 0, a = -2.5f; x < d->size; a+=(3.5f/d->size), x++)