# Periodic boundary conditions for stencil algorithms

**URL:** <https://fortran-lang.discourse.group/t/periodic-boundary-conditions-for-stencil-algorithms/7353>\
**Category:** Poll\
**Created:** [February 6, 2024, 6:35pm UTC](https://fortran-lang.discourse.group/t/periodic-boundary-conditions-for-stencil-algorithms/7353 "2024-02-06T18:35:14Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [February 9, 2024, 10:10pm UTC](https://fortran-lang.discourse.group/t/periodic-boundary-conditions-for-stencil-algorithms/7353/11 "2024-02-09T22:10:47Z")

</div>

I found some interesting experiments with stencil and halo syntax for Fortran in the following two works:

- ForOpenCL: Transformations Exploiting Array Syntax in  
Fortran for Accelerator Programming: [https://arxiv.org/pdf/1107.2157.pdf](https://arxiv.org/pdf/1107.2157.pdf)
- Locally-Oriented Programming: A Simple Programming Model for Stencil-Based Computations on Multi-Level Distributed Memory Architectures: [https://arxiv.org/pdf/1502.03504.pdf](https://arxiv.org/pdf/1502.03504.pdf)

The first work would be relevant to the discussion on [Fortran Programmers : How do you want to offload to GPU accelerators in the next 5 years?](https://fortran-lang.discourse.group/t/fortran-programmers-how-do-you-want-to-offload-to-gpu-accelerators-in-the-next-5-years/247/1)

```fortran
! Envisioned stencil syntax
pure CONCURRENT subroutine Laplacian(U)}
real, HALO(:,:) :: U
     U(0,0) = U(0,+1) &
+ U(-1,0) - 4*U(0, 0) + U(+1,0) &
            + U(0,-1)
end subroutine Laplacian

! Declaration syntax including halo
real, allocatable, dimension(:,:), codimension[:,:] &
HALO(1:*:1,1:*:1) :: U

! Launching the kernel
do while (.not. converged)
   do concurrent (i=1:M, j=1:N) [[device]]
      call Laplacian( U(i,j)[device] )
   end do
   call HALO_TRANSFER(U, BC=CYCLIC)
end do

```

---

_[View the full topic](https://fortran-lang.discourse.group/t/periodic-boundary-conditions-for-stencil-algorithms/7353)._
