# A Parallel Algorithm Based on Regularized Lattice Boltzmann Method for Multi-Layer Grids
## 3 Parallel Strategy and Algorithm  
This paper describes the division of the grid in the two-dimensional case. A load balancing strategy [34] prevents a process from going into an idle state while waiting for data from other processes. When performing simulations, all grid cells are assigned to  
Figure 4: Schematic diagram for multi-layer grids. Figure 5: Schematic diagram of the interpolation process. available processes. The presence of idle processes is prevented. The effective assignment of grids to processes is essential for efficiency improvements. In the simulation scenario, the grid for each layer is stored in a one-dimensional array. This array stores the number of grids involved in each column of the evolution step for the grid region. The one-dimensional array is partitioned according to the number of processes. Firstly, this paper separates the different grid layers into individual dimensions. Divide the various layers of the grid into multiple subdomains along the same direction. Subdomains with the same number of processes in different layers are formed into a separate computational region. At the same time, data exchange between boundary grids basically occurs only between neighboring processes. In this paper, the grid division algorithm is designed in Algorithm 1. The flowchart for grid division is shown in Figure 6.  
```
1:Number of grid layers: \(N\); Number of processes: \(np\);
2:File after grid division. 3:int \(Col[N][R]=0\), \(Total[N][R]=0\);
4:// \(R\) is the number of columns in the current layer grid. 5://\(Col[N][R]\) represents how many grids are stored in each of the columns 1 to \(R\) from layer 1 to layer \(N\). 6://\(Total[N][R]\) represents how many grids are stored in column 1 to the current column. 7:for int \(k=0\) to \(N-1\)do
8:for int \(j=0\) to \(R-1\)do
9:\(Col[k][j]=l\); // \(l\) is the number of grids in the \(jth\) column of the \(kth\) layer. 10:endfor
11:for int \(k=0\) to \(N-1\)do
12:for int \(j=0\) to \(R-1\)do
13:\(Total[k][j]=Total[k][j-1]+Col[k][j]\) ;
14:endfor
15:endfor
16:for int \(id=0\) to \(np-1\)do
17:for int \(k=0\) to \(N-1\)do
18:for int \(j=0\) to \(R-1\)do
19:if\(Total[k][j]>Total[k][R-1]*(id+1)/np\)then
20: int \(a=Total[k][j]-Total[k][R-1]*(id+1)/np\);
21: int \(b=Total[k][R-1]*(id+1)/np-Total[k][j-1]\);
22:if a < b then
23: Set the process number in this column to \(id\);
24:\(+id\);
25:else
26: \(+id\);
27: Set the process number in this column to \(id\);
28:endif
29: Set the process number in this column to \(id\);
30:endif
31:endfor
32:endfor
33:endfor
```  
**Algorithm 1** Load Balancing-Based Grid Dividing Algorithm  
The division of the multi-layer grid is shown schematically in Figure 7.  
Figure 6: Flow chart for grid division. Figure 7: Schematic diagram of the multi-layer grid division. The three-layer grid structure of a two-dimensional flow over two circular cylinders is taken as an example in this paper. Using the multi-layer grids RLBM, all grid points within the same layer have similar computational demands. Coarse grid points undergo half the computations compared to fine grid points. The grid area in Figure 7 consists of three distinct grid sizes. Based on the division idea in Algorithm 1, a parallel grid division was performed. Grids of varying resolutions are partitioned into four equal segments. Each MPI process manages a segment of each grid layer. The data transfer method utilizing this parallel partitioning is illustrated in Figure 7. Red denotes process 0, yellow denotes process 1, purple denotes process 2, and blue denotes process 3. The data-transfer method of the multi-layer grid is shown schematically in Figure 8.  
Under this parallel strategy, each process exchanges data solely with two neighboring processes. The parallel algorithm proposed in this paper relies on the grid division algorithm within the computational domain. After dividing the grid into sections, the data at the grid junctions include data for evolution and data for interpolation.