Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 07ea02fa authored by FELŠÖCI Marek's avatar FELŠÖCI Marek
Browse files

Add support for executing tests from a batch file

parent e6b1fa88
No related branches found
No related tags found
No related merge requests found
...@@ -2,10 +2,19 @@ ...@@ -2,10 +2,19 @@
#include "config.h" #include "config.h"
#include <math.h> #include <math.h>
#include <complex.h> #include <complex.h>
#include <errno.h>
#include "hmat/hmat.h" #include "hmat/hmat.h"
#include "util.h" #include "util.h"
extern char * batch_file; extern char * batch_input;
extern char * batch_output;
extern double computation_time;
extern double ram_usage_peak;
extern double solution_relative_error;
extern hmat_interface_t * interface; extern hmat_interface_t * interface;
...@@ -60,7 +69,10 @@ int displayArray(char *s, void *f, int m, int n) ; ...@@ -60,7 +69,10 @@ int displayArray(char *s, void *f, int m, int n) ;
int testHMAT(double * relative_error); int testHMAT(double * relative_error);
double* createCylinder(void) ; double* createCylinder(void) ;
int printHelp() ; int printHelp() ;
double compression_to_epsilon(const char * compression);
int run_one(); int run_one();
int run_batch();
void reset_meters();
void prepare_hmat(int, int, int, int, int*, int*, int*, int*, void*, hmat_block_info_t *); void prepare_hmat(int, int, int, int, int*, int*, int*, int*, void*, hmat_block_info_t *);
void advanced_compute_hmat(struct hmat_block_compute_context_t*); void advanced_compute_hmat(struct hmat_block_compute_context_t*);
void update_progress(hmat_progress_t * ctx); void update_progress(hmat_progress_t * ctx);
......
#include "main.h" #include "main.h"
char * batch_file = NULL; char * batch_input = NULL;
char * batch_output = NULL;
double computation_time = 0.;
double ram_usage_peak = 0.;
double solution_relative_error = 0.;
hmat_interface_t * interface = NULL; hmat_interface_t * interface = NULL;
double epsilon = 1e-3; double epsilon = 1e-3;
hmat_progress_t progress; hmat_progress_t progress;
...@@ -14,6 +18,90 @@ void update_progress(hmat_progress_t * ctx) { ...@@ -14,6 +18,90 @@ void update_progress(hmat_progress_t * ctx) {
Mpf_progressBar(ctx->current, ctx->max); Mpf_progressBar(ctx->current, ctx->max);
} }
double compression_to_epsilon(const char * compression) {
if(strncmp(compression, "medium", 6) == 0) {
return 1e-6;
} else if(strncmp(compression, "high", 4) == 0) {
return 1e-10;
} else if(strncmp(compression, "disabled", 6) == 0) {
return 1e-16;
}
return 1e-3;
}
void reset_meters() {
computation_time = 0.;
ram_usage_peak = 0.;
solution_relative_error = 0.;
}
int run_batch() {
if(!batch_input) {
SETERRQ(
1,
"Batch file name was not initialized! Did you forget the --batch option?"
);
}
// Open the batch file for reading.
FILE * input = fopen(batch_input, "r"); CHKPTRQ(input);
// Open the output file to save the test results in.
FILE * output = fopen(batch_output, "w"); CHKPTRQ(output);
int c = 0, ierr, ret = 0;
char * compression = (char *) malloc(9); CHKPTRQ(compression);
read:
c = fscanf(input, "%d,%s\n", &nbPts, compression);
if(c == EOF && errno) {
SHWERRM(
1,
"Failed to read the input batch file! Execution cannot continue!"
);
ret = 1;
goto end;
}
if(c == EOF) {
goto end;
}
if(c < 2) {
SHWERRM(
1,
"A syntax error occured while reading the input batch file! "
"Execution cannot continue!"
);
ret = 1;
goto end;
}
epsilon = compression_to_epsilon(compression);
reset_meters();
run_one();
ierr = fprintf(
output, "%d,%s,%f,%f,%e\n",
nbPts, compression, computation_time, ram_usage_peak,
solution_relative_error
);
if(ierr < 0) {
SHWERRM(
1,
"Failed to write the result into the output file! "
"Execution cannot continue!"
);
ret = 1;
goto end;
}
goto read;
end:
fclose(input);
fclose(output);
free(compression);
return ret;
}
int run_one() { int run_one() {
int ierr; int ierr;
...@@ -76,12 +164,23 @@ int main(int argc, char **argv) { ...@@ -76,12 +164,23 @@ int main(int argc, char **argv) {
printf("[minisolver] minisolver version = %s\n", PACKAGE_VERSION); printf("[minisolver] minisolver version = %s\n", PACKAGE_VERSION);
printf("[minisolver] hmat version = %s\n", HMAT_VERSION); printf("[minisolver] hmat version = %s\n", HMAT_VERSION);
if(MpfArgGetString(&argc, argv, 1, "--batch", &batch_file)) { if(MpfArgGetString(&argc, argv, 1, "--batch-input", &batch_input)) {
printf("[minisolver] batch file = %s\n", batch_file); if(!MpfArgGetString(&argc, argv, 1, "--batch-output", &batch_output)) {
printf("Test 1\n"); batch_output = (char *) malloc(12); CHKPTRQ(batch_output);
ierr = run_one(); CHKERRQ(ierr); batch_output = strncpy(batch_output, "results.csv", 11);
printf("Test 2\n"); CHKPTRQ(batch_output);
ierr = run_one(); CHKERRQ(ierr); }
printf("[minisolver] batch input file = %s\n", batch_input);
printf("[minisolver] batch output file = %s\n", batch_output);
printf("[minisolver] runnin test batch ... ");
ierr = run_batch(); CHKERRQ(ierr);
printf("done\n");
free(batch_input);
free(batch_output);
return 0; return 0;
} }
...@@ -91,20 +190,15 @@ int main(int argc, char **argv) { ...@@ -91,20 +190,15 @@ int main(int argc, char **argv) {
char * compression = NULL; char * compression = NULL;
if (MpfArgGetString( &argc, argv, 1, "--compression" , &compression)) { if (MpfArgGetString( &argc, argv, 1, "--compression" , &compression)) {
if(strncmp(compression, "medium", 6) == 0) { epsilon = compression_to_epsilon(compression);
epsilon = 1e-6;
} else if(strncmp(compression, "high", 4) == 0) {
epsilon = 1e-10;
} else if(strncmp(compression, "disabled", 6) == 0) {
epsilon = 1e-16;
}
} else {
compression = strncpy(compression, "low", 3); CHKPTRQ(compression);
} }
printf("[minisolver] compression = %s\n", compression);
printf("[minisolver] compression = %s\n", compression ? compression : "low");
printf("[minisolver] epsilon = %.0e\n", epsilon); printf("[minisolver] epsilon = %.0e\n", epsilon);
free(compression); if(compression) {
free(compression);
}
ierr = run_one(); CHKERRQ(ierr); ierr = run_one(); CHKERRQ(ierr);
......
...@@ -40,6 +40,7 @@ int testHMAT(double * relative_error) { ...@@ -40,6 +40,7 @@ int testHMAT(double * relative_error) {
temps_final = getTime(); temps_final = getTime();
temps_cpu = (temps_final - temps_initial) ; temps_cpu = (temps_final - temps_initial) ;
computation_time += temps_cpu;
printf("[minisolver] factorization time = %f\n", temps_cpu) ; printf("[minisolver] factorization time = %f\n", temps_cpu) ;
/* Solve the system : A-1.solCLA -> solCLA */ /* Solve the system : A-1.solCLA -> solCLA */
...@@ -54,12 +55,14 @@ int testHMAT(double * relative_error) { ...@@ -54,12 +55,14 @@ int testHMAT(double * relative_error) {
printf("done\n"); printf("done\n");
temps_cpu = (temps_final - temps_initial); temps_cpu = (temps_final - temps_initial);
computation_time += temps_cpu;
printf("[minisolver] solve time = %f\n", temps_cpu); printf("[minisolver] solve time = %f\n", temps_cpu);
/* Compare the two vectors solCLA and rhs */ /* Compare the two vectors solCLA and rhs */
printf("[minisolver] computing relative error ... "); printf("[minisolver] computing relative error ... ");
ierr=computeRelativeError(solCLA, rhs, relative_error); CHKERRQ(ierr); ierr=computeRelativeError(solCLA, rhs, relative_error); CHKERRQ(ierr);
solution_relative_error = *relative_error;
printf("done\n"); printf("done\n");
printf("[minisolver] relative error = %.4e\n", *relative_error); printf("[minisolver] relative error = %.4e\n", *relative_error);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment