Skip to content
Snippets Groups Projects
Commit dabb3049 authored by James Willis's avatar James Willis
Browse files

Added standalone parameter that is not found under a section.

parent 19817e8e
Branches
Tags
1 merge request!140First version of main() using a parameter file to get constants.
...@@ -32,6 +32,7 @@ int main(int argc, char *argv[]) { ...@@ -32,6 +32,7 @@ int main(int argc, char *argv[]) {
/* Create variables that will be set from the parameter file. */ /* Create variables that will be set from the parameter file. */
int no_of_threads = 0; int no_of_threads = 0;
int no_of_time_steps = 0; int no_of_time_steps = 0;
int kernel = 0;
float max_h = 0.0f; float max_h = 0.0f;
double start_time = 0.0; double start_time = 0.0;
char ic_file [PARSER_MAX_LINE_SIZE]; char ic_file [PARSER_MAX_LINE_SIZE];
...@@ -48,20 +49,23 @@ int main(int argc, char *argv[]) { ...@@ -48,20 +49,23 @@ int main(int argc, char *argv[]) {
/* Retrieve parameters and store them in variables defined above. /* Retrieve parameters and store them in variables defined above.
* Have to specify the name of the parameter as it appears in the * Have to specify the name of the parameter as it appears in the
* input file: testParserInput.yaml.*/ * input file: testParserInput.yaml.*/
parser_get_param_int(&param_file,"no_of_threads",&no_of_threads); parser_get_param_int(&param_file,"Scheduler:no_of_threads",&no_of_threads);
parser_get_param_int(&param_file,"no_of_time_steps",&no_of_time_steps); parser_get_param_int(&param_file,"Simulation:no_of_time_steps",&no_of_time_steps);
parser_get_param_float(&param_file,"max_h",&max_h); parser_get_param_float(&param_file,"Simulation:max_h",&max_h);
parser_get_param_double(&param_file,"start_time",&start_time); parser_get_param_double(&param_file,"Simulation:start_time",&start_time);
parser_get_param_string(&param_file,"ic_file",ic_file); parser_get_param_string(&param_file,"IO:ic_file",ic_file);
parser_get_param_int(&param_file,"kernel",&kernel);
/* Print the variables to check their values are correct. */ /* Print the variables to check their values are correct. */
printf("no_of_threads: %d, no_of_time_steps: %d, max_h: %f, start_time: %lf, ic_file: %s\n",no_of_threads, no_of_time_steps, max_h, start_time, ic_file); printf("no_of_threads: %d, no_of_time_steps: %d, max_h: %f, start_time: %lf, ic_file: %s, kernel: %d\n",no_of_threads, no_of_time_steps, max_h, start_time, ic_file, kernel);
assert(no_of_threads == 16); assert(no_of_threads == 16);
assert(no_of_time_steps == 10); assert(no_of_time_steps == 10);
assert(fabs(max_h - 1.1255) < 0.00001); assert(fabs(max_h - 1.1255) < 0.00001);
assert(fabs(start_time - 1.23456789) < 0.00001); assert(fabs(start_time - 1.23456789) < 0.00001);
assert(strcmp(ic_file,"ic_file.ini") == 0); /*strcmp returns 0 if correct.*/ assert(strcmp(ic_file,"ic_file.ini") == 0); /*strcmp returns 0 if correct.*/
assert(kernel == 4);
return 0; return 0;
} }
--- ---
no_of_threads: 16 # The number of threads that will be used. #section_1:
no_of_time_steps: 10 # var_a: 4.5e10
max_h: 1.1255 # var_b: Hello World!
start_time: 1.23456789
#Input file
ic_file: ic_file.ini
kernel: 4
Scheduler:
no_of_threads: 16 # The number of threads that will be used.
Simulation:
no_of_time_steps: 10
max_h: 1.1255
start_time: 1.23456789
IO:
#Input file
ic_file: ic_file.ini
... ...
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment