life.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011,2013,2017 CNRS
  4. * Copyright (C) 2010,2011,2014 Université de Bordeaux
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include "stencil.h"
  18. /* Heart of the stencil computation: compute a new state from an old one. */
  19. void life_update(int bz, const TYPE *old, TYPE *newp, int nx, int ny, int nz, int ldy, int ldz, int iter)
  20. {
  21. (void)bz;
  22. int x, y, z, num, alive;
  23. for (z = iter; z < nz - iter; z++)
  24. {
  25. for (y = K; y < ny - K; y++)
  26. {
  27. for (x = K; x < nx - K; x++)
  28. {
  29. num = 0
  30. + old[x+(y+1)*ldy+(z+0)*ldz]
  31. + old[x+(y+1)*ldy+(z+1)*ldz]
  32. + old[x+(y+0)*ldy+(z+1)*ldz]
  33. + old[x+(y-1)*ldy+(z+1)*ldz]
  34. + old[x+(y-1)*ldy+(z+0)*ldz]
  35. + old[x+(y-1)*ldy+(z-1)*ldz]
  36. + old[x+(y+0)*ldy+(z-1)*ldz]
  37. + old[x+(y+1)*ldy+(z-1)*ldz]
  38. ;
  39. alive = old[x+y*ldy+z*ldz];
  40. alive = (alive && num == 2) || num == 3;
  41. newp[x+y*ldy+z*ldz] = alive;
  42. }
  43. }
  44. }
  45. }