Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
openMP-HW
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hasan.bahjat
openMP-HW
Commits
76d926f0
You need to sign in or sign up before continuing.
Commit
76d926f0
authored
Nov 04, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update mak file
parent
de5e8713
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
1 deletion
+53
-1
MakeFile
MakeFile
+1
-1
mandlebrot.c
mandlebrot.c
+52
-0
mandlebrot.exe
mandlebrot.exe
+0
-0
No files found.
MakeFile
View file @
76d926f0
# Compiler and flags
CC
=
g
cc
CC
=
g
++
CFLAGS
=
-fopenmp
-O2
PROF_FLAGS
=
-pg
...
...
mandlebrot.c
0 → 100644
View file @
76d926f0
#include "iostream"
#include <complex>
#include <omp.h>
#include <cstdlib>
bool
isInMandelbrotSet
(
double
real
,
double
imag
,
int
max_iterations
)
{
std
::
complex
<
double
>
c
(
real
,
imag
);
std
::
complex
<
double
>
z
=
0
;
for
(
int
i
=
0
;
i
<
max_iterations
;
++
i
)
{
z
=
z
*
z
+
c
;
if
(
std
::
abs
(
z
)
>
2
.
0
)
return
false
;
}
return
true
;
}
double
calculateMandelbrotArea
(
int
num_points
,
int
max_iterations
,
bool
parallel
)
{
int
in_set_count
=
0
;
double
real
,
imag
;
#pragma omp parallel for reduction(+:in_set_count) private(real, imag) if (parallel)
for
(
int
i
=
0
;
i
<
num_points
;
++
i
)
{
real
=
(
rand
()
/
(
double
)
RAND_MAX
)
*
3
.
5
-
2
.
5
;
// Real part in range [-2.5, 1]
imag
=
(
rand
()
/
(
double
)
RAND_MAX
)
*
2
.
0
-
1
.
0
;
// Imaginary part in range [-1, 1]
if
(
isInMandelbrotSet
(
real
,
imag
,
max_iterations
))
{
in_set_count
++
;
}
}
double
area
=
(
3
.
5
*
2
.
0
)
*
(
in_set_count
/
(
double
)
num_points
);
return
area
;
}
int
main
()
{
int
num_points
=
1000000
;
// Number of random points for Monte Carlo
int
max_iterations
=
5000
;
// Maximum iterations for Mandelbrot check
// Sequential run
double
start_time
=
omp_get_wtime
();
double
area_seq
=
calculateMandelbrotArea
(
num_points
,
max_iterations
,
false
);
double
end_time
=
omp_get_wtime
();
std
::
cout
<<
"Sequential Mandelbrot area: "
<<
area_seq
<<
std
::
endl
;
std
::
cout
<<
"Sequential time: "
<<
end_time
-
start_time
<<
" seconds
\n
"
;
// Parallel run
start_time
=
omp_get_wtime
();
double
area_par
=
calculateMandelbrotArea
(
num_points
,
max_iterations
,
true
);
end_time
=
omp_get_wtime
();
std
::
cout
<<
"Parallel Mandelbrot area: "
<<
area_par
<<
std
::
endl
;
std
::
cout
<<
"Parallel time: "
<<
end_time
-
start_time
<<
" seconds
\n
"
;
return
0
;
}
mandlebrot.exe
0 → 100644
View file @
76d926f0
File added
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