Add profiling and variants
This commit is contained in:
parent
9c8585c7bc
commit
acc831e0b0
@ -16,7 +16,7 @@ jmax 200 # number of interior cells in y-direction
|
||||
|
||||
itermax 10000 # maximal number of pressure iteration in one time step
|
||||
eps 0.000001 # stopping tolerance for pressure iteration
|
||||
# omg 0.9999 # relaxation parameter for SOR iteration
|
||||
omg 1.93 # relaxation parameter for SOR iteration
|
||||
rho 0.99999 # relaxation parameter for SOR iteration
|
||||
omg 1.998 # relaxation parameter for SOR iteration
|
||||
|
||||
#===============================================================================
|
||||
|
@ -10,31 +10,58 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "likwid-marker.h"
|
||||
#include "parameter.h"
|
||||
#include "solver.h"
|
||||
#include "timing.h"
|
||||
|
||||
#define LIKWID_PROFILE(tag, call) \
|
||||
startTime = getTimeStamp(); \
|
||||
LIKWID_MARKER_START(#tag); \
|
||||
call(&solver); \
|
||||
LIKWID_MARKER_STOP(#tag); \
|
||||
endTime = getTimeStamp();
|
||||
|
||||
enum VARIANT { SOR = 1, RB, RBA };
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int variant = SOR;
|
||||
double startTime, endTime;
|
||||
Parameter params;
|
||||
Solver solver;
|
||||
initParameter(¶ms);
|
||||
LIKWID_MARKER_INIT;
|
||||
|
||||
if (argc != 2) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <configFile>\n", argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
readParameter(¶ms, argv[1]);
|
||||
printParameter(¶ms);
|
||||
if (argc == 3) {
|
||||
variant = atoi(argv[2]);
|
||||
}
|
||||
|
||||
initSolver(&solver, ¶ms, 2);
|
||||
startTime = getTimeStamp();
|
||||
solve(&solver);
|
||||
endTime = getTimeStamp();
|
||||
switch (variant) {
|
||||
case SOR:
|
||||
printf("Plain SOR\n");
|
||||
LIKWID_PROFILE("SOR", solve);
|
||||
break;
|
||||
case RB:
|
||||
printf("Red-black SOR\n");
|
||||
LIKWID_PROFILE("RB", solveRB);
|
||||
break;
|
||||
case RBA:
|
||||
printf("Red-black SOR with acceleration\n");
|
||||
LIKWID_PROFILE("RBA", solveRBA);
|
||||
break;
|
||||
}
|
||||
printf("Solution took %.2fs\n", endTime - startTime);
|
||||
writeResult(&solver);
|
||||
|
||||
LIKWID_MARKER_CLOSE;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -12,41 +12,48 @@
|
||||
#include "util.h"
|
||||
#define MAXLINE 4096
|
||||
|
||||
void initParameter(Parameter *param) {
|
||||
void initParameter(Parameter* param)
|
||||
{
|
||||
param->xlength = 1.0;
|
||||
param->ylength = 1.0;
|
||||
param->imax = 100;
|
||||
param->jmax = 100;
|
||||
param->imax = 100;
|
||||
param->jmax = 100;
|
||||
param->itermax = 1000;
|
||||
param->eps = 0.0001;
|
||||
param->omg = 1.8;
|
||||
param->eps = 0.0001;
|
||||
param->omg = 1.8;
|
||||
param->rho = 0.99;
|
||||
}
|
||||
|
||||
void readParameter(Parameter *param, const char *filename) {
|
||||
FILE *fp = fopen(filename, "r");
|
||||
void readParameter(Parameter* param, const char* filename)
|
||||
{
|
||||
FILE* fp = fopen(filename, "r");
|
||||
char line[MAXLINE];
|
||||
int i;
|
||||
|
||||
if(!fp) {
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Could not open parameter file: %s\n", filename);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while(!feof(fp)) {
|
||||
while (!feof(fp)) {
|
||||
line[0] = '\0';
|
||||
fgets(line, MAXLINE, fp);
|
||||
for(i = 0; line[i] != '\0' && line[i] != '#'; i++);
|
||||
for (i = 0; line[i] != '\0' && line[i] != '#'; i++)
|
||||
;
|
||||
line[i] = '\0';
|
||||
|
||||
char *tok = strtok(line, " ");
|
||||
char *val = strtok(NULL, " ");
|
||||
char* tok = strtok(line, " ");
|
||||
char* val = strtok(NULL, " ");
|
||||
|
||||
#define PARSE_PARAM(p,f) if(strncmp(tok, #p, sizeof(#p) / sizeof(#p[0]) - 1) == 0) { param->p = f(val); }
|
||||
#define PARSE_STRING(p) PARSE_PARAM(p, strdup)
|
||||
#define PARSE_INT(p) PARSE_PARAM(p, atoi)
|
||||
#define PARSE_REAL(p) PARSE_PARAM(p, atof)
|
||||
#define PARSE_PARAM(p, f) \
|
||||
if (strncmp(tok, #p, sizeof(#p) / sizeof(#p[0]) - 1) == 0) { \
|
||||
param->p = f(val); \
|
||||
}
|
||||
#define PARSE_STRING(p) PARSE_PARAM(p, strdup)
|
||||
#define PARSE_INT(p) PARSE_PARAM(p, atoi)
|
||||
#define PARSE_REAL(p) PARSE_PARAM(p, atof)
|
||||
|
||||
if(tok != NULL && val != NULL) {
|
||||
if (tok != NULL && val != NULL) {
|
||||
PARSE_REAL(xlength);
|
||||
PARSE_REAL(ylength);
|
||||
PARSE_INT(imax);
|
||||
@ -54,13 +61,15 @@ void readParameter(Parameter *param, const char *filename) {
|
||||
PARSE_INT(itermax);
|
||||
PARSE_REAL(eps);
|
||||
PARSE_REAL(omg);
|
||||
PARSE_REAL(rho);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void printParameter(Parameter *param) {
|
||||
void printParameter(Parameter* param)
|
||||
{
|
||||
printf("Parameters:\n");
|
||||
printf("Geometry data:\n");
|
||||
printf("\tDomain box size (x, y): %e, %e\n", param->xlength, param->ylength);
|
||||
|
@ -8,10 +8,10 @@
|
||||
#define __PARAMETER_H_
|
||||
|
||||
typedef struct {
|
||||
double xlength, ylength;
|
||||
double xlength, ylength;
|
||||
int imax, jmax;
|
||||
int itermax;
|
||||
double eps, omg, gamma;
|
||||
double eps, omg, rho, gamma;
|
||||
} Parameter;
|
||||
|
||||
void initParameter(Parameter*);
|
||||
|
@ -24,6 +24,7 @@ void initSolver(Solver* solver, Parameter* params, int problem)
|
||||
solver->dy = params->ylength / params->jmax;
|
||||
solver->eps = params->eps;
|
||||
solver->omega = params->omg;
|
||||
solver->rho = params->rho;
|
||||
solver->itermax = params->itermax;
|
||||
|
||||
int imax = solver->imax;
|
||||
@ -181,7 +182,7 @@ void solveRBA(Solver* solver)
|
||||
double idx2 = 1.0 / dx2;
|
||||
double idy2 = 1.0 / dy2;
|
||||
double factor = 0.5 * (dx2 * dy2) / (dx2 + dy2);
|
||||
double rho = solver->omega;
|
||||
double rho = solver->rho;
|
||||
double* p = solver->p;
|
||||
double* rhs = solver->rhs;
|
||||
double epssq = eps * eps;
|
||||
|
@ -12,7 +12,7 @@ typedef struct {
|
||||
double dx, dy;
|
||||
int imax, jmax;
|
||||
double *p, *rhs;
|
||||
double eps, omega;
|
||||
double eps, omega, rho;
|
||||
int itermax;
|
||||
} Solver;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user