Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
dabb3049
Commit
dabb3049
authored
9 years ago
by
James Willis
Browse files
Options
Downloads
Patches
Plain Diff
Added standalone parameter that is not found under a section.
parent
19817e8e
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!140
First version of main() using a parameter file to get constants.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/testParser.c
+11
-7
11 additions, 7 deletions
tests/testParser.c
tests/testParserInput.yaml
+16
-6
16 additions, 6 deletions
tests/testParserInput.yaml
with
27 additions
and
13 deletions
tests/testParser.c
+
11
−
7
View file @
dabb3049
...
@@ -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
.
0
f
;
float
max_h
=
0
.
0
f
;
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
;
}
}
This diff is collapsed.
Click to expand it.
tests/testParserInput.yaml
+
16
−
6
View file @
dabb3049
---
---
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment