Add profiling and variants

This commit is contained in:
Jan Eitzinger 2023-06-18 13:55:23 +02:00
parent 9c8585c7bc
commit acc831e0b0
6 changed files with 65 additions and 28 deletions

View File

@ -16,7 +16,7 @@ jmax 200 # number of interior cells in y-direction
itermax 10000 # maximal number of pressure iteration in one time step itermax 10000 # maximal number of pressure iteration in one time step
eps 0.000001 # stopping tolerance for pressure iteration eps 0.000001 # stopping tolerance for pressure iteration
# omg 0.9999 # relaxation parameter for SOR iteration rho 0.99999 # relaxation parameter for SOR iteration
omg 1.93 # relaxation parameter for SOR iteration omg 1.998 # relaxation parameter for SOR iteration
#=============================================================================== #===============================================================================

View File

@ -10,31 +10,58 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "likwid-marker.h"
#include "parameter.h" #include "parameter.h"
#include "solver.h" #include "solver.h"
#include "timing.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 main(int argc, char** argv)
{ {
int variant = SOR;
double startTime, endTime; double startTime, endTime;
Parameter params; Parameter params;
Solver solver; Solver solver;
initParameter(&params); initParameter(&params);
LIKWID_MARKER_INIT;
if (argc != 2) { if (argc < 2) {
printf("Usage: %s <configFile>\n", argv[0]); printf("Usage: %s <configFile>\n", argv[0]);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
readParameter(&params, argv[1]); readParameter(&params, argv[1]);
printParameter(&params); printParameter(&params);
if (argc == 3) {
variant = atoi(argv[2]);
}
initSolver(&solver, &params, 2); initSolver(&solver, &params, 2);
startTime = getTimeStamp(); switch (variant) {
solve(&solver); case SOR:
endTime = getTimeStamp(); 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); printf("Solution took %.2fs\n", endTime - startTime);
writeResult(&solver); writeResult(&solver);
LIKWID_MARKER_CLOSE;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -12,7 +12,8 @@
#include "util.h" #include "util.h"
#define MAXLINE 4096 #define MAXLINE 4096
void initParameter(Parameter *param) { void initParameter(Parameter* param)
{
param->xlength = 1.0; param->xlength = 1.0;
param->ylength = 1.0; param->ylength = 1.0;
param->imax = 100; param->imax = 100;
@ -20,33 +21,39 @@ void initParameter(Parameter *param) {
param->itermax = 1000; param->itermax = 1000;
param->eps = 0.0001; param->eps = 0.0001;
param->omg = 1.8; param->omg = 1.8;
param->rho = 0.99;
} }
void readParameter(Parameter *param, const char *filename) { void readParameter(Parameter* param, const char* filename)
FILE *fp = fopen(filename, "r"); {
FILE* fp = fopen(filename, "r");
char line[MAXLINE]; char line[MAXLINE];
int i; int i;
if(!fp) { if (!fp) {
fprintf(stderr, "Could not open parameter file: %s\n", filename); fprintf(stderr, "Could not open parameter file: %s\n", filename);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while(!feof(fp)) { while (!feof(fp)) {
line[0] = '\0'; line[0] = '\0';
fgets(line, MAXLINE, fp); 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'; line[i] = '\0';
char *tok = strtok(line, " "); char* tok = strtok(line, " ");
char *val = strtok(NULL, " "); 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_PARAM(p, f) \
#define PARSE_STRING(p) PARSE_PARAM(p, strdup) if (strncmp(tok, #p, sizeof(#p) / sizeof(#p[0]) - 1) == 0) { \
#define PARSE_INT(p) PARSE_PARAM(p, atoi) param->p = f(val); \
#define PARSE_REAL(p) PARSE_PARAM(p, atof) }
#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(xlength);
PARSE_REAL(ylength); PARSE_REAL(ylength);
PARSE_INT(imax); PARSE_INT(imax);
@ -54,13 +61,15 @@ void readParameter(Parameter *param, const char *filename) {
PARSE_INT(itermax); PARSE_INT(itermax);
PARSE_REAL(eps); PARSE_REAL(eps);
PARSE_REAL(omg); PARSE_REAL(omg);
PARSE_REAL(rho);
} }
} }
fclose(fp); fclose(fp);
} }
void printParameter(Parameter *param) { void printParameter(Parameter* param)
{
printf("Parameters:\n"); printf("Parameters:\n");
printf("Geometry data:\n"); printf("Geometry data:\n");
printf("\tDomain box size (x, y): %e, %e\n", param->xlength, param->ylength); printf("\tDomain box size (x, y): %e, %e\n", param->xlength, param->ylength);

View File

@ -11,7 +11,7 @@ typedef struct {
double xlength, ylength; double xlength, ylength;
int imax, jmax; int imax, jmax;
int itermax; int itermax;
double eps, omg, gamma; double eps, omg, rho, gamma;
} Parameter; } Parameter;
void initParameter(Parameter*); void initParameter(Parameter*);

View File

@ -24,6 +24,7 @@ void initSolver(Solver* solver, Parameter* params, int problem)
solver->dy = params->ylength / params->jmax; solver->dy = params->ylength / params->jmax;
solver->eps = params->eps; solver->eps = params->eps;
solver->omega = params->omg; solver->omega = params->omg;
solver->rho = params->rho;
solver->itermax = params->itermax; solver->itermax = params->itermax;
int imax = solver->imax; int imax = solver->imax;
@ -181,7 +182,7 @@ void solveRBA(Solver* solver)
double idx2 = 1.0 / dx2; double idx2 = 1.0 / dx2;
double idy2 = 1.0 / dy2; double idy2 = 1.0 / dy2;
double factor = 0.5 * (dx2 * dy2) / (dx2 + dy2); double factor = 0.5 * (dx2 * dy2) / (dx2 + dy2);
double rho = solver->omega; double rho = solver->rho;
double* p = solver->p; double* p = solver->p;
double* rhs = solver->rhs; double* rhs = solver->rhs;
double epssq = eps * eps; double epssq = eps * eps;

View File

@ -12,7 +12,7 @@ typedef struct {
double dx, dy; double dx, dy;
int imax, jmax; int imax, jmax;
double *p, *rhs; double *p, *rhs;
double eps, omega; double eps, omega, rho;
int itermax; int itermax;
} Solver; } Solver;