aboutsummaryrefslogtreecommitdiff
path: root/fractal-gen.c
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2015-06-09 18:11:34 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2015-06-09 18:51:35 +1200
commitd29cb84f52f93e060c2ec0f020f56fea0636428d (patch)
tree6eb70e2bf52cfe4b7ac4d5d07ce99f77cc397e90 /fractal-gen.c
parentabed235f6918e932020f93f5be4f358637af8144 (diff)
downloadfractal-gen-d29cb84f52f93e060c2ec0f020f56fea0636428d.tar.xz
Moved mallocs inside their if()s, various whitespace removals
Diffstat (limited to 'fractal-gen.c')
-rw-r--r--fractal-gen.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/fractal-gen.c b/fractal-gen.c
index 79f2de7..6ce9867 100644
--- a/fractal-gen.c
+++ b/fractal-gen.c
@@ -44,11 +44,8 @@ int main(int argc, char **argv)
assert(iterat > 0);
assert(cores > 0);
- // Allocated memory for sections, bailing upon failure
- sections = malloc(sizeof(data_section)*cores);
-
-
- if (sections == NULL)
+ // Allocate memory for sections
+ if ((sections = malloc(sizeof(data_section)*cores)) == NULL)
{
perror("malloc");
return EXIT_FAILURE;
@@ -65,18 +62,13 @@ int main(int argc, char **argv)
sections[i].power = power;
sections[i].iterat = iterat;
-int s;
-
// A bit complex, icky, will document later
if (i < (size%cores))
- s = (size*((int)(size/cores)+1));
+ x = (size*((int)(size/cores)+1));
else
- s = (size*(int)(size/cores));
-
- sections[i].data = malloc(s);
-
+ x = (size*(int)(size/cores));
- if (sections[i].data == NULL)
+ if ((sections[i].data = malloc(x)) == NULL)
{
fprintf(stderr, "\n");
perror("malloc");
@@ -88,7 +80,7 @@ int s;
free(sections);
return EXIT_FAILURE;
}
- fprintf(stderr, " -> Thread #%d (%d)\r", i+1, s);
+ fprintf(stderr, " -> Thread #%d (%d bytes data area)\r", i+1, x);
pthread_create(&sections[i].thread, NULL, generator, &(sections[i]));
}