-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcsCollectActiveParticlesForNewInterval.cu
53 lines (43 loc) · 1.62 KB
/
lcsCollectActiveParticlesForNewInterval.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 : lcsCollectActiveParticlesForNewInterval.cu
Author : Mingcheng Chen
Last Update : September 3rd, 2012
**************************************************************************/
#include <stdio.h>
#define BLOCK_SIZE 1024
__global__ void InitializeScanArrayKernel(int *exitCells, int *scanArray, int length) {
int globalID = blockDim.x * blockIdx.x + threadIdx.x;
if (globalID < length) {
if (exitCells[globalID] < -1) exitCells[globalID] = -(exitCells[globalID] + 2);
scanArray[globalID] = exitCells[globalID] == -1 ? 0 : 1;
}
}
__global__ void CollectActiveParticlesKernel(int *exitCells, int *scanArray, int *activeParticles, int length) {
int globalID = blockDim.x * blockIdx.x + threadIdx.x;
if (globalID < length) {
if (exitCells[globalID] != -1)
activeParticles[scanArray[globalID]] = globalID;
}
}
extern "C"
void InitializeScanArray(int *exitCells, int *scanArray, int length) {
dim3 dimBlock(BLOCK_SIZE, 1, 1);
dim3 dimGrid((length - 1) / dimBlock.x + 1, 1, 1);
InitializeScanArrayKernel<<<dimGrid, dimBlock>>>(exitCells, scanArray, length);
cudaError_t err = cudaDeviceSynchronize();
if (err) {
cudaGetErrorString(err);
exit(0);
}
}
extern "C"
void CollectActiveParticles(int *exitCells, int *scanArray, int *activeParticles, int length) {
dim3 dimBlock(BLOCK_SIZE, 1, 1);
dim3 dimGrid((length - 1) / dimBlock.x + 1, 1, 1);
CollectActiveParticlesKernel<<<dimGrid, dimBlock>>>(exitCells, scanArray, activeParticles, length);
cudaError_t err = cudaDeviceSynchronize();
if (err) {
cudaGetErrorString(err);
exit(0);
}
}