Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Andreas Kempe
mpi-mandelbrot
Commits
037b9943
Commit
037b9943
authored
Sep 25, 2015
by
Andreas Kempe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Multithreaded drawing working.
parent
de9b9a76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
7 deletions
+16
-7
main.cpp
main.cpp
+16
-7
No files found.
main.cpp
View file @
037b9943
...
...
@@ -3,6 +3,7 @@
#include <Magick++.h>
#include <complex>
#include <cmath>
#include <sstream>
#define IMG_WIDTH 800
#define IMG_HEIGHT 600
...
...
@@ -17,6 +18,8 @@
using
namespace
std
;
using
namespace
Magick
;
int
effective_height
=
IMG_HEIGHT
;
struct
MandelResult
{
unsigned
int
end_iterations
;
...
...
@@ -58,30 +61,36 @@ MandelResult IsMandelbrotPoint(int x, int y, unsigned int iterations)
int
main
(
int
argc
,
char
**
argv
)
{
int
id
;
int
num
procs
;
int
procs
;
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
procs
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
id
);
cout
<<
id
<<
endl
;
Image
my_image
(
IMG_SIZE
,
"white"
);
// Calculate this threads working area.
effective_height
/=
procs
;
Image
my_image
(
Geometry
(
IMG_WIDTH
,
effective_height
),
"white"
);
for
(
int
x
=
0
;
x
<
IMG_WIDTH
;
++
x
)
{
for
(
int
y
=
0
;
y
<
IMG_HEIGHT
;
++
y
)
for
(
int
y
=
effective_height
*
id
;
y
<
effective_height
*
(
id
+
1
)
;
++
y
)
{
MandelResult
result
=
IsMandelbrotPoint
(
x
,
y
,
ITERATIONS
);
if
(
result
.
belongs
)
my_image
.
pixelColor
(
x
,
y
,
Color
(
"purple"
));
my_image
.
pixelColor
(
x
,
y
-
effective_height
*
id
,
Color
(
"purple"
));
else
my_image
.
pixelColor
(
x
,
y
,
Color
(
0
,
0
,
MaxRGB
/
ITERATIONS
*
result
.
end_iterations
));
my_image
.
pixelColor
(
x
,
y
-
effective_height
*
id
,
Color
(
0
,
0
,
MaxRGB
/
ITERATIONS
*
result
.
end_iterations
));
}
}
my_image
.
write
(
"mandelbrot.png"
);
stringstream
ss
;
ss
<<
id
<<
".png"
;
my_image
.
write
(
ss
.
str
());
MPI_Finalize
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment