I am wroking on a simple monte-carlo simulation. It simulates a number of particles moving around, and assign the values of the particles to the passing grid. The following is the skeleton of my program:
//-----------------------------------------------------------
kernel Move1Step(float3 position[], float val[], float media[]){
pos=position [idx];
v=val[idx];
{{modify pos and v based on media[]}}
pisition[idx]=pos;
val[idx]=v;
}
//-----------------------------------------------------------
kernel Assign2Grid(float3 position, float val[], float map[]) {
pos=position [idx];
v=val[idx];
map[MAP_INDEX_3D_TO_1D(pos.x,pos.y,pos.z)] += v;
}
//-----------------------------------------------------------
void main(){
...
for(iter=0;iter<10000;iter++){
Move1Step<<<?,?>>>(position, val,media);
Assign2Grid<<<?,?>>>(position, val,map);
}
...
}
I’ve checked both kernels and they look just fine (and simple), but I am getting weird results: the map is very sparse with only a few non-zero values.
I am wondering if I messed up with something here. does the above code look logically correct to you? if not, what should I change?
thank you for any comments.
(note: assign2grid<<<>>> is basically a scatter kernel. the length of position/val is about 1000, and map can be 128x128x128.)