Skip to content
Snippets Groups Projects
Commit 86b490fc authored by Xin Li's avatar Xin Li
Browse files

added hello.f90 and pi.f90

parent 0106bd2e
Branches
Tags
No related merge requests found
......@@ -48,9 +48,9 @@ The aim of these exercises is to give an introduction to OpenMP programming.
All examples are available in both C and Fortran90.
- OpenMP Intro lab:
- [Instructions](intro_lab/OpenMPlab-assigment.pdf)]
- Simple hello world program [in C](intro_lab/hello.c) and in Fortran (TODO: add fortran)
- Calculate pi [in C](intro_lab/pi.c) and in Fortran (TODO: add fortran)
- [Instructions](intro_lab/OpenMPlab-assigment.pdf)
- Simple hello world program [in C](intro_lab/hello.c) and [in Fortran](intro_lab/hello.f90)
- Calculate pi [in C](intro_lab/pi.c) and [in Fortran](intro_lab/hello.f90)
- OpenMP Advanced Lab:
- [Instructions](advanced_lab/ompproj.pdf)
- In C: [shwater2d.c](advanced_lab/c/shwater2d.c), [vtk_export.c](advanced_lab/c/vtk_export.c) and [Makefile](advanced_lab/c/Makefile)
......
program hello
implicit none
integer :: thread_id = 0
print '("Hello World from thread ", i0)', thread_id
end program
! This program will numerically compute the integral of
!
! 4/(1+x*x)
!
! from 0 to 1. The value of this integral is pi -- which
! 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
implicit none
integer*8 :: num_steps = 100000000
real*8 step
integer i
real*8 x, pi, raw_sum
real*8 start_time, run_time
step = 1.0D0 / num_steps
start_time = OMP_GET_WTIME()
raw_sum = 0.0
do i = 1, num_steps
x = (i-0.5)*step
raw_sum = raw_sum + 4.0/(1.0+x*x)
enddo
pi = step * raw_sum
run_time = OMP_GET_WTIME() - start_time
print '(" pi with ", i0, " steps is ", f12.6, " in ", f12.6, " seconds")', num_steps, pi, run_time
end program
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment