Commit 45b7cb8a authored by Alexandru Dura's avatar Alexandru Dura

WIP: implement the MPI code

parent 24780675
#include <mpi.h>
#include "Field.h"
#include "Util.h"
#include "Problem.h"
void addGates(Field &f, int nGates, double gateSize) {
}
#define DEFAULT_COMM MPI_COMM_WORLD
int main(int argc, char **argv) {
MPI::Init();
int nsize, rank;
MPI_Comm_size(DEFAULT_COMM, &nsize);
MPI_Comm_rank(DEFAULT_COMM, &rank);
int xdim, ydim, maxiter;
double cx, cy;
read_param(&xdim, &ydim, &cx, &cy, &maxiter);
unsigned localXdim = xdim;
unsigned localYdim = ydim / nsize;
double gateVal = 100;
unsigned nGates = 2;
Problem p(nsize, rank, localXdim, localYdim, nGates, nGates, gateVal);
MPI::Finalize();
return 0;
}
#include "Problem.h"
void Problem::init() {
void Problem::initField(Field &f) {
for (int i = 0; i < ydim + 2; ++i) {
for (int j = 0; j < xdim + 2; ++j) {
f0[i][j] = 0;
f[i][j] = 0;
}
}
}
void Problem::addGates(unsigned xGates, unsigned yGates, double value) {
void Problem::addGates(Field &f, unsigned xGates, unsigned yGates, double value) {
const double GATE_WIDTH = 0.1;
if (iField == 0) {
......@@ -18,7 +18,7 @@ void Problem::addGates(unsigned xGates, unsigned yGates, double value) {
unsigned gateStart = gateCentre - 0.5 * GATE_WIDTH * xdim;
unsigned gateEnd = gateCentre + 0.5 * GATE_WIDTH * xdim;
auto row = f0.firstHalo();
auto row = f.firstHalo();
for (unsigned j = gateStart; j < gateEnd; ++j) {
row[j] = value;
......@@ -37,7 +37,7 @@ void Problem::addGates(unsigned xGates, unsigned yGates, double value) {
if (gateStart >= starty && gateStart < endy) {
for (unsigned j = gateStart; j < std::min(gateEnd, endy); j++) {
f0[j - starty + 1][xdim] = value;
f[j - starty + 1][xdim] = value;
}
}
}
......
......@@ -15,8 +15,8 @@ class Problem {
Field *currentf;
Field *nextf;
void init();
void addGates(unsigned xgates, unsigned ygates, double value);
void initField(Field &f);
void addGates(Field &f, unsigned xgates, unsigned ygates, double value);
public:
Problem(unsigned nFields, unsigned iField, unsigned xdim, unsigned ydim,
......@@ -30,8 +30,11 @@ public:
currentf(&f0),
nextf(&f1) {
init();
addGates(xgates, ygates, gateVal);
initField(f0);
initField(f1);
addGates(f0, xgates, ygates, gateVal);
addGates(f1, xgates, ygates, gateVal);
}
void step(double cx, double cy);
......
#pragma once
void read_param(int* pxdim, int* pydim, double* pcx, double* pcy, int* pmaxiter);
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