Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openmp-lab-exercises
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
pdc-summer-school
openmp-lab-exercises
Commits
6fb9f35b
Commit
6fb9f35b
authored
6 years ago
by
Xin Li
Browse files
Options
Downloads
Patches
Plain Diff
updated pi code
parent
49d2f3bd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
intro_lab/pi.c
+8
-7
8 additions, 7 deletions
intro_lab/pi.c
intro_lab/pi.f90
+6
-6
6 additions, 6 deletions
intro_lab/pi.f90
with
14 additions
and
13 deletions
intro_lab/pi.c
+
8
−
7
View file @
6fb9f35b
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
#include
<math.h>
#include
<math.h>
#include
<omp.h>
#include
<omp.h>
#define NSTEPS 134217728
/*
/*
* This program computes pi as
* This program computes pi as
* \pi = 4 arctan(1)
* \pi = 4 arctan(1)
...
@@ -9,24 +11,23 @@
...
@@ -9,24 +11,23 @@
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
unsigned
long
nsteps
=
100000000
;
long
i
;
double
dx
=
1
.
0
/
nsteps
;
double
dx
=
1
.
0
/
NSTEPS
;
double
pi
=
0
.
0
;
double
pi
=
0
.
0
;
double
start_time
=
omp_get_wtime
();
double
start_time
=
omp_get_wtime
();
unsigned
long
i
;
for
(
i
=
0
;
i
<
NSTEPS
;
i
++
)
for
(
i
=
0
;
i
<
nsteps
;
i
++
)
{
{
double
x
=
(
i
+
0
.
5
)
*
dx
;
double
x
=
(
i
+
0
.
5
)
*
dx
;
pi
+=
1
.
0
/
(
1
.
0
+
x
*
x
);
pi
+=
1
.
0
/
(
1
.
0
+
x
*
x
);
}
}
pi
*=
4
.
0
*
dx
;
pi
*=
4
.
0
*
dx
;
double
run_time
=
omp_get_wtime
()
-
start_time
;
double
run_time
=
omp_get_wtime
()
-
start_time
;
double
ref_pi
=
4
.
0
*
atan
(
1
.
0
);
double
ref_pi
=
4
.
0
*
atan
(
1
.
0
);
printf
(
"pi with %ld steps is %.10f in %.6f seconds (error=%e)
\n
"
,
printf
(
"pi with %ld steps is %.10f in %.6f seconds (error=%e)
\n
"
,
nsteps
,
pi
,
run_time
,
fabs
(
ref_pi
-
pi
));
NSTEPS
,
pi
,
run_time
,
fabs
(
ref_pi
-
pi
));
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
intro_lab/pi.f90
+
6
−
6
View file @
6fb9f35b
...
@@ -8,25 +8,25 @@ use omp_lib
...
@@ -8,25 +8,25 @@ use omp_lib
implicit
none
implicit
none
integer
(
kind
=
8
)
::
nsteps
,
i
integer
(
kind
=
8
),
parameter
::
NSTEPS
=
134217728
integer
(
kind
=
8
)
::
i
real
(
kind
=
8
)
::
dx
,
x
,
pi
,
ref_pi
real
(
kind
=
8
)
::
dx
,
x
,
pi
,
ref_pi
real
(
kind
=
8
)
start_time
,
run_time
real
(
kind
=
8
)
start_time
,
run_time
nsteps
=
100000000
dx
=
1.0D0
/
NSTEPS
dx
=
1.0D0
/
nsteps
pi
=
0.0D0
pi
=
0.0D0
start_time
=
OMP_GET_WTIME
()
start_time
=
OMP_GET_WTIME
()
do
i
=
1
,
nsteps
do
i
=
1
,
NSTEPS
x
=
(
i
-
0.5D0
)
*
dx
x
=
(
i
-
0.5D0
)
*
dx
pi
=
pi
+
1.0D0
/
(
1.0D0
+
x
*
x
)
pi
=
pi
+
1.0D0
/
(
1.0D0
+
x
*
x
)
enddo
enddo
pi
=
pi
*
4.0D0
*
dx
pi
=
pi
*
4.0D0
*
dx
run_time
=
OMP_GET_WTIME
()
-
start_time
run_time
=
OMP_GET_WTIME
()
-
start_time
ref_pi
=
4.0D0
*
atan
(
1.0D0
)
ref_pi
=
4.0D0
*
atan
(
1.0D0
)
print
'("pi with ", i0, " steps is ", f16.10, " in ", f12.6, " seconds (error=", e12.6, ")")'
,
nsteps
,
pi
,
run_time
,
abs
(
ref_pi
-
pi
)
print
'("pi with ", i0, " steps is ", f16.10, " in ", f12.6, " seconds (error=", e12.6, ")")'
,
NSTEPS
,
pi
,
run_time
,
abs
(
ref_pi
-
pi
)
end
program
end
program
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