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
c5da1b6e
Commit
c5da1b6e
authored
Jul 11, 2019
by
Neil Gershenfeld
Browse files
wip
parent
cf955b1c
Pipeline
#3909
passed with stage
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
MPI/mpipi3.c
View file @
c5da1b6e
...
...
@@ -10,8 +10,7 @@
#include <sys/time.h>
#include <stdint.h>
//#define NPTS 10000000000
#define NPTS 1000000000
#define NPTS 10000000000
#define NLOOP 10
void
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -19,7 +18,6 @@ void main(int argc, char** argv) {
uint64_t
i
,
j
,
istart
,
iend
,
init_time
,
start_time
,
end_time
;
struct
timeval
init
,
start
,
end
;
double
sum
,
pi
,
mflops
,
max
;
gettimeofday
(
&
init
,
NULL
);
MPI_Init
(
&
argc
,
&
argv
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
...
...
OpenMP/mppi2.c
0 → 100644
View file @
c5da1b6e
/*
* mppi.c
* Neil Gershenfeld 6/21/19
* OpenMP pi calculation benchmark, with multiple iterations
* pi = 3.14159265358979323846
*/
#include <stdio.h>
#include <time.h>
#include <omp.h>
#include <stdint.h>
#define NPTS 1000000000
#define NLOOP 10
void
main
()
{
uint64_t
i
;
int
j
;
double
a
,
b
,
c
,
pi
,
dt
,
mflops
,
max
;
struct
timespec
tstart
,
tend
;
a
=
0
.
5
;
b
=
0
.
75
;
c
=
0
.
25
;
max
=
0
;
for
(
j
=
0
;
j
<
NLOOP
;
++
j
)
{
pi
=
0
;
clock_gettime
(
CLOCK_REALTIME
,
&
tstart
);
#pragma omp parallel 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 = %ld, pi = %f, threads = %d
\n
"
,
NPTS
,
pi
,
omp_get_max_threads
());
if
(
mflops
>
max
)
max
=
mflops
;
printf
(
"time = %f, estimated MFlops = %f, max = %f
\n
"
,
dt
,
mflops
,
max
);
}
}
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