## 4 Methods
### Domain Decomposition and Tile Division  
The entire study area in the WRF is called a domain. The subdomain obtained by dividing the domain with processes is called a patch, a process known as domain decomposition. The subdomains are assigned to each process. The patch can also be subdivided into tiles (see Figure 3), a process known as tile division.  
WRF uses \(\text{nproc\_x}\) to denote the number of processes in the east-west direction of the domain and \(\text{nproc\_y}\) to denote the number of processes in the north-south direction of the domain. The domain decomposition should follow the following condition:  
\[n=nproc\_x\times nproc\_y \tag{4}\]  
Figure 3: Three level domain decomposition of WRF.  
Algorithm 1 can summarize the calculation process of WRF. First, WRF will first calculate the value of each tile; then calculate the data of each patch in units of tiles; finally, through MPI, exchange data for the part of each patch that needs to communicate, and finally obtain the data of the entire domain.  
```
1 function compute (tile)
2 for\(j=1\),tile\(\_\)max\(\_\)y
3 fork\(k=1\),tile\(\_\)max\(\_\)k
4 for\(i=1\),tile\(\_\)max\(\_\)i
5 tile[\(i\)][\(j\)][\(k\)] = do some calculations
6 enddo
7 enddo
8 enddo
9 endfunction
10
11 procedureSLOVE_em (patch)
12.......
13!SOMP PARALLEL DO
14 for\(i=1\),numtiles
15 Do some calculations usingtile
16 enddo
17!OMP END PARALLEL DO
18.
19 ifMPI PARALLELthen
20 Transfers data fromhalos
21 to the specified process
22 endif
23 endprocedure
```  
**Algorithm 1** Pseudo-code of data calculation process in _patch_ of WRF  
Where n is the number of processes currently in use. The number of grids assigned to each process in the x-direction is the total number of grids in the x-directionnproc_x, and the number of grids assigned to each process in the y-direction is the total number of grids in the x-direction/nproc_y.  
Patches are used as blocks of data assigned to each process after domain decomposition, and changing the values of nproc_x and nproc_y once the number of processes in use has been determined will change the default algorithm for WRF domain decomposition, which is nproc_y >= nproc_x, with nproc_y-nproc_x being the minimum value. nproc_x and nproc_y values can be changed by setting the parameters in namelistinput [8; 12].  
In the calculation of tiles, the i belongs to the innermost loop (see Algorithm 1). According to the WRF's domain decomposition and tile division approach, the more grids are allocated to patches in the i-direction in the decomposition of the domain, the better the local memory continuity in the i-direction of the tiles during computation (see Figure 4). Of course, for WRF calculations, we need to consider factors such as communication and hardware architecture in addition to the cache, and it is not the case that the more the number of patches' grids in the i-direction is divided, the better. This demonstrates different performance of WRF on different computing platforms and in different arithmetic cases, revealing the preferred method to privilege the best combination of decomposition [7].  
Tile division is based on patch partitioning, which can be changed by numtiles = n in namelistinput, where n is the number of tiles divided by the path. If not set, WRF defaults to n = number of threads used. When the tile division is small enough, the WRF can load into the cache as a whole tile during computation, and vice versa; this may occur multiple times. Therefore, a proper tile division can also improve the access to the cache during WRF calculations.