aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--algorithms/mandelbrot.c2
-rw-r--r--fractal-gen.c18
-rw-r--r--fractal-gen.h2
3 files changed, 17 insertions, 5 deletions
diff --git a/algorithms/mandelbrot.c b/algorithms/mandelbrot.c
index 3b10b0a..1c3f5a2 100644
--- a/algorithms/mandelbrot.c
+++ b/algorithms/mandelbrot.c
@@ -40,7 +40,7 @@ void *generate_mandelbrot_section(void *section)
for (y = d->core, b = (d->core*(size_units/d->size)+top); y < d->size; b+=((d->cores*size_units)/d->size), y+=d->cores)
{
- for (x = 0, a = left; x < d->size; a+=(size_units/d->size), x++)
+ for (x = d->clust_id, a = (d->clust_id*(size_units/d->size)+left); x < d->size; a+=((d->clust_total*size_units)/d->size), x+=d->clust_total)
{
z = 0;
c = a+I*b;
diff --git a/fractal-gen.c b/fractal-gen.c
index 02ec5bd..b2025a9 100644
--- a/fractal-gen.c
+++ b/fractal-gen.c
@@ -36,6 +36,7 @@ struct section_generator
int main(int argc, char **argv)
{
unsigned int size, iterat, cores, i, x, y;
+ unsigned int clust_id, clust_total;
double power;
char* bname;
data_section* sections;
@@ -61,9 +62,10 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- if (argc != 4 && argc != 5)
+ if (argc != 4 && argc != 5 && argc != 6)
{
- fprintf(stderr, "%s size iterat power [threads]\n", argv[0]);
+ fprintf(stderr, "%s size iterat power [threads]\n"
+ "%s size iterat power [cluster id] [cluster total]\n", argv[0], argv[0]);
return EXIT_FAILURE;
}
@@ -71,8 +73,14 @@ int main(int argc, char **argv)
iterat = atoi(argv[2]);
power = atof(argv[3]);
- // Fetch number of cores available on machine
+ /* Fetch or use defaults for
+ * - num cores available
+ * - our ID in cluster
+ * - total members in cluster
+ */
cores = argc == 5? atoi(argv[4]) : sysconf(_SC_NPROCESSORS_ONLN); // Screw maintainability ;)
+ clust_id = argc == 6? atoi(argv[4]) : 0;
+ clust_total = argc == 6? atoi(argv[5]) : 1;
// Interlacing is column-based, can't have more workers than columns
if (cores > size)
@@ -99,6 +107,8 @@ int main(int argc, char **argv)
// Has to be a better way
sections[i].core = i;
sections[i].cores = cores;
+ sections[i].clust_id = clust_id;
+ sections[i].clust_total = clust_total;
sections[i].size = size;
sections[i].power = power;
sections[i].iterat = iterat;
@@ -131,7 +141,7 @@ int main(int argc, char **argv)
// Output PGM Header
- printf("P5\n%d\n%d\n255\n",size,size);
+ printf("P5\n%d\n%d\n255\n",size/clust_total,size);
// Vomit the data segments back onto the screen, deinterlacing
// TO DO: look at fwrite performance benefits over putchar
diff --git a/fractal-gen.h b/fractal-gen.h
index 3c4e435..656aeec 100644
--- a/fractal-gen.h
+++ b/fractal-gen.h
@@ -42,6 +42,8 @@ typedef struct
{
unsigned int core;
unsigned int cores;
+ unsigned int clust_id;
+ unsigned int clust_total;
unsigned int size;
double power;
unsigned int iterat;