Page MenuHomec4science

simu_gol.hh
No OneTemporary

File Metadata

Created
Sat, May 4, 09:49

simu_gol.hh

#ifndef SIMU_GOL_HH
#define SIMU_GOL_HH
#include "simu.hh"
/* -------------------------------------------------------------------------- */
class GOL : public Simu {
public:
GOL(long int dims[2], int ghost, bool periodic,
MPI_Comm global_comm,
const std::string & server, int port = 4321)
: Simu(dims, ghost, periodic, global_comm, server, port) {}
GOL(long int dims[2], int ghost, bool periodic = true,
MPI_Comm global_comm = MPI_COMM_WORLD)
: Simu(dims, ghost, periodic, global_comm) {}
void determineCell(long int i, long int j, int tid) {
long int _i = i;
long int _j = j;
char neighbours = -((*_old_grid)(_i, _j) & 0x0F);
for (char v = -1; v < 2; ++v)
for (char w = -1; w < 2; ++w)
neighbours += ((*_old_grid)(_i + v, _j + w) & 0x0F);
char res = 0;
if (neighbours == 2) {
res = (*_old_grid)(i, j) & 0x0F;
} else if (neighbours == 3) {
res = 1;
}
(*_grid)(_i, _j) = res + (tid << 4);
}
void initialState(bool random) {
if (random) {
_old_grid->randomize();
} else {
_old_grid->clear();
}
}
};
#endif /* SIMU_GOL_HH */

Event Timeline