-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcsCollectActiveParticlesForNewRun.cu
54 lines (43 loc) · 1.75 KB
/
lcsCollectActiveParticlesForNewRun.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/************************************************************************
File : lcsCollectActiveParticlesForNewRun.cu
Author : Mingcheng Chen
Last Update : January 29th, 2013
*************************************************************************/
#include <stdio.h>
#define BLOCK_SIZE 1024
__global__ void InitializeScanArrayKernel(int *exitCells, int *oldActiveParticles, int *scanArray, int length) {
int globalID = blockDim.x * blockIdx.x + threadIdx.x;
if (globalID < length)
scanArray[globalID] = exitCells[oldActiveParticles[globalID]] < 0 ? 0 : 1;
}
__global__ void CollectActiveParticlesKernel(int *exitCells, int *oldActiveParticles, int *scanArray,
int *newActiveParticles, int length) {
int globalID = blockDim.x * blockIdx.x + threadIdx.x;
if (globalID < length)
if (exitCells[oldActiveParticles[globalID]] >= 0)
newActiveParticles[scanArray[globalID]] = oldActiveParticles[globalID];
}
extern "C"
void InitializeScanArray2(int *exitCells, int *oldActiveParticles, int *scanArray, int length) {
dim3 dimBlock(BLOCK_SIZE, 1, 1);
dim3 dimGrid((length - 1) / dimBlock.x + 1, 1, 1);
InitializeScanArrayKernel<<<dimGrid, dimBlock>>>(exitCells, oldActiveParticles, scanArray, length);
cudaError_t err = cudaDeviceSynchronize();
if (err) {
cudaGetErrorString(err);
exit(0);
}
}
extern "C"
void CollectActiveParticles2(int *exitCells, int *oldActiveParticles, int *scanArray,
int *newActiveParticles, int length) {
dim3 dimBlock(BLOCK_SIZE, 1, 1);
dim3 dimGrid((length - 1) / dimBlock.x + 1, 1, 1);
CollectActiveParticlesKernel<<<dimGrid, dimBlock>>>(exitCells, oldActiveParticles, scanArray,
newActiveParticles, length);
cudaError_t err = cudaDeviceSynchronize();
if (err) {
cudaGetErrorString(err);
exit(0);
}
}