Page MenuHomec4science

game-of-life.cc
No OneTemporary

File Metadata

Created
Mon, Nov 4, 10:50

game-of-life.cc

#include "simu_gol.hh"
#include "cppargparse/cppargparse.hh"
#include <iostream>
#include <mpi.h>
int main(int argc, char ** argv) {
cppargparse::ArgumentParser parser;
parser.addArgument("-s;--server", "Server to connect to for visualization",
1, cppargparse::_string, "127.0.0.1");
parser.addArgument("-p;--port", "Port",
1, cppargparse::_integer, 4321);
parser.addArgument("--no_visu", "Do not connect to a visualization server",
0, cppargparse::_boolean, false, true);
parser.addArgument("-r;--random", "Init at random",
0, cppargparse::_boolean, false, true);
parser.addArgument("-g;--grid", "Grid height width",
2, cppargparse::_integer);
parser.parse(argc, argv);
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
long int dims[2] = {216, 384};
if (parser.has("grid")) {
std::vector<int> grid_dims = parser["grid"];
dims[0] = grid_dims[0];
dims[1] = grid_dims[1];
}
//long int dims[2] = {21, 21};
GOL * simu;
if(bool(parser["no_visu"]))
simu = new GOL(dims, 1, true, MPI_COMM_WORLD);
else
simu = new GOL(dims, 1, true, MPI_COMM_WORLD, parser["server"], parser["port"]);
simu->initialState(parser["random"]);
while (true) {
#pragma omp parallel default(shared)
{
#pragma omp single
{ simu->send(); }
int tid = omp_get_thread_num();
simu->determineCells(tid);
#pragma omp single
{
simu->swap();
simu->recv();
}
}
}
simu->send();
simu->getSender().wait();
delete simu;
MPI_Finalize();
return 0;
}

Event Timeline