aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2016-10-26 16:02:06 +1300
committerDavid Phillips <david@sighup.nz>2016-10-26 16:04:18 +1300
commit253ecc8d4f6aaaa4a7f86f713d1c485dac8eda78 (patch)
treec69e9ea4f4e504ef500315e77a31752cd36e3759
parent22ccf34f4960b355d55e2aad14008a4c50e65197 (diff)
downloadfractal-gen-253ecc8d4f6aaaa4a7f86f713d1c485dac8eda78.tar.xz
Rename cores => threads
-rw-r--r--algorithms/burning-ship.c4
-rw-r--r--algorithms/mandelbrot.c4
-rw-r--r--fractal-gen.c48
-rw-r--r--fractal-gen.h2
4 files changed, 29 insertions, 29 deletions
diff --git a/algorithms/burning-ship.c b/algorithms/burning-ship.c
index 6f8c9d9..43f645f 100644
--- a/algorithms/burning-ship.c
+++ b/algorithms/burning-ship.c
@@ -49,7 +49,7 @@ void
for (y = clust_id; y < size; y += clust_total) {
a = d->core*(f->scale/size)+left;
- for (x = d->core; x < size; x += cores) {
+ for (x = d->core; x < size; x += threads) {
z = 0;
c = a+I*b;
for (i = 0; i < iterat; i++) {
@@ -59,7 +59,7 @@ void
z = cpow( fabs(creal(z)) + I*fabs(cimag(z)) , power) + c;
}
d->data[d->idx++] = (255*i)/iterat;
- a += cores*(f->scale/size);
+ a += threads*(f->scale/size);
}
b += clust_total*(f->scale/size);
}
diff --git a/algorithms/mandelbrot.c b/algorithms/mandelbrot.c
index 33d7cde..e55b3e0 100644
--- a/algorithms/mandelbrot.c
+++ b/algorithms/mandelbrot.c
@@ -49,7 +49,7 @@ void
for (y = clust_id; y < size; y += clust_total) {
a = d->core*(f->scale/size)+left;
- for (x = d->core; x < size; x += cores) {
+ for (x = d->core; x < size; x += threads) {
z = 0;
c = a + I*b;
for (i = 0; i < iterat; i++) {
@@ -59,7 +59,7 @@ void
z = cpow(z , power) + c;
}
d->data[d->idx++] = (255*i)/iterat;
- a += cores*(f->scale/size);
+ a += threads*(f->scale/size);
}
b += clust_total*(f->scale/size);
}
diff --git a/fractal-gen.c b/fractal-gen.c
index c5930c9..59329aa 100644
--- a/fractal-gen.c
+++ b/fractal-gen.c
@@ -109,7 +109,7 @@ main(int argc, char **argv)
}
/* Allocate memory for sections */
- if ((sections = mmap(NULL, sizeof(data_section)*cores, PROT_READ|PROT_WRITE,
+ if ((sections = mmap(NULL, sizeof(data_section)*threads, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_ANONYMOUS, -1, 0)) == (data_section*)MAP_FAILED) {
perror("mmap");
return 1;
@@ -133,16 +133,16 @@ main(int argc, char **argv)
"Forecast resource use:\n"
" Threads: %d\n"
" RAM : ~%.4f %s\n",
- cores,
+ threads,
ram_nice,
ram_unit);
/* Spawn all the threads! Something something interlacing */
- for (i = 0; i < cores; i++) {
+ for (i = 0; i < threads; i++) {
/* A bit complex, icky, will document later */
- if (i < (size%cores))
- width = (size/cores)+1;
+ if (i < (size%threads))
+ width = (size/threads)+1;
else
- width = (size/cores);
+ width = (size/threads);
toalloc = width*size;
toalloc = ceilf((double)toalloc/clust_total);
@@ -156,7 +156,7 @@ main(int argc, char **argv)
while(i-- + 1)
free(sections[i].data);
- munmap(sections, sizeof(data_section)*cores);
+ munmap(sections, sizeof(data_section)*threads);
return 1;
}
/* FIXME repetition */
@@ -171,13 +171,13 @@ main(int argc, char **argv)
pthread_create(&sections[i].thread, NULL, generate, &(sections[i]));
}
- s = &(sections[cores-1]);
+ s = &(sections[threads-1]);
switch (child = fork()) {
case 0:
while(1) {
fprintf(stderr, "Thread %d: %.4f%%\r",
- cores-1,
+ threads-1,
100.f*(double)s->idx/s->datasize);
sleep(1);
}
@@ -188,7 +188,7 @@ main(int argc, char **argv)
break;
}
/* Wait for each thread to complete */
- for (i = 0; i < cores; i++)
+ for (i = 0; i < threads; i++)
pthread_join(sections[i].thread, NULL);
kill(child, SIGKILL);
@@ -200,9 +200,9 @@ main(int argc, char **argv)
double time_wall = timespec_diff(time_start, time_end);
double time_ch = 0;
- for (i = 0; i < cores; i++) {
+ for (i = 0; i < threads; i++) {
data_section *s = &(sections[i]);
- time_ch += (timespec_diff(s->time_start, s->time_end)) / cores;
+ time_ch += (timespec_diff(s->time_start, s->time_end)) / threads;
}
fprintf(stderr,
@@ -219,16 +219,16 @@ main(int argc, char **argv)
for (y = 0; y < size/clust_total; y++) {
for (x = 0; x < size; x++)
{
- s = &(sections[x%cores]);
- putchar(s->data[y*(s->width) + x/cores]);
+ s = &(sections[x%threads]);
+ putchar(s->data[y*(s->width) + x/threads]);
}
}
/* Free the memory we allocated for point data */
- for (i = 0; i < cores; i++)
+ for (i = 0; i < threads; i++)
free(sections[i].data);
- munmap(sections, sizeof(data_section)*cores);
+ munmap(sections, sizeof(data_section)*threads);
return 0;
}
@@ -242,7 +242,7 @@ parse_args(int argc, char **argv)
size = 0;
iterat = 0;
power = 2;
- cores = sysconf(_SC_NPROCESSORS_ONLN);
+ threads = sysconf(_SC_NPROCESSORS_ONLN);
thread_mult = 1;
clust_id = 0;
clust_total = 1;
@@ -262,7 +262,7 @@ parse_args(int argc, char **argv)
case 'i': iterat = atoi(optarg); break;
case 'e': power = atof(optarg); break;
- case 'c': cores = atoi(optarg); break;
+ case 'c': threads = atoi(optarg); break;
case 't': thread_mult = atof(optarg); break;
case 'N': clust_id = atoi(optarg); break;
@@ -281,7 +281,7 @@ parse_args(int argc, char **argv)
}
/* Extend number of threads to multiplier value */
- cores *= thread_mult;
+ threads *= thread_mult;
if (size <= 0) {
fprintf(stderr, "ERROR: size must be positive\n");
@@ -299,9 +299,9 @@ parse_args(int argc, char **argv)
}
/* Interlacing is row-based, can't have more workers than columns */
- if (cores > size) {
- cores = size;
- fprintf(stderr, "WARN: Capping number of threads to image size (%d)\n", cores);
+ if (threads > size) {
+ threads = size;
+ fprintf(stderr, "WARN: Capping number of threads to image size (%d)\n", threads);
}
if (size % clust_total != 0) {
@@ -309,7 +309,7 @@ parse_args(int argc, char **argv)
return 1;
}
- if (cores <= 0) {
+ if (threads <= 0) {
fprintf(stderr, "ERROR: core counts should be positive\n");
return 1;
}
@@ -331,7 +331,7 @@ void show_help()
{
fprintf(stderr,
"%s -s size -i iterat [-e exponent]\n"
- " [-c cores] [-t thread_multiplier]\n"
+ " [-c threads] [-t thread_multiplier]\n"
" [-N cluster-id -T cluster-total]\n",
argv0);
}
diff --git a/fractal-gen.h b/fractal-gen.h
index 8dcd167..fb70e58 100644
--- a/fractal-gen.h
+++ b/fractal-gen.h
@@ -49,7 +49,7 @@ typedef struct data_section_s {
pthread_t thread;
} data_section;
-unsigned int cores;
+unsigned int threads;
unsigned int clust_id;
unsigned int clust_total;
unsigned int size;