@ -140,145 +140,154 @@ Dalam folder **example** di struktur direktori sumber terdapat contoh penggunaan
1. Buat file **CMakeLists.txt** dengan struktur sebagai berikut untuk menambahkan pustaka cuda (**libcuda.so**) dan pustaka PoissonSolver3DCylindricalGPU (**libPoissonSolver3DCylindricalGPU.so**) pada proyek cmake:
1. Buat file **CMakeLists.txt** dengan struktur sebagai berikut untuk menambahkan pustaka cuda (**libcuda.so**) dan pustaka PoissonSolver3DCylindricalGPU (**libPoissonSolver3DCylindricalGPU.so**) pada proyek cmake:
```
```
cmake_minimum_required (VERSION 2.8.11)
cmake_minimum_required (VERSION 2.8.11)
project (3DPoissonSolverGPUTest)
project (3DPoissonSolverGPUTest)
find_package(CUDA)
find_package(CUDA)
if(NOT CUDA_FOUND)
if(NOT CUDA_FOUND)
message( FATAL_ERROR "NVIDIA CUDA package not found" )
message( FATAL_ERROR "NVIDIA CUDA package not found" )
else()
else()
find_library(LIBCUDA_SO_PATH libcuda.so)
find_library(LIBCUDA_SO_PATH libcuda.so)
string(FIND ${LIBCUDA_SO_PATH} "-NOTFOUND" LIBCUDA_SO_PATH_NOTFOUND )
string(FIND ${LIBCUDA_SO_PATH} "-NOTFOUND" LIBCUDA_SO_PATH_NOTFOUND )
endif(NOT CUDA_FOUND)
endif(NOT CUDA_FOUND)
message( STATUS "Building Poisson Solver with CUDA support" )
message( STATUS "Building Poisson Solver with CUDA support" )
if(LIBCUDA_SO_PATH_NOTFOUND GREATER -1)
if(LIBCUDA_SO_PATH_NOTFOUND GREATER -1)
message( FATAL_ERROR "NVIDIA CUDA libcuda.so not found" )
message( FATAL_ERROR "NVIDIA CUDA libcuda.so not found" )
endif(LIBCUDA_SO_PATH_NOTFOUND GREATER -1)
endif(LIBCUDA_SO_PATH_NOTFOUND GREATER -1)
#set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/cuda" ${CMAKE_MODULE_PATH})
#set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/cuda" ${CMAKE_MODULE_PATH})
#find_package (CUDA QUIET REQUIRED)
#find_package (CUDA QUIET REQUIRED)
set(PSLIBNAME libPoissonSolver3DCylindricalGPU.so)
set(PSLIBNAME libPoissonSolver3DCylindricalGPU.so)
find_library(PSLIB ${PSLIBNAME})
string(FIND ${PSLIB} "-NOTFOUND" PSLIB_NOTFOUND )
if(PSLIB_NOTFOUND GREATER -1)
message( FATAL_ERROR "Poisson Solver Cuda Library libPoissonSolver3DCylindricalGPU.o not found" )
endif(PSLIB_NOTFOUND GREATER -1)
```
find_library(PSLIB ${PSLIBNAME})
Setelah itu, baru tambahkan perintah pada CMakeLists.txt (dilanjutkan) untuk mengikut sertakan kode sumber user yaitu:
string(FIND ${PSLIB} "-NOTFOUND" PSLIB_NOTFOUND )
if(PSLIB_NOTFOUND GREATER -1)
message( FATAL_ERROR "Poisson Solver Cuda Library libPoissonSolver3DCylindricalGPU.o not found" )
endif(PSLIB_NOTFOUND GREATER -1)
```
```
Setelah itu, baru tambahkan perintah pada CMakeLists.txt (dilanjutkan) untuk mengikut sertakan kode sumber user yaitu:
# tambah disini kode sumber user
set(CPP_SOURCE PoissonSolver3DGPUTest.cpp)
set(HEADERS PoissonSolver3DGPUTest.h)
set(TARGET_NAME poissonsolvergputest)
add_executable(${TARGET_NAME}
PoissonSolver3DGPUTest.cpp
)
# ikut sertakan shared library cuda dan poisson solver
target_link_libraries(${TARGET_NAME} ${PSLIB} ${LIBCUDA_SO_PATH})
```
```
# tambah disini kode sumber user
set(CPP_SOURCE PoissonSolver3DGPUTest.cpp)
set(HEADERS PoissonSolver3DGPUTest.h)
set(TARGET_NAME poissonsolvergputest)
2. Pada kode sumber include header file sehingga definisi fungsi dan kelas dapat dipanggil di badan kode.
add_executable(${TARGET_NAME}
```c++
PoissonSolver3DGPUTest.cpp
#include "PoissonSolver3DCylindricalGPU.h"
)
...
# ikut sertakan shared library cuda dan poisson solver
// create poissonSolver
target_link_libraries(${TARGET_NAME} ${PSLIB} ${LIBCUDA_SO_PATH})
PoissonSolver3DCylindricalGPU *poissonSolver = new PoissonSolver3DCylindricalGPU();
PoissonSolver3DCylindricalGPU::fgConvergenceError = 1e-8;
poissonSolver->SetExactSolution(VPotentialExact,kRows,kColumns, kPhiSlices);
poissonSolver->SetStrategy(PoissonSolver3DCylindricalGPU::kMultiGrid);
poissonSolver->SetCycleType(PoissonSolver3DCylindricalGPU::kFCycle);
poissonSolver->PoissonSolver3D(VPotential,RhoCharge,kRows,kColumns,kPhiSlices, kIterations,kSymmetry) ;
```
```
2. Pada kode sumber include header file sehingga definisi fungsi dan kelas dapat dipanggil di badan kode.
```c++
#include "PoissonSolver3DCylindricalGPU.h"
...
// create poissonSolver
PoissonSolver3DCylindricalGPU *poissonSolver = new PoissonSolver3DCylindricalGPU();
PoissonSolver3DCylindricalGPU::fgConvergenceError = 1e-8;
poissonSolver->SetExactSolution(VPotentialExact,kRows,kColumns, kPhiSlices);
poissonSolver->SetStrategy(PoissonSolver3DCylindricalGPU::kMultiGrid);
poissonSolver->SetCycleType(PoissonSolver3DCylindricalGPU::kFCycle);
poissonSolver->PoissonSolver3D(VPotential,RhoCharge,kRows,kColumns,kPhiSlices, kIterations,kSymmetry) ;
```
3. Buat folder terpisah untuk mebangun proyek yang menggunakan pustaka misal **buildexamplepoissonsolver** lalu jalankan **cmake** dengan flag spesial yaitu ** -DCMAKE_PREFIX_PATH** yang ditetapkan dengan absolute path tempat direktori PoissonSolver3DCylindricalGPU dibangun.
3. Buat folder terpisah untuk mebangun proyek yang menggunakan pustaka misal **buildexamplepoissonsolver** lalu jalankan **cmake** dengan flag spesial yaitu ** -DCMAKE_PREFIX_PATH** yang ditetapkan dengan absolute path tempat direktori PoissonSolver3DCylindricalGPU dibangun.
```
```
$ mkdir buildexamplepoissonsolver
$ mkdir buildexamplepoissonsolver
$ cd buildexamplepoissonsolver
$ cd buildexamplepoissonsolver
$ cmake ../PoissonSolver3D/example/ -DCMAKE_PREFIX_PATH=/home/usertest/trypoissonsolver/buildpoissonsolver
$ cmake ../PoissonSolver3D/example/ -DCMAKE_PREFIX_PATH=/home/usertest/trypoissonsolver/buildpoissonsolver
...
...
-- Found CUDA: /apps/tools/cuda-9.1 (found version "9.1")
-- Found CUDA: /apps/tools/cuda-9.1 (found version "9.1")
-- Building Poisson Solver with CUDA support
-- Building Poisson Solver with CUDA support
-- Configuring done
-- Configuring done
-- Generating done
-- Generating done
-- Build files have been written to: /home/usertest/trypoissonsolver/buildexamplepoissonsolver
-- Build files have been written to: /home/usertest/trypoissonsolver/buildexamplepoissonsolver
```
```
4. Jalankan **make** untuk membuat *executable file*
4. Jalankan **make** untuk membuat *executable file*
```
```
$ make
$ make
-- Building Poisson Solver with CUDA support
-- Building Poisson Solver with CUDA support
-- Configuring done
-- Configuring done
-- Generating done
-- Generating done
-- Build files have been written to: /home/usertest/trypoissonsolver/buildexamplepoissonsolver
-- Build files have been written to: /home/usertest/trypoissonsolver/buildexamplepoissonsolver
[ 50%] Linking CXX executable poissonsolvergputest
[ 50%] Linking CXX executable poissonsolvergputest
[100%] Built target poissonsolvergputest
[100%] Built target poissonsolvergputest
```
```
5. Hasil dari **make** adalah program yang dapat dieksekusi yang berjalan di GPU card
5. Hasil dari **make** adalah program yang dapat dieksekusi yang berjalan di GPU card
```
```
$ ./poissonsolvergputest
$ ./poissonsolvergputest
Poisson Solver 3D Cylindrical GPU test
Poisson Solver 3D Cylindrical GPU test
Ukuran grid (r,phi,z) = (17,17,18)
Ukuran grid (r,phi,z) = (17,17,18)
Waktu komputasi: 0.55 s
Waktu komputasi: 0.55 s
Jumlah iterasi siklus multigrid: 5
Jumlah iterasi siklus multigrid: 5
Iterasi Error Convergen Error Absolut
Iterasi Error Convergen Error Absolut
[0]: 8.362587e-01 2.430797e-03
[0]: 8.362587e-01 2.430797e-03
[1]: 5.126660e-02 4.434380e-04
[1]: 5.126660e-02 4.434380e-04
[2]: 9.490424e-03 1.892288e-04
[2]: 9.490424e-03 1.892288e-04
[3]: 2.084086e-03 1.314385e-04
[3]: 2.084086e-03 1.314385e-04
[4]: 1.141812e-03 1.217592e-04
[4]: 1.141812e-03 1.217592e-04
Poisson Solver 3D Cylindrical GPU test
Ukuran grid (r,phi,z) = (33,33,36)
Waktu komputasi: 1.000000e-02 s
Jumlah iterasi siklus multigrid: 10
Iterasi Error Convergen Error Absolut
[0]: 1.724319e-03 1.315177e-04
[1]: 8.652242e-05 1.266415e-04
[2]: 5.450314e-05 1.256187e-04
[3]: 5.081671e-05 1.249848e-04
[4]: 4.951065e-05 1.244460e-04
[5]: 4.904093e-05 1.241379e-04
[6]: 4.890266e-05 1.239894e-04
[7]: 4.885175e-05 1.239208e-04
[8]: 4.883604e-05 1.238959e-04
[9]: 4.883501e-05 1.238844e-04
Poisson Solver 3D Cylindrical GPU test
Ukuran grid (r,phi,z) = (65,65,72)
Waktu komputasi: 5.000000e-02 s
Jumlah iterasi siklus multigrid: 3
Iterasi Error Convergen Error Absolut
[0]: 1.084726e-04 1.291784e-04
[1]: 5.680057e-06 1.283386e-04
[2]: 1.501479e-06 1.278558e-04
Poisson Solver 3D Cylindrical GPU test
Ukuran grid (r,phi,z) = (129,129,144)
Waktu komputasi: 1.200000e-01 s
Jumlah iterasi siklus multigrid: 3
Iterasi Error Convergen Error Absolut
[0]: 1.373293e-05 1.302576e-04
[1]: 2.154564e-06 1.299626e-04
[2]: 1.048384e-06 1.297261e-04
Poisson Solver 3D Cylindrical GPU test
Ukuran grid (r,phi,z) = (257,257,288)
Waktu komputasi: 6.900000e-01 s
Jumlah iterasi siklus multigrid: 5
Iterasi Error Convergen Error Absolut
[0]: 5.469890e-06 1.388922e-04
[1]: 1.783695e-06 1.384964e-04
[2]: 1.345343e-06 1.381199e-04
[3]: 1.156555e-06 1.377524e-04
[4]: 1.050234e-06 1.373983e-04
```
Poisson Solver 3D Cylindrical GPU test
Ukuran grid (r,phi,z) = (33,33,36)
Waktu komputasi: 1.000000e-02 s
Jumlah iterasi siklus multigrid: 10
Iterasi Error Convergen Error Absolut
[0]: 1.724319e-03 1.315177e-04
[1]: 8.652242e-05 1.266415e-04
[2]: 5.450314e-05 1.256187e-04
[3]: 5.081671e-05 1.249848e-04
[4]: 4.951065e-05 1.244460e-04
[5]: 4.904093e-05 1.241379e-04
[6]: 4.890266e-05 1.239894e-04
[7]: 4.885175e-05 1.239208e-04
[8]: 4.883604e-05 1.238959e-04
[9]: 4.883501e-05 1.238844e-04
Poisson Solver 3D Cylindrical GPU test
Ukuran grid (r,phi,z) = (65,65,72)
Waktu komputasi: 5.000000e-02 s
Jumlah iterasi siklus multigrid: 3
Iterasi Error Convergen Error Absolut
[0]: 1.084726e-04 1.291784e-04
[1]: 5.680057e-06 1.283386e-04
[2]: 1.501479e-06 1.278558e-04
Poisson Solver 3D Cylindrical GPU test
Ukuran grid (r,phi,z) = (129,129,144)
Waktu komputasi: 1.200000e-01 s
Jumlah iterasi siklus multigrid: 3
Iterasi Error Convergen Error Absolut
[0]: 1.373293e-05 1.302576e-04
[1]: 2.154564e-06 1.299626e-04
[2]: 1.048384e-06 1.297261e-04
Poisson Solver 3D Cylindrical GPU test
Ukuran grid (r,phi,z) = (257,257,288)
Waktu komputasi: 6.900000e-01 s
Jumlah iterasi siklus multigrid: 5
Iterasi Error Convergen Error Absolut
[0]: 5.469890e-06 1.388922e-04
[1]: 1.783695e-06 1.384964e-04
[2]: 1.345343e-06 1.381199e-04
[3]: 1.156555e-06 1.377524e-04
[4]: 1.050234e-06 1.373983e-04
```