Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
a35351c4
Commit
a35351c4
authored
Apr 29, 2016
by
Matthieu Schaller
Browse files
Added a function to the engine to dump a snapshot.
parent
03b87256
Changes
3
Hide whitespace changes
Inline
Side-by-side
examples/main.c
View file @
a35351c4
...
...
@@ -422,30 +422,10 @@ int main(int argc, char *argv[]) {
fflush
(
stdout
);
}
int
with_outputs
=
1
;
/* Write the state of the system before starting time integration. */
char
baseName
[
200
];
parser_get_param_string
(
params
,
"Snapshots:basename"
,
baseName
);
if
(
with_outputs
&&
!
dry_run
)
{
/* Write the state of the system before starting time integration. */
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
#if defined(WITH_MPI)
#if defined(HAVE_PARALLEL_HDF5)
write_output_parallel
(
&
e
,
baseName
,
&
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
MPI_INFO_NULL
);
#else
write_output_serial
(
&
e
,
baseName
,
&
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
MPI_INFO_NULL
);
#endif
#else
write_output_single
(
&
e
,
baseName
,
&
us
);
#endif
if
(
myrank
==
0
&&
verbose
)
{
clocks_gettime
(
&
toc
);
message
(
"writing particle properties took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
),
clocks_getunit
());
fflush
(
stdout
);
}
}
if
(
!
dry_run
)
engine_dump_snapshot
(
&
e
,
&
us
,
baseName
);
/* Now that everything is ready, no need for the parameters any more */
free
(
params
);
...
...
@@ -507,27 +487,8 @@ int main(int argc, char *argv[]) {
/* Take a step. */
engine_step
(
&
e
);
if
(
with_outputs
&&
j
%
10
==
0
)
{
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
#if defined(WITH_MPI)
#if defined(HAVE_PARALLEL_HDF5)
write_output_parallel
(
&
e
,
&
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
MPI_INFO_NULL
);
#else
write_output_serial
(
&
e
,
&
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
MPI_INFO_NULL
);
#endif
#else
write_output_single
(
&
e
,
baseName
,
&
us
);
#endif
if
(
myrank
==
0
&&
verbose
)
{
clocks_gettime
(
&
toc
);
message
(
"writing particle properties took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
),
clocks_getunit
());
fflush
(
stdout
);
}
}
/* Snapshot if need be */
if
(
j
%
10
==
0
)
engine_dump_snapshot
(
&
e
,
&
us
,
baseName
);
/* Dump the task data using the given frequency. */
if
(
dump_tasks
&&
(
dump_tasks
==
1
||
j
%
dump_tasks
==
1
))
{
...
...
@@ -610,28 +571,8 @@ int main(int argc, char *argv[]) {
(
double
)
runner_hist_bins
[
k
]);
#endif
if
(
with_outputs
)
{
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
/* Write final output. */
#if defined(WITH_MPI)
#if defined(HAVE_PARALLEL_HDF5)
write_output_parallel
(
&
e
,
&
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
MPI_INFO_NULL
);
#else
write_output_serial
(
&
e
,
&
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
MPI_INFO_NULL
);
#endif
#else
write_output_single
(
&
e
,
baseName
,
&
us
);
#endif
if
(
myrank
==
0
&&
verbose
)
{
clocks_gettime
(
&
toc
);
message
(
"writing particle properties took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
),
clocks_getunit
());
fflush
(
stdout
);
}
}
/* Write final output. */
engine_dump_snapshot
(
&
e
,
&
us
,
baseName
);
#ifdef WITH_MPI
if
((
res
=
MPI_Finalize
())
!=
MPI_SUCCESS
)
...
...
src/engine.c
View file @
a35351c4
...
...
@@ -58,6 +58,9 @@
#include
"minmax.h"
#include
"part.h"
#include
"partition.h"
#include
"parallel_io.h"
#include
"serial_io.h"
#include
"single_io.h"
#include
"timers.h"
const
char
*
engine_policy_names
[
13
]
=
{
...
...
@@ -2324,6 +2327,37 @@ void engine_split(struct engine *e, struct partition *initial_partition) {
#endif
}
/**
* @brief Writes a snapshot with the current state of the engine
*
* @param e The #engine.
* @param us The unit system to use for the snapshots.
* @param baseName The common part of the snapshot file names.
*/
void
engine_dump_snapshot
(
struct
engine
*
e
,
struct
UnitSystem
*
us
,
const
char
*
baseName
)
{
struct
clocks_time
time1
,
time2
;
clocks_gettime
(
&
time1
);
#if defined(WITH_MPI)
#if defined(HAVE_PARALLEL_HDF5)
write_output_parallel
(
e
,
baseName
,
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
MPI_INFO_NULL
);
#else
write_output_serial
(
e
,
baseName
,
us
,
myrank
,
nr_nodes
,
MPI_COMM_WORLD
,
MPI_INFO_NULL
);
#endif
#else
write_output_single
(
e
,
baseName
,
us
);
#endif
clocks_gettime
(
&
time2
);
if
(
e
->
verbose
)
message
(
"writing particle properties took %.3f %s."
,
(
float
)
clocks_diff
(
&
time1
,
&
time2
),
clocks_getunit
());
}
#if defined(HAVE_LIBNUMA) && defined(_GNU_SOURCE)
static
bool
hyperthreads_present
(
void
)
{
#ifdef __linux__
...
...
src/engine.h
View file @
a35351c4
...
...
@@ -185,6 +185,8 @@ struct engine {
/* Function prototypes. */
void
engine_barrier
(
struct
engine
*
e
,
int
tid
);
void
engine_dump_snapshot
(
struct
engine
*
e
,
struct
UnitSystem
*
us
,
const
char
*
baseName
);
void
engine_init
(
struct
engine
*
e
,
struct
space
*
s
,
const
struct
swift_params
*
params
,
int
nr_nodes
,
int
nodeID
,
int
nr_threads
,
int
policy
,
int
verbose
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment