Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
pub
pi
Commits
e7cf1f47
Commit
e7cf1f47
authored
6 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
296c169d
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#3739
passed
6 years ago
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
MPI/mpipi.c
+8
-11
8 additions, 11 deletions
MPI/mpipi.c
with
8 additions
and
11 deletions
MPI/mpipi.c
+
8
−
11
View file @
e7cf1f47
...
...
@@ -8,11 +8,10 @@
#include
<mpi.h>
#include
<sys/time.h>
#define NPTS 100000000
#define NLOOP 10
#define NPTS 1000000000
void
main
(
int
argc
,
char
**
argv
)
{
int
rank
,
nproc
,
i
,
istart
,
iend
,
loop
,
N
;
int
rank
,
nproc
,
i
,
istart
,
iend
;
unsigned
long
int
start_time
,
end_time
;
struct
timeval
start
,
end
;
double
sum
,
pi
,
mflops
;
...
...
@@ -25,22 +24,20 @@ void main(int argc, char** argv) {
istart
=
1
+
NPTS
*
((
rank
+
0
.
0
)
/
nproc
);
iend
=
NPTS
*
((
rank
+
1
.
0
)
/
nproc
);
sum
=
0
.
0
;
for
(
loop
=
0
;
loop
<
NLOOP
;
++
loop
)
for
(
i
=
istart
;
i
<=
iend
;
++
i
)
sum
+=
0
.
5
/
((
i
-
0
.
75
)
*
(
i
-
0
.
25
));
MPI_Reduce
(
&
sum
,
&
pi
,
1
,
MPI_DOUBLE
,
MPI_SUM
,
0
,
MPI_COMM_WORLD
);
gettimeofday
(
&
end
,
NULL
);
start_time
=
start
.
tv_sec
*
1e6
+
start
.
tv_usec
;
end_time
=
end
.
tv_sec
*
1e6
+
end
.
tv_usec
;
mflops
=
NLOOP
*
(
NPTS
*
(
5
.
0
/
(
end_time
-
start_time
))
)
;
printf
(
"processes = %d, NPTS = %d,
NLOOP = %d,
pi = %f
\n
"
,
nproc
,
NPTS
,
NLOOP
,
pi
/
NLOOP
);
mflops
=
NPTS
*
(
5
.
0
/
(
end_time
-
start_time
));
printf
(
"processes = %d, NPTS = %d, pi = %f
\n
"
,
nproc
,
NPTS
,
pi
);
printf
(
"time = %f, estimated MFlops = %f
\n
"
,(
end_time
-
start_time
)
/
1.0e6
,
mflops
);
}
else
{
istart
=
1
+
NPTS
*
((
rank
+
0
.
0
)
/
nproc
);
iend
=
NPTS
*
((
rank
+
1
.
0
)
/
nproc
);
sum
=
0
.
0
;
for
(
loop
=
0
;
loop
<
NLOOP
;
++
loop
)
for
(
i
=
istart
;
i
<=
iend
;
++
i
)
sum
+=
0
.
5
/
((
i
-
0
.
75
)
*
(
i
-
0
.
25
));
MPI_Reduce
(
&
sum
,
&
pi
,
1
,
MPI_DOUBLE
,
MPI_SUM
,
0
,
MPI_COMM_WORLD
);
...
...
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