life.c 1.7 KB

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