]> AND Private Git Repository - book_gpu.git/blob - BookGPU/Chapters/chapter5/code/ex2.cu
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
add ch4
[book_gpu.git] / BookGPU / Chapters / chapter5 / code / ex2.cu
1 #include <gpulab/grid.h>\r
2 #include <gpulab/FD/stencil.h>\r
3 \r
4 int main(int argc, char *argv[])\r
5 {\r
6         // Initialize grid dimensions\r
7         unsigned int Nx = 10,  Ny = 10;\r
8         gpulab::grid_dim<unsigned int> dim(Nx,Ny);\r
9         gpulab::grid<double> u(dim);\r
10         gpulab::grid<double> ux(u);\r
11         gpulab::grid<double> uxy(u);\r
12 \r
13         // Put meaningful values into u here ...\r
14 \r
15         // Stencil size, alpha=beta=2, 9pt 2D stencil\r
16         int alpha = 2;\r
17         // 1st order derivative\r
18         gpulab::FD::stencil_2d<double> stencil(1, alpha);\r
19         // Calculate uxy = du/dx + du/dy\r
20         stencil.mult(u,uxy);\r
21         // Calculate ux  = du/dx\r
22         stencil.diff_x(u,ux);\r
23         // Host and device pointers to stencil coeffs\r
24         double const* hc = stencil.coeffs_host();\r
25         double const* dc = stencil.coeffs_device();\r
26 \r
27         return 0;\r
28 }\r