Commit 26c9df1a authored by Alexandru Dura's avatar Alexandru Dura

Add the checkpoint restart feature

parent eb257440
......@@ -74,13 +74,26 @@ void exchangeHalos(int rank, int nsize, Problem &p) {
int main(int argc, char **argv) {
MPI_Init(nullptr, nullptr);
// Process arguments for checkpoint facility
const char *pauseFile = nullptr;
const char *restartFile = nullptr;
for (int i = 1; i < argc; ++i) {
if (!strncmp(argv[i], "-p=", 3)) {
pauseFile = argv[i] + 3;
} else if (!strncmp(argv[i], "-r=", 3)) {
restartFile = argv[i] + 3;
}
}
// Initialize the MPI machinery
MPI_Init(nullptr, nullptr);
int nsize, rank;
MPI_Comm_size(DEFAULT_COMM, &nsize);
MPI_Comm_rank(DEFAULT_COMM, &rank);
// Distribute the problem parameters
GlobalProblemConfig config;
MPI_Datatype GlobalProblemConfig_t;
MPI_Type_create_struct(5, GlobalProblemConfig::block_lengths(), GlobalProblemConfig::displacements(),
......@@ -92,26 +105,50 @@ int main(int argc, char **argv) {
}
MPI_Bcast(&config, 1, GlobalProblemConfig_t, 0, DEFAULT_COMM);
printf("%d: %d, %d\n", rank, config.xdim, config.ydim);
// Set up the local problem
unsigned localXdim = config.xdim;
unsigned localYdim = config.ydim / nsize;
assert(config.ydim % nsize == 0);
int upNeighbour = rank + 1;
int dnNeighbour = rank - 1;
// Hardcoded parameters
double gateVal = 100;
unsigned nGates = 2;
Problem p(nsize, rank, localXdim, localYdim, nGates, nGates, gateVal);
if (restartFile) {
printf("%d: Restarting from file %s\n", rank, restartFile);
MPI_File fh;
int dataSize = p.getField().numCols() * localYdim;
double *data = p.getField().firstRow().raw();
MPI_File_open(DEFAULT_COMM, restartFile, MPI_MODE_RDONLY, MPI_INFO_NULL, &fh);
MPI_File_set_view(fh, rank * dataSize * sizeof(double),
MPI_DOUBLE, MPI_DOUBLE, "native", MPI_INFO_NULL);
MPI_File_read(fh, data, dataSize, MPI_DOUBLE, MPI_STATUS_IGNORE);
MPI_File_close(&fh);
}
// Simulate
for (int i = 0; i < config.maxiter; ++i) {
exchangeHalos(rank, nsize, p);
p.step(config.cx, config.cy);
}
if (pauseFile) {
// Write the problem out, for later restart
MPI_File fh;
int dataSize = p.getField().numCols() * localYdim;
double *data = p.getField().firstRow().raw();
MPI_File_open(DEFAULT_COMM, pauseFile, MPI_MODE_WRONLY | MPI_MODE_CREATE, MPI_INFO_NULL, &fh);
MPI_File_set_view(fh, rank * dataSize * sizeof(double),
MPI_DOUBLE, MPI_DOUBLE, "native", MPI_INFO_NULL);
MPI_File_write(fh, data, dataSize, MPI_DOUBLE, MPI_STATUS_IGNORE);
MPI_File_close(&fh);
printf("%d: Problem written out to file %s\n", rank, pauseFile);
}
// Compute the global min and max
double localMin, localMax;
......
......@@ -35,10 +35,8 @@ void Problem::addGates(Field &f, unsigned xGates, unsigned yGates, double value)
unsigned gateStart = gateCentre - 0.5 * GATE_WIDTH * nFields * ydim;
unsigned gateEnd = gateCentre + 0.5 * GATE_WIDTH * nFields * ydim;
if (gateStart >= starty && gateStart < endy) {
for (unsigned j = gateStart; j < std::min(gateEnd, endy); j++) {
f[j - starty + 1][xdim + 1] = value;
}
for (unsigned j = std::max(gateStart, starty); j < std::min(gateEnd, endy); j++) {
f[j - starty + 1][xdim + 1] = value;
}
}
}
......
......@@ -15,6 +15,10 @@ class Problem {
Field *currentf;
Field *nextf;
unsigned xgates;
unsigned ygates;
double gateVal;
void initField(Field &f);
void addGates(Field &f, unsigned xgates, unsigned ygates, double value);
......@@ -28,13 +32,12 @@ public:
f0(xdim, ydim),
f1(xdim, ydim),
currentf(&f0),
nextf(&f1) {
nextf(&f1), xgates(xgates), ygates(ygates), gateVal(gateVal) {
initField(f0);
initField(f1);
addGates(f0, xgates, ygates, gateVal);
addGates(f1, xgates, ygates, gateVal);
}
void step(double cx, double cy);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment