-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathserial.F90
67 lines (56 loc) · 2.43 KB
/
serial.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
!> @file serial.F90
!> @brief Contains the serial version of Laplace.
!> @note This code was originaly written by John Urbanic for PSC 2014, later modified by Ludovic Capelli.
!> @author John Urbanic
!> @author Ludovic Capelli
!> @brief Runs the experiment.
!> @pre The macro 'ROWS' contains the number of rows (excluding boundaries). It is a define passed as a compilation flag, see makefile.
!> @pre The macro 'COLUMNS' contains the number of columns (excluding boundaries). It is a define passed as a compilation flag, see makefile.
PROGRAM serial
USE util
IMPLICIT NONE
!> Indexes used in for loops
INTEGER :: i, j
!> Current iteration.
INTEGER :: iteration = 0
!> Largest change in temperature.
DOUBLE PRECISION :: dt = 100.0
!> Time taken during the entire simulation, in seconds
REAL :: timer_simulation
!> Temperature grid.
REAL*8, DIMENSION(0:ROWS+1,0:COLUMNS+1) :: temperature
!> Temperature grid from last iteration.
REAL*8, DIMENSION(0:ROWS+1,0:COLUMNS+1) :: temperature_last
! Initialise temperatures and temperature_last including boundary conditions
CALL initialise_temperatures(temperature, temperature_last)
!///////////////////////////////////
!// -- Code from here is timed -- //
!///////////////////////////////////
CALL start_timer(timer_simulation)
! Do until error is minimal or until maximum steps
DO WHILE ( dt > MAX_TEMP_ERROR .and. iteration <= MAX_NUMBER_OF_ITERATIONS)
iteration = iteration+1
DO j=1,COLUMNS
DO i=1,ROWS
temperature(i,j) = 0.25 * (temperature_last(i+1, j ) + &
temperature_last(i-1, j ) + &
temperature_last(i , j+1) + &
temperature_last(i , j-1))
ENDDO
ENDDO
dt=0.0
! Copy grid to old grid for next iteration and find max change
DO j=1,COLUMNS
DO i=1,ROWS
dt = max(abs(temperature(i,j) - temperature_last(i,j)), dt)
temperature_last(i,j) = temperature(i,j)
ENDDO
ENDDO
! Periodically print test values
IF (mod(iteration, PRINT_FREQUENCY) .eq. 0) THEN
CALL track_progress(iteration, temperature)
ENDIF
ENDDO
CALL stop_timer(timer_simulation)
CALL print_summary(iteration, dt, timer_simulation)
END PROGRAM serial