Commit 9a5cd392 authored by Alexandru Dura's avatar Alexandru Dura

Initial commit of the project

parent 76150277
// -*-c++-*-
#include <ostream>
class RowView {
double * const row;
RowView(double *row) : row(row) {}
friend class Field;
public:
double &operator[](unsigned i) {
return row[i];
}
double* raw() {
return row;
}
};
class Field {
const unsigned xdim, ydim;
const unsigned m, n;
double *field;
void init() {
field = new double[m * n];
}
public:
Field(int xdim, int ydim) : xdim(xdim), ydim(ydim), m(ydim + 2), n(xdim + 2) {
init();
}
~Field() {
delete[] field;
}
RowView operator[](unsigned i) {
return RowView(field + i * n);
}
RowView firstRow() {
return operator[](1);
}
RowView lastRow() {
return operator[](m-2);
}
RowView firstHalo() {
return operator[](0);
}
RowView lastHalo() {
return operator[](m-1);
}
void print(std::ostream &os) {
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
os << *(field + i * n + j) << " ";
}
os << "\n";
}
}
};
int main(int argc, char **argv) {
return 0;
}
ENTRY_POINTS=Main.cpp Test.cpp
CPP_SOURCE_FILES = $(filter-out $(ENTRY_POINTS), $(wildcard *.cpp))
C_SOURCE_FILES = $(wildcard *.c)
HEADER_FILES = $(wildcard *.h)
CXX=g++
MPICXX=mpic++
CXX_FLAGS=-O3
main : Main.cpp $(CPP_SOURCE_FILES) $(HEADER_FILES)
$(MPICXX) -O3 Main.cpp $(CPP_SOURCE_FILES) -o main
test : Test.cpp $(CPP_SOURCE_FILES) $(HEADER_FILES)
$(CXX) -g -O0 Test.cpp $(CPP_SOURCE_FILES) -o test
clean :
rm *.o
#include "Field.h"
#include <cassert>
#include <iostream>
int main() {
Field f(4, 3);
for (int i = 0; i < 3 + 2; ++i) {
for (int j = 0; j < 4 + 2; ++j) {
f[i][j] = (double) (i + j);
}
}
f.print(std::cout);
for (int i = 0; i < 3 + 2; ++i) {
for (int j = 0; j < 4 + 2; ++j) {
assert(f[i][j] == (double) (i + j));
}
}
return 0;
}
#include <cstdio>
#include <cstdlib>
void read_param(int* pxdim, int* pydim, double* pcx, double* pcy, int* pmaxiter)
{
FILE *fp = fopen( "diffusion.in", "r" );
if ( fp == NULL )
{
fprintf(stderr, "No parameter file: diffusion.in found for reading!\n");
exit(1);
}
// read dimensions of problem
int nb_read = fscanf(fp, "%d %d \n", pxdim, pydim);
if (nb_read != 2)
{
fprintf(stderr, "unable to read xdim and ydim from diffusion.in\n");
exit(1);
}
printf("Read xdim=%d ydim=%d\n", *pxdim, *pydim);
// read cx and cy
nb_read = fscanf(fp, "%lf %lf \n", pcx, pcy);
if (nb_read != 2)
{
fprintf(stderr, "unable to read cx and cy from diffusion.in\n");
exit(1);
}
printf("Read cx=%lf cy=%lf\n", *pcx, *pcy);
// read iteration count
nb_read = fscanf(fp, "%d \n", pmaxiter);
if (nb_read != 1)
{
fprintf(stderr, "unable to read number of iterations from diffusion.in\n");
exit(1);
}
printf("Read maxiter=%d\n", *pmaxiter);
fclose(fp);
}
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