diff --git a/include/main.h b/include/main.h index a85c4588debf0a598a976f77523846b2345444c5..884debecdf2bd84356e51560e3dc0b1d59483631 100644 --- a/include/main.h +++ b/include/main.h @@ -2,10 +2,19 @@ #include "config.h" #include <math.h> #include <complex.h> +#include <errno.h> #include "hmat/hmat.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; @@ -60,7 +69,10 @@ int displayArray(char *s, void *f, int m, int n) ; int testHMAT(double * relative_error); double* createCylinder(void) ; int printHelp() ; +double compression_to_epsilon(const char * compression); 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 advanced_compute_hmat(struct hmat_block_compute_context_t*); void update_progress(hmat_progress_t * ctx); diff --git a/src/main.c b/src/main.c index fb365902742dbef3d7919e39869cc30a751dd218..b35a8aca71e7a6ca3e089006f1d35bbf786f33c0 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,10 @@ #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; double epsilon = 1e-3; hmat_progress_t progress; @@ -14,6 +18,90 @@ void update_progress(hmat_progress_t * ctx) { 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 ierr; @@ -76,12 +164,23 @@ int main(int argc, char **argv) { printf("[minisolver] minisolver version = %s\n", PACKAGE_VERSION); printf("[minisolver] hmat version = %s\n", HMAT_VERSION); - if(MpfArgGetString(&argc, argv, 1, "--batch", &batch_file)) { - printf("[minisolver] batch file = %s\n", batch_file); - printf("Test 1\n"); - ierr = run_one(); CHKERRQ(ierr); - printf("Test 2\n"); - ierr = run_one(); CHKERRQ(ierr); + if(MpfArgGetString(&argc, argv, 1, "--batch-input", &batch_input)) { + if(!MpfArgGetString(&argc, argv, 1, "--batch-output", &batch_output)) { + batch_output = (char *) malloc(12); CHKPTRQ(batch_output); + batch_output = strncpy(batch_output, "results.csv", 11); + CHKPTRQ(batch_output); + } + + 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; } @@ -91,20 +190,15 @@ int main(int argc, char **argv) { char * compression = NULL; if (MpfArgGetString( &argc, argv, 1, "--compression" , &compression)) { - if(strncmp(compression, "medium", 6) == 0) { - 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); + epsilon = compression_to_epsilon(compression); } - printf("[minisolver] compression = %s\n", compression); + + printf("[minisolver] compression = %s\n", compression ? compression : "low"); printf("[minisolver] epsilon = %.0e\n", epsilon); - free(compression); + if(compression) { + free(compression); + } ierr = run_one(); CHKERRQ(ierr); diff --git a/src/testHMAT.c b/src/testHMAT.c index 78e5237b2db4eb37938a66c3edfa305f2addcaa4..9c8019da0611ea6abdb9f6e07763884b2d64a8f1 100644 --- a/src/testHMAT.c +++ b/src/testHMAT.c @@ -40,6 +40,7 @@ int testHMAT(double * relative_error) { temps_final = getTime(); temps_cpu = (temps_final - temps_initial) ; + computation_time += temps_cpu; printf("[minisolver] factorization time = %f\n", temps_cpu) ; /* Solve the system : A-1.solCLA -> solCLA */ @@ -54,12 +55,14 @@ int testHMAT(double * relative_error) { printf("done\n"); temps_cpu = (temps_final - temps_initial); + computation_time += temps_cpu; printf("[minisolver] solve time = %f\n", temps_cpu); /* Compare the two vectors solCLA and rhs */ printf("[minisolver] computing relative error ... "); ierr=computeRelativeError(solCLA, rhs, relative_error); CHKERRQ(ierr); + solution_relative_error = *relative_error; printf("done\n"); printf("[minisolver] relative error = %.4e\n", *relative_error);