Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mpi-mandelbrot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Kempe
mpi-mandelbrot
Commits
037b9943
Commit
037b9943
authored
Sep 25, 2015
by
Andreas Kempe
Browse files
Options
Downloads
Patches
Plain Diff
Multithreaded drawing working.
parent
de9b9a76
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.cpp
+16
-7
16 additions, 7 deletions
main.cpp
with
16 additions
and
7 deletions
main.cpp
+
16
−
7
View file @
037b9943
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include
<Magick++.h>
#include
<Magick++.h>
#include
<complex>
#include
<complex>
#include
<cmath>
#include
<cmath>
#include
<sstream>
#define IMG_WIDTH 800
#define IMG_WIDTH 800
#define IMG_HEIGHT 600
#define IMG_HEIGHT 600
...
@@ -17,6 +18,8 @@
...
@@ -17,6 +18,8 @@
using
namespace
std
;
using
namespace
std
;
using
namespace
Magick
;
using
namespace
Magick
;
int
effective_height
=
IMG_HEIGHT
;
struct
MandelResult
struct
MandelResult
{
{
unsigned
int
end_iterations
;
unsigned
int
end_iterations
;
...
@@ -58,30 +61,36 @@ MandelResult IsMandelbrotPoint(int x, int y, unsigned int iterations)
...
@@ -58,30 +61,36 @@ MandelResult IsMandelbrotPoint(int x, int y, unsigned int iterations)
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
int
id
;
int
id
;
int
num
procs
;
int
procs
;
MPI_Init
(
&
argc
,
&
argv
);
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
procs
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
id
);
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
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
);
MandelResult
result
=
IsMandelbrotPoint
(
x
,
y
,
ITERATIONS
);
if
(
result
.
belongs
)
if
(
result
.
belongs
)
my_image
.
pixelColor
(
x
,
y
,
Color
(
"purple"
));
my_image
.
pixelColor
(
x
,
y
-
effective_height
*
id
,
Color
(
"purple"
));
else
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
();
MPI_Finalize
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment