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
5f3aaa92
Commit
5f3aaa92
authored
9 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Free the memory required by the parameter file when done with it.
parent
ff7d0dd0
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!140
First version of main() using a parameter file to get constants.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/main.c
+14
-9
14 additions, 9 deletions
examples/main.c
with
14 additions
and
9 deletions
examples/main.c
+
14
−
9
View file @
5f3aaa92
...
...
@@ -237,21 +237,22 @@ int main(int argc, char *argv[]) {
const
int
talking
=
(
verbose
==
1
&&
myrank
==
0
)
||
(
verbose
==
2
);
/* Read the parameter file */
struct
swift_params
params
;
struct
swift_params
*
params
=
malloc
(
sizeof
(
struct
swift_params
));
if
(
params
==
NULL
)
error
(
"Error allocating memory for the parameter file."
);
if
(
myrank
==
0
)
{
message
(
"Reading parameters from file '%s'"
,
paramFileName
);
parser_read_file
(
paramFileName
,
&
params
);
parser_read_file
(
paramFileName
,
params
);
// parser_print_params(¶ms);
parser_write_params_to_file
(
&
params
,
"used_parameters.yml"
);
parser_write_params_to_file
(
params
,
"used_parameters.yml"
);
}
#ifdef WITH_MPI
/* Broadcast the parameter file */
MPI_Bcast
(
&
params
,
sizeof
(
struct
swift_params
),
MPI_BYTE
,
0
,
MPI_COMM_WORLD
);
MPI_Bcast
(
params
,
sizeof
(
struct
swift_params
),
MPI_BYTE
,
0
,
MPI_COMM_WORLD
);
#endif
/* Initialize unit system */
struct
UnitSystem
us
;
units_init
(
&
us
,
&
params
);
units_init
(
&
us
,
params
);
if
(
myrank
==
0
)
{
message
(
"Unit system: U_M = %e g."
,
us
.
UnitMass_in_cgs
);
message
(
"Unit system: U_L = %e cm."
,
us
.
UnitLength_in_cgs
);
...
...
@@ -264,7 +265,7 @@ int main(int argc, char *argv[]) {
#ifdef WITH_MPI
struct
partition
initial_partition
;
enum
repartition_type
reparttype
;
partition_init
(
&
initial_partition
,
&
reparttype
,
&
params
,
nr_nodes
);
partition_init
(
&
initial_partition
,
&
reparttype
,
params
,
nr_nodes
);
/* Let's report what we did */
if
(
myrank
==
0
)
{
...
...
@@ -279,7 +280,7 @@ int main(int argc, char *argv[]) {
/* Read particles and space information from (GADGET) ICs */
char
ICfileName
[
200
]
=
""
;
parser_get_param_string
(
&
params
,
"InitialConditions:file_name"
,
ICfileName
);
parser_get_param_string
(
params
,
"InitialConditions:file_name"
,
ICfileName
);
if
(
myrank
==
0
)
message
(
"Reading ICs from file '%s'"
,
ICfileName
);
struct
part
*
parts
=
NULL
;
struct
gpart
*
gparts
=
NULL
;
...
...
@@ -331,7 +332,7 @@ int main(int argc, char *argv[]) {
/* Initialize the space with these data. */
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
struct
space
s
;
space_init
(
&
s
,
&
params
,
dim
,
parts
,
gparts
,
Ngas
,
Ngpart
,
periodic
,
talking
,
space_init
(
&
s
,
params
,
dim
,
parts
,
gparts
,
Ngas
,
Ngpart
,
periodic
,
talking
,
dry_run
);
if
(
myrank
==
0
)
{
clocks_gettime
(
&
toc
);
...
...
@@ -376,7 +377,7 @@ int main(int argc, char *argv[]) {
/* Initialize the engine with the space and policies. */
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
struct
engine
e
;
engine_init
(
&
e
,
&
s
,
&
params
,
nr_nodes
,
myrank
,
engine_policies
,
talking
);
engine_init
(
&
e
,
&
s
,
params
,
nr_nodes
,
myrank
,
engine_policies
,
talking
);
if
(
myrank
==
0
)
{
clocks_gettime
(
&
toc
);
message
(
"engine_init took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
),
...
...
@@ -384,6 +385,10 @@ int main(int argc, char *argv[]) {
fflush
(
stdout
);
}
/* Now that everything is ready, no need for the parameters any more */
free
(
params
);
params
=
NULL
;
int
with_outputs
=
1
;
if
(
with_outputs
&&
!
dry_run
)
{
/* Write the state of the system before starting time integration. */
...
...
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