Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. __kernel void diffusion (__global double *heat_values, const float diffusion_const) {
  2. //width and height without padding
  3. int width = get_global_size(0);
  4. //height is not needed
  5. //int height = get_global_size(1);
  6.  
  7. //increment width by 2 to include padding
  8. width += 2;
  9.  
  10. //the caller specifies an offset in clEnqueueNDRangeKernel
  11. //therefore ix & jx are never on the border
  12. int ix = get_global_id(0);
  13. int jx = get_global_id(1);
  14.  
  15. unsigned int px = jx*width + ix;
  16. //printf("[%d]: up=%lf, left=%lf, px=%lf, right=%lf, down=%lf\n", px, heat_values[px-width], heat_values[px-1], heat_values[px], heat_values[px+1], heat_values[px+width]);
  17. double new_temp = heat_values[px] + diffusion_const * (
  18. (heat_values[px-1] + heat_values[px+1] +
  19. heat_values[px-width] + heat_values[px+width]
  20. )/4 - heat_values[px]);
  21.  
  22. //wait for others s.t. we don't override the value if another thread has potentially not read it yet
  23. barrier(CLK_GLOBAL_MEM_FENCE);
  24. heat_values[px] = new_temp;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement