This is a simple demonstration of running the MATLAB code provided in the appendix of the following paper:

X. Liu, J. Shen and X. Zhang, A simple GPU implementation of spectral-element methods for solving 3D Poisson type
equations on cartesian meshes. arXiv PDF



Download and unzip the code which consists of three MATLAB scripts. Matlab 2023 is needed.

This is an example of accelerating a simple 3D Poisson solver (Q^k spectral element method) on GPU. See the paper above for details. The script Poisson3D.m sets Np=5 for Q^5 element, and Nx=40, Ny=40, Nz=40 for a 40^3 finite element mesh. You can change Np, Nx, Ny, Nz to any natural number. 

The script Poisson3D.m will detect whether there is a GPU device to use. If there is a GPU device, the script will do computation on default GPU device ID=1. Otherwise, the script will do the computation on CPU. You should change the GPU ID to the your desired one there are multiple GPU cards. The following is what it looks like when running the code on a machine equipped with at least one GPU card:
~ % cd Poisson_GPUCode
Poisson_GPUCode % matlab -nodisplay

< M A T L A B (R) >
Copyright 1984-2023 The MathWorks, Inc.
R2023a Update 2 (9.14.0.2254940) 64-bit (glnxa64)
April 17, 2023

>> run('Poisson3D.m')
3D Poisson with total DoFs 201 by 201 by 201
Laplacian is Q5 spectral element method
GPU computation: starting to load matrices/data
GPU loading finished and computing started
The ell infinity norm error is 1.970776e-10
The online GPU computation time is 7.340000e-02

Now in Poisson3D.m, set Np=5, and Nx=200, Ny=200, Nz=200, for which the number total Degree of Freedoms is 1001^3:

>> run('Poisson3D.m') 
3D Poisson with total DoFs 1001 by 1001 by 1001
Laplacian is Q5 spectral element method
GPU computation: starting to load matrices/data
GPU loading finished and computing started
The ell infinity norm error is 1.300271e-11
The online GPU computation time is 7.877890e-01

Though the offline computation (loading data to GPU) may take a while, the online GPU computation time is 0.7877890 second for inverting high order accurate Laplacian for about one billion DoFs on one Nvidia A100 80G GPU card.

The following is what happens if there is no GPU device available, when running the script Poisson3D.m. Be aware that GPU acceleration can be observed only for large enough problems. 

Poisson_GPUCode % matlab -nodisplay

< M A T L A B (R) >
Copyright 1984-2023 The MathWorks, Inc.
R2023a Update 2 (9.14.0.2254940) 64-bit (glnxa64)
April 17, 2023
>> run ('Poisson3D.m')
3D Poisson with total DoFs 201 by 201 by 201
Laplacian is Q5 spectral element method
The ell infinity norm error is 1.964983e-10
The online CPU computation time is 2.100320e-01

Author: Xiangxiong Zhang.