diff options
author | David Phillips <dbphillipsnz@gmail.com> | 2015-07-24 13:01:44 +1200 |
---|---|---|
committer | David Phillips <dbphillipsnz@gmail.com> | 2015-07-24 13:01:44 +1200 |
commit | 1ff1618017994332da265be161e8cc548e8b8495 (patch) | |
tree | b3032f360983a4c7153dc94f864091f8679c9b94 /fractal-gen.c | |
parent | 61d614b804adfc461d98b6c889ca2121407514ad (diff) | |
download | fractal-gen-1ff1618017994332da265be161e8cc548e8b8495.tar.xz |
Started work on cluster-style parallel processing
Diffstat (limited to 'fractal-gen.c')
-rw-r--r-- | fractal-gen.c | 18 |
1 files changed, 14 insertions, 4 deletions
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 |