Skip to content

Commit 81e712f

Browse files
committed
Introduce doc for the halo API
1 parent 30be102 commit 81e712f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

doc/api_halo.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## API for Halo-cell Support
2+
3+
While most of the communications using the 2D decomposition are via the global transposition calls, it may become necessary for neighbouring blocks to exchange data explicitly. One such scenario is in CFD applications performing large-eddy simulations (LES). While most spatial derivatives are computed using the implicit formulation to achieve a high order of accuracy, some derivatives may be evaluated quickly using local stencils and explicit formulae, such as those used by sub-grid scale models (a model by definition does not require higher-order of accuracy).
4+
5+
The halo-cell support API provides data structures and nearest-neighbour communication routines that support explicit message passing between neighbouring pencils. As with the rest of the 2DECOMP&FFT library, the API is designed to be very user-friendly:
6+
7+
```
8+
call update_halo(var, var_halo, level)
9+
```
10+
Here the first parameter `var`, a 3D input array, contains the normal pencil-distributed data as defined by the decomposition library. After invoking the routine, the second parameter `var_halo`, an output, returns all original data plus halo data from the neighbouring processes. One can imagine that pencils are now fatter and overlap with the neighbouring pencils. The third parameter `level` defines how many layers of overlapping is required. `var_halo` should be defined from the calling routine as either a 3D allocatable array or pointer. Its memory space will be calculated and allocated by the library. When the routine returns, `var_halo` can be referenced by the calling program using the normal *i,j,k* indices.
11+
12+
As with the rest of the 2DECOMP&FFT library, a more general form of the routine is available (implemented using Fortran optional arguments):
13+
```
14+
call update_halo(var, var_halo, level, opt_decomp, opt_global)
15+
```
16+
This supports halo-cell communications among pencils with arbitrary global sizes, as described by `opt_decomp`, the decomposition object. The last optional parameter `opt_global` is required (to be set to `.true.`) if global coordinate is used to define the pencils, i.e. the input array `var` is defined using the *start/end* variables rather than the *size* variables. This ensures the coordinate systems used by `var` and `var_halo` are consistent.
17+
18+
To demonstrate the use of this API, here is an example that computes spatial derivatives:
19+
20+
```
21+
! to calculate dv/dy, assume that variables are stored in X-pencil
22+
23+
real, allocatable, dimension(:,:,:) :: v, v_halo, dvdy
24+
25+
allocate(v(xsize(1), xsize(2), xsize(3)))
26+
allocate(dvdy(xsize(1), xsize(2), xsize(3)))
27+
28+
call update_halo(v,v_halo,level=1)
29+
30+
! compute derivatives
31+
do k=1,xsize(3)
32+
do j=1,xsize(2)
33+
do i=1,xsize(1)
34+
dvdy(i,j,k) = (v_halo(i,j+1,k)-v_halo(i,j-1,k)) / dy
35+
end do
36+
end do
37+
end do
38+
```
39+
40+
As seen, the variables are stored in X-pencil and derivatives are to be evaluated over distributed data along Y direction using a central finite difference scheme. This is the perfect situation to use the halo-cell support API. Using global transpositions would be unnecessarily too expensive for this type of local/explicit calculations. After the call to `update_halo`, it is safe to refer to the *j+1* and *j-1* indices on array `v_halo` in order to compute the derivatives.
41+
42+
Note that for the pencils bordering the computational domain, it is up to the application to handle the physical boundary conditions. The library does support periodic condition, i.e. for processes near the boundary of the computational domain, a call to the update_halo routine will fill the halo cells of one side with values from the other side of the domain, when periodic condition is required. To specify periodic condition, one need to initialise the decomposition library with additional information:
43+
```
44+
call decomp_2d_init(nx, ny, nz, P_row, P_col, periodic_bc)
45+
```
46+
The extra parameter `periodic_bc` is a 1D array containing 3 logical values that specify which dimension should be periodic. This parameter is optional and is only used with the halo-cell API. The domain decomposition should otherwise behaves exactly as normal.
47+
48+
Like the rest of 2DECOMP&FFT, the halo-cell support API is implemented in a black-box fashion. The library internally handles the communications between neighbouring blocks using the standard MPI non-blocking point-to-point communications.

0 commit comments

Comments
 (0)