milupHPC documentation
  • src
  • integrator
device_leapfrog.cu
Go to the documentation of this file.
1#include "../../include/integrator/device_leapfrog.cuh"
2#include "../../include/cuda_utils/cuda_launcher.cuh"
3
4__global__ void LeapfrogNS::Kernel::updateX(Particles *particles, integer n, real dt) {
5
6 integer bodyIndex = threadIdx.x + blockIdx.x * blockDim.x;
7 integer stride = blockDim.x * gridDim.x;
8 integer offset = 0;
9
10 while (bodyIndex + offset < n) {
11
12
13 //if ((bodyIndex + offset) == 10) {
14 // printf("check: x = %e += %e * (%e + 0.5 * %e * %e) = %e\n", particles->x[bodyIndex + offset], dt, particles->vx[bodyIndex + offset],
15 // dt, particles->g_ax[bodyIndex + offset], dt * (particles->vx[bodyIndex + offset] + 0.5 * dt * particles->g_ax[bodyIndex + offset]));
16 //}
17
18 // update x
19 particles->x[bodyIndex + offset] += dt * (particles->vx[bodyIndex + offset] + 0.5 * dt * particles->g_ax[bodyIndex + offset]);
20 particles->g_ax_old[bodyIndex + offset] = particles->g_ax[bodyIndex + offset];
21#if DIM > 1
22 particles->y[bodyIndex + offset] += dt * (particles->vy[bodyIndex + offset] + 0.5 * dt * particles->g_ay[bodyIndex + offset]);
23 particles->g_ay_old[bodyIndex + offset] = particles->g_ay[bodyIndex + offset];
24#if DIM == 3
25 particles->z[bodyIndex + offset] += dt * (particles->vz[bodyIndex + offset] + 0.5 * dt * particles->g_az[bodyIndex + offset]);
26 particles->g_az_old[bodyIndex + offset] = particles->g_az[bodyIndex + offset];
27#endif
28#endif
29
30 offset += stride;
31 }
32}
33
34__global__ void LeapfrogNS::Kernel::updateV(Particles *particles, integer n, real dt) {
35
36 integer bodyIndex = threadIdx.x + blockIdx.x * blockDim.x;
37 integer stride = blockDim.x * gridDim.x;
38 integer offset = 0;
39
40 while (bodyIndex + offset < n) {
41
42 //if ((bodyIndex + offset) == 10) {
43 // printf("check: vx = %e += 0.5 * %e * (%e + %e) = %e\n", particles->vx[bodyIndex + offset], dt, particles->g_ax[bodyIndex + offset], particles->g_ax_old[bodyIndex + offset],
44 // 0.5 * dt * (particles->g_ax[bodyIndex + offset] + particles->g_ax_old[bodyIndex + offset]));
45 //}
46
47 // update v
48 particles->vx[bodyIndex + offset] += 0.5 * dt * (particles->g_ax[bodyIndex + offset] + particles->g_ax_old[bodyIndex + offset]);
49#if DIM > 1
50 particles->vy[bodyIndex + offset] += 0.5 * dt * (particles->g_ay[bodyIndex + offset] + particles->g_ay_old[bodyIndex + offset]);
51#if DIM == 3
52 particles->vz[bodyIndex + offset] += 0.5 * dt * (particles->g_az[bodyIndex + offset] + particles->g_az_old[bodyIndex + offset]);
53#endif
54#endif
55
56 offset += stride;
57 }
58}
59
60real LeapfrogNS::Kernel::Launch::updateX(Particles *particles, integer n, real dt) {
61
62 ExecutionPolicy executionPolicy;
63 return cuda::launch(true, executionPolicy, ::LeapfrogNS::Kernel::updateX, particles, n, dt);
64
65}
66
67real LeapfrogNS::Kernel::Launch::updateV(Particles *particles, integer n, real dt) {
68
69 ExecutionPolicy executionPolicy;
70 return cuda::launch(true, executionPolicy, ::LeapfrogNS::Kernel::updateV, particles, n, dt);
71
72}
ExecutionPolicy
Execution policy/instruction for CUDA kernel execution.
Definition: cuda_launcher.cuh:33
Particles
Particle(s) class based on SoA (Structur of Arrays).
Definition: particles.cuh:50
Particles::g_az_old
real * g_az_old
Definition: particles.cuh:97
Particles::x
real * x
(pointer to) x position (array)
Definition: particles.cuh:62
Particles::g_ax_old
real * g_ax_old
Definition: particles.cuh:89
Particles::g_ay
real * g_ay
(pointer to) y gravitational acceleration (array)
Definition: particles.cuh:92
Particles::y
real * y
(pointer to) y position (array)
Definition: particles.cuh:70
Particles::g_ay_old
real * g_ay_old
Definition: particles.cuh:93
Particles::g_ax
real * g_ax
(pointer to) x gravitational acceleration (array)
Definition: particles.cuh:88
Particles::z
real * z
(pointer to) z position (array)
Definition: particles.cuh:78
Particles::vz
real * vz
(pointer to) z velocity (array)
Definition: particles.cuh:80
Particles::g_az
real * g_az
(pointer to) z gravitational acceleration (array)
Definition: particles.cuh:96
Particles::vx
real * vx
(pointer to) x velocity (array)
Definition: particles.cuh:64
Particles::vy
real * vy
(pointer to) y velocity (array)
Definition: particles.cuh:72
LeapfrogNS::Kernel::Launch::updateX
real updateX(Particles *particles, integer n, real dt)
Wrapper for LeapfrogNS::Kernel::update().
Definition: device_leapfrog.cu:60
LeapfrogNS::Kernel::Launch::updateV
real updateV(Particles *particles, integer n, real dt)
Definition: device_leapfrog.cu:67
LeapfrogNS::Kernel::updateV
__global__ void updateV(Particles *particles, integer n, real dt)
Definition: device_leapfrog.cu:34
LeapfrogNS::Kernel::updateX
__global__ void updateX(Particles *particles, integer n, real dt)
Update/move/advance particles.
Definition: device_leapfrog.cu:4
cuda::launch
real launch(bool timeKernel, const ExecutionPolicy &policy, void(*f)(Arguments...), Arguments... args)
CUDA execution wrapper function.
Definition: cuda_launcher.cuh:114
real
double real
Definition: parameter.h:15
integer
int integer
Definition: parameter.h:17

milupHPC - src/integrator/device_leapfrog.cu Source File
Generated on Wed Aug 31 2022 12:16:52 by Doxygen 1.9.3