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
49d2f3bd
Commit
49d2f3bd
authored
6 years ago
by
Xin Li
Browse files
Options
Downloads
Patches
Plain Diff
updated intro_lab
parent
6643b934
Branches
Branches containing commit
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
+2
-2
2 additions, 2 deletions
intro_lab/pi.c
intro_lab/pi.f90
+17
-26
17 additions, 26 deletions
intro_lab/pi.f90
with
19 additions
and
28 deletions
intro_lab/pi.c
+
2
−
2
View file @
49d2f3bd
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
unsigned
long
nsteps
=
1
<<
27
;
/* around 10^8 steps */
unsigned
long
nsteps
=
1
00000000
;
double
dx
=
1
.
0
/
nsteps
;
double
dx
=
1
.
0
/
nsteps
;
double
pi
=
0
.
0
;
double
pi
=
0
.
0
;
...
@@ -25,7 +25,7 @@ int main(int argc, char** argv)
...
@@ -25,7 +25,7 @@ int main(int argc, char** argv)
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
(
"
\n
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
+
17
−
26
View file @
49d2f3bd
! This program will numerically compute the integral of
! This program computes pi as
!
! \pi = 4 arctan(1)
! 4/(1+x*x)
! = 4 \int _0 ^1 \frac{1} {1 + x^2} dx
!
! from 0 to 1. The value of this integral is pi -- which
program
compute_pi
! is great since it gives us an easy way to check the answer.
!
! The is the original sequential program. It uses the timer
! from the OpenMP runtime library
!
! History: Written by Tim Mattson, 11/99.
program
calc_pi
use
omp_lib
use
omp_lib
implicit
none
implicit
none
integer
(
kind
=
8
)
::
num_steps
=
100000000
integer
(
kind
=
8
)
::
nsteps
,
i
real
(
kind
=
8
)
step
real
(
kind
=
8
)
::
dx
,
x
,
pi
,
ref_pi
integer
i
real
(
kind
=
8
)
x
,
pi
,
raw_sum
real
(
kind
=
8
)
start_time
,
run_time
real
(
kind
=
8
)
start_time
,
run_time
step
=
1.0D0
/
num_steps
nsteps
=
100000000
dx
=
1.0D0
/
nsteps
pi
=
0.0D0
start_time
=
OMP_GET_WTIME
()
start_time
=
OMP_GET_WTIME
()
raw_sum
=
0.0D0
do
i
=
1
,
nsteps
x
=
(
i
-
0.5D0
)
*
dx
do
i
=
1
,
num_steps
pi
=
pi
+
1.0D0
/
(
1.0D0
+
x
*
x
)
x
=
(
i
-0.5D0
)
*
step
raw_sum
=
raw_sum
+
4.0D0
/(
1.0D0
+
x
*
x
)
enddo
enddo
pi
=
step
*
raw_sum
pi
=
pi
*
4.0D0
*
dx
run_time
=
OMP_GET_WTIME
()
-
start_time
run_time
=
OMP_GET_WTIME
()
-
start_time
print
'(" pi with ", i0, " steps is ", f12.6, " in ", f12.6, " seconds")'
,
num_steps
,
pi
,
run_time
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
)
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