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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
pi
Commits
6053c6a5
Commit
6053c6a5
authored
6 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
c181be81
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2889
passed
6 years ago
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
C/threadpi.c
+64
-0
64 additions, 0 deletions
C/threadpi.c
README.md
+1
-0
1 addition, 0 deletions
README.md
with
65 additions
and
0 deletions
C/threadpi.c
0 → 100644
+
64
−
0
View file @
6053c6a5
/*
* threadpi.c
* Neil Gershenfeld 12/17/18
* pi calculation benchmark
* pi = 3.14159265358979323846
*/
#include
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
#include
<pthread.h>
unsigned
int
npts
=
1e9
;
double
pi
=
0
;
pthread_mutex_t
mutex
;
struct
data
{
unsigned
int
index
;
unsigned
int
points
;
};
void
*
fn
(
void
*
arg
)
{
struct
data
*
vars
;
unsigned
int
i
,
start
,
end
;
double
sum
=
0
;
double
a
=
0
.
5
;
double
b
=
0
.
75
;
double
c
=
0
.
25
;
vars
=
(
struct
data
*
)
arg
;
start
=
1
+
(
vars
->
points
)
*
(
vars
->
index
);
end
=
(
vars
->
points
)
*
(
vars
->
index
+
1
);
for
(
i
=
start
;
i
<=
end
;
++
i
)
sum
+=
a
/
((
i
-
b
)
*
(
i
-
c
));
pthread_mutex_lock
(
&
mutex
);
pi
+=
sum
;
pthread_mutex_unlock
(
&
mutex
);
pthread_exit
(
0
);
}
void
main
(
int
argc
,
char
*
argv
[])
{
int
i
,
nthreads
;
nthreads
=
atoi
(
argv
[
1
]);
pthread_t
threads
[
nthreads
];
struct
data
var
[
nthreads
];
double
dt
,
mflops
;
void
*
status
;
struct
timespec
tstart
,
tend
;
clock_gettime
(
CLOCK_REALTIME
,
&
tstart
);
for
(
i
=
0
;
i
<
nthreads
;
++
i
)
{
var
[
i
].
index
=
i
;
var
[
i
].
points
=
npts
;
pthread_create
(
&
threads
[
i
],
NULL
,
fn
,(
void
*
)
&
var
[
i
]);
}
for
(
i
=
0
;
i
<
nthreads
;
++
i
)
{
pthread_join
(
threads
[
i
],
&
status
);
}
clock_gettime
(
CLOCK_REALTIME
,
&
tend
);
dt
=
(
tend
.
tv_sec
+
tend
.
tv_nsec
/
1e9
)
-
(
tstart
.
tv_sec
+
tstart
.
tv_nsec
/
1e9
);
mflops
=
nthreads
*
(
npts
*
5
.
0
/
(
dt
*
1e6
));
printf
(
"npts = %d, pi = %f
\n
"
,
npts
,
pi
);
printf
(
"time = %f, estimated MFlops = %f
\n
"
,
dt
,
mflops
);
pthread_mutex_destroy
(
&
mutex
);
pthread_exit
(
NULL
);
}
This diff is collapsed.
Click to expand it.
README.md
+
1
−
0
View file @
6053c6a5
...
...
@@ -5,6 +5,7 @@
|---|---|---|---|---|
|71.46|
[
pi.html
](
https://pub.pages.cba.mit.edu/pi/JavaScript/pi.html
)
|JavaScript, 56 workers|Intel 2x E5-2680|Nov 19, 2018|
|46.96|
[
mpipi.c
](
MPI/mpipi.c
)
|C, MPI
<br>
mpicc mpipi.c -o mpipi -O3 -ffast-math
<br>
mpirun -np 6 mpipi|Intel i7-8700T|Nov 17, 2018|
|44.61|
[
threadpi.c
](
C/threadpi.c
)
|C, 6 threads
<br>
gcc threadpi.c -o threadpi -O3 -ffast-math -pthread|Intel i7-8700T|Dec 17, 2018|
|16.16|
[
pi.html
](
https://pub.pages.cba.mit.edu/pi/JavaScript/pi.html
)
|JavaScript, 6 workers|Intel i7-8700T|Nov 17, 2018|
|15.72|
[
clusterpi.js
](
Node/clusterpi.js
)
|Node, 6 workers|Intel i7-8700T|Dec 8, 2018|
|9.371|
[
pi.c
](
C/pi.c
)
|C
<br>
gcc pi.c -o pi -lm -O3 -ffast-math|Intel i7-8700T|Nov 17, 2018|
...
...
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