Skip to content

Latest commit

 

History

History
101 lines (76 loc) · 3.8 KB

File metadata and controls

101 lines (76 loc) · 3.8 KB

Sample code for GPU computing

Sample1

The code just calculates the sum of the two vectors.
\begin{align*} C_i=A_i+B_i \end{align*}

See the code for CPU and GPU.

How to compile and run the sample codes is shown as follows.

cd cpp
make
sbatch pbs_sample1.sh
cat sample1.cpulog
cat sample1.gpulog

References

Sample2

This example shows how GPU calculates fast. The calculation is basically the same as the sample1.

See the code for CPU and GPU.

How to compile and run the sample codes is shown as follows.

cd cpp
make
sbatch pbs_sample2.sh
cat sample2.cpulog
cat sample2.gpulog

Sample3

This example shows how 2D array is treated. We solve 2D poission equation by Jacobi method.
\begin{align*} \frac{\partial^2 \Phi}{\partial ^2x} +\frac{\partial^2 \Phi}{\partial ^2y} =4\pi G \rho \end{align*}

In the method, the gravitational potential is obtained by the following iterative procedure. \begin{align*} \Phi^{n+1}{i,j}= \left( \Phi^{n}{i+1,j}+\Phi^{n}{i-1,j} +\Phi^{n}{i,j+1}+\Phi^{n}{i,j-1} -4\pi G \rho{i,j}h^2 \right)/4 \end{align*}

See the code for CPU and GPU.

How to compile and run the sample codes is shown as follows.

cd cpp
make
sbatch pbs_sample3.sh
cat sample3.cpulog
cat sample3.gpulog

Check the gravitational potential by gnuplot. Follow the instruction in the analysis server..

cd /gwork0/<username>/gpusample/cpp
gnuplot
splot "xy-gpu.dat" u 1:2:4 w l
splot "xy-cpu.dat" u 1:2:4 w l

References

Sample4

This example shows how the summation of all components of a vector are obtained.

\begin{align*} S=\sum_i^N a_i \end{align*}

See the code for CPU and GPU. This code implementation is the simplest and slowest one, so if you want to use faster code, see the references.

How to compile and run the sample codes is shown as follows.

cd cpp
make
sbatch pbs_sample4.sh
cat sample4.cpulog
cat sample4.gpulog

References