Paste
Of Code


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
program toy_collision
      use omp_lib
      implicit none

      integer :: nx, ny, nsteps, ii, i, j, t
      integer :: index_val
      real(8), allocatable :: ff_temp(:)
      real(8) :: start_time, end_time, total_time

      ! Parameters
      nx = 100
      ny = 100
      nsteps = 10000

      allocate(ff_temp((nx)*(ny)*9))
      ff_temp = 0

      start_time = omp_get_wtime()

      ! Time stepping loop
      do t = 1, nsteps

      ! Triple nested loop over x, y and characteristic directions
!$omp parallel do collapse(2) default(NONE)
!$omp&private(j, i, ii, index_val)
!$omp&shared(ny, nx, ff_temp)
      do i = 0, nx-1
        do j = 0, ny-1
            do ii = 0, 8
                ! Flatten 3D coordinates to 1D index value -- adjusted formula for LBM coordinates
                index_val = ii + 9 * (i + nx * j)

                ! Make some updates to distribution function
                ff_temp(index_val) = ff_temp(index_val) + (i + j)

            enddo
        enddo
      enddo
      enddo

      end_time = omp_get_wtime()
      total_time = end_time - start_time

      print*, 'Time step: ', t
      print*, 'ff_temp at index 1000: ', ff_temp(1000)
      print*, 'ff_temp at index 5000: ', ff_temp(5000)
      print*, 'ff_temp at index 8000 ', ff_temp(8000)
      print*, 'Size of ff_temp: ', size(ff_temp)
      print*, 'Total time for solve: ', total_time

      end program toy_collision
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

Toggle: theme, font