Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pub
pi
Commits
2be85af8
Commit
2be85af8
authored
Jun 21, 2019
by
Neil Gershenfeld
Browse files
start OpenMP
parent
e7cf1f47
Pipeline
#3764
passed with stage
in 1 second
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
OpenMP/mppi.c
0 → 100644
View file @
2be85af8
/*
* mppi.c
* Neil Gershenfeld 6/21/19
* OpenMPI pi calculation benchmark
* pi = 3.14159265358979323846
*/
#include <stdio.h>
#include <time.h>
#include <omp.h>
#define NPTS 1000000000
double
pi
;
void
main
()
{
int
i
;
printf
(
"%d
\n
"
,
omp_get_max_threads
());
double
a
,
b
,
c
,
dt
,
mflops
;
struct
timespec
tstart
,
tend
;
clock_gettime
(
CLOCK_REALTIME
,
&
tstart
);
a
=
0
.
5
;
b
=
0
.
75
;
c
=
0
.
25
;
pi
=
0
;
pi
=
0
;
#pragma omp parallel
#pragma omp for reduction(+:pi)
for
(
i
=
1
;
i
<=
NPTS
;
++
i
)
pi
+=
a
/
((
i
-
b
)
*
(
i
-
c
));
clock_gettime
(
CLOCK_REALTIME
,
&
tend
);
dt
=
(
tend
.
tv_sec
+
tend
.
tv_nsec
/
1e9
)
-
(
tstart
.
tv_sec
+
tstart
.
tv_nsec
/
1e9
);
mflops
=
NPTS
*
5
.
0
/
(
dt
*
1e6
);
printf
(
"NPTS = %d, pi = %f
\n
"
,
NPTS
,
pi
);
printf
(
"time = %f, estimated MFlops = %f
\n
"
,
dt
,
mflops
);
}
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