Skip to content
GitLab
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
6d62ad47
Commit
6d62ad47
authored
Jan 29, 2018
by
Peter W. Draper
Browse files
Formatting
parent
45945643
Changes
13
Hide whitespace changes
Inline
Side-by-side
examples/main.c
View file @
6d62ad47
...
...
@@ -472,7 +472,8 @@ int main(int argc, char *argv[]) {
/* Work out where we will read and write restart files. */
char
restart_dir
[
PARSER_MAX_LINE_SIZE
];
parser_get_opt_param_string
(
params
,
"Restarts:subdir"
,
restart_dir
,
"restart"
);
parser_get_opt_param_string
(
params
,
"Restarts:subdir"
,
restart_dir
,
"restart"
);
/* The directory must exist. */
if
(
myrank
==
0
)
{
...
...
@@ -481,9 +482,9 @@ int main(int argc, char *argv[]) {
error
(
"Cannot restart as no restart subdirectory: %s (%s)"
,
restart_dir
,
strerror
(
errno
));
}
else
{
if
(
mkdir
(
restart_dir
,
0777
)
!=
0
)
error
(
"Failed to create restart directory: %s (%s)"
,
restart_dir
,
strerror
(
errno
));
if
(
mkdir
(
restart_dir
,
0777
)
!=
0
)
error
(
"Failed to create restart directory: %s (%s)"
,
restart_dir
,
strerror
(
errno
));
}
}
}
...
...
@@ -495,7 +496,8 @@ int main(int argc, char *argv[]) {
/* How often to check for the stop file and dump restarts and exit the
* application. */
int
restart_stop_steps
=
parser_get_opt_param_int
(
params
,
"Restarts:stop_steps"
,
100
);
int
restart_stop_steps
=
parser_get_opt_param_int
(
params
,
"Restarts:stop_steps"
,
100
);
/* If restarting, look for the restart files. */
if
(
restart
)
{
...
...
@@ -508,7 +510,8 @@ int main(int argc, char *argv[]) {
message
(
"Restarting SWIFT"
);
/* Locate the restart files. */
restart_files
=
restart_locate
(
restart_dir
,
restart_name
,
&
restart_nfiles
);
restart_files
=
restart_locate
(
restart_dir
,
restart_name
,
&
restart_nfiles
);
if
(
restart_nfiles
==
0
)
error
(
"Failed to locate any restart files in %s"
,
restart_dir
);
...
...
@@ -553,8 +556,8 @@ int main(int argc, char *argv[]) {
/* And initialize the engine with the space and policies. */
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
engine_config
(
1
,
&
e
,
params
,
nr_nodes
,
myrank
,
nr_threads
,
with_aff
,
talking
,
restart_file
);
engine_config
(
1
,
&
e
,
params
,
nr_nodes
,
myrank
,
nr_threads
,
with_aff
,
talking
,
restart_file
);
if
(
myrank
==
0
)
{
clocks_gettime
(
&
toc
);
message
(
"engine_config took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
),
...
...
@@ -663,7 +666,8 @@ int main(int argc, char *argv[]) {
if
(
myrank
==
0
)
message
(
"Read %lld gas particles, %lld star particles and %lld gparts from the "
"Read %lld gas particles, %lld star particles and %lld gparts from "
"the "
"ICs."
,
N_total
[
0
],
N_total
[
2
],
N_total
[
1
]);
...
...
@@ -680,7 +684,7 @@ int main(int argc, char *argv[]) {
fflush
(
stdout
);
}
/* Also update the total counts (in case of changes due to replication) */
/* Also update the total counts (in case of changes due to replication) */
#if defined(WITH_MPI)
N_long
[
0
]
=
s
.
nr_parts
;
N_long
[
1
]
=
s
.
nr_gparts
;
...
...
@@ -762,8 +766,8 @@ int main(int argc, char *argv[]) {
talking
,
&
reparttype
,
&
us
,
&
prog_const
,
&
hydro_properties
,
&
gravity_properties
,
&
potential
,
&
cooling_func
,
&
chemistry
,
&
sourceterms
);
engine_config
(
0
,
&
e
,
params
,
nr_nodes
,
myrank
,
nr_threads
,
with_aff
,
talking
,
restart_file
);
engine_config
(
0
,
&
e
,
params
,
nr_nodes
,
myrank
,
nr_threads
,
with_aff
,
talking
,
restart_file
);
if
(
myrank
==
0
)
{
clocks_gettime
(
&
toc
);
message
(
"engine_init took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
),
...
...
@@ -837,13 +841,15 @@ int main(int argc, char *argv[]) {
if
(
with_verbose_timers
)
timers_open_file
(
myrank
);
/* Create a name for restart file of this rank. */
if
(
restart_genname
(
restart_dir
,
restart_name
,
e
.
nodeID
,
restart_file
,
200
)
!=
0
)
if
(
restart_genname
(
restart_dir
,
restart_name
,
e
.
nodeID
,
restart_file
,
200
)
!=
0
)
error
(
"Failed to generate restart filename"
);
/* Main simulation loop */
/* ==================== */
int
force_stop
=
0
;
for
(
int
j
=
0
;
!
engine_is_done
(
&
e
)
&&
e
.
step
-
1
!=
nsteps
&&
!
force_stop
;
j
++
)
{
for
(
int
j
=
0
;
!
engine_is_done
(
&
e
)
&&
e
.
step
-
1
!=
nsteps
&&
!
force_stop
;
j
++
)
{
/* Reset timers */
timers_reset_all
();
...
...
@@ -854,17 +860,20 @@ int main(int argc, char *argv[]) {
/* Print the timers. */
if
(
with_verbose_timers
)
timers_print
(
e
.
step
);
/* Every so often allow the user to stop the application and dump the restart
/* Every so often allow the user to stop the application and dump the
* restart
* files. */
if
(
j
%
restart_stop_steps
==
0
)
{
force_stop
=
restart_stop_now
(
restart_dir
,
0
);
if
(
myrank
==
0
&&
force_stop
)
message
(
"Forcing application exit, dumping restart files..."
);
force_stop
=
restart_stop_now
(
restart_dir
,
0
);
if
(
myrank
==
0
&&
force_stop
)
message
(
"Forcing application exit, dumping restart files..."
);
}
/* Also if using nsteps to exit, will not have saved any restarts on exit, make
/* Also if using nsteps to exit, will not have saved any restarts on exit,
* make
* sure we do that (useful in testing only). */
if
(
force_stop
||
(
e
.
restart_onexit
&&
e
.
step
-
1
==
nsteps
))
engine_dump_restarts
(
&
e
,
0
,
1
);
if
(
force_stop
||
(
e
.
restart_onexit
&&
e
.
step
-
1
==
nsteps
))
engine_dump_restarts
(
&
e
,
0
,
1
);
#ifdef SWIFT_DEBUG_TASKS
/* Dump the task data using the given frequency. */
...
...
src/clocks.c
View file @
6d62ad47
...
...
@@ -230,12 +230,9 @@ double clocks_from_ticks(ticks tics) {
* @result the number of ticks, if possible.
*/
ticks
clocks_to_ticks
(
double
ms
)
{
return
(
ticks
)
(
ms
*
(
double
)
clocks_get_cpufreq
()
/
clocks_units_scale
);
return
(
ticks
)(
ms
*
(
double
)
clocks_get_cpufreq
()
/
clocks_units_scale
);
}
ticks
clocks_to_ticks
(
double
interval
);
/**
* @brief return the time units.
*
...
...
src/engine.c
View file @
6d62ad47
...
...
@@ -4552,7 +4552,6 @@ void engine_dump_restarts(struct engine *e, int drifted_all, int force) {
}
}
/**
* @brief Returns 1 if the simulation has reached its end point, 0 otherwise
*/
...
...
@@ -5257,7 +5256,7 @@ void engine_init(
*
* @param restart true when restarting the application.
* @param e The #engine.
* @param params The parsed parameter file.
* @param params The parsed parameter file.
* @param nr_nodes The number of MPI ranks.
* @param nodeID The MPI rank of this node.
* @param nr_threads The number of threads per MPI rank.
...
...
@@ -5265,8 +5264,9 @@ void engine_init(
* @param verbose Is this #engine talkative ?
* @param restart_file The name of our restart file.
*/
void
engine_config
(
int
restart
,
struct
engine
*
e
,
const
struct
swift_params
*
params
,
int
nr_nodes
,
int
nodeID
,
int
nr_threads
,
int
with_aff
,
int
verbose
,
void
engine_config
(
int
restart
,
struct
engine
*
e
,
const
struct
swift_params
*
params
,
int
nr_nodes
,
int
nodeID
,
int
nr_threads
,
int
with_aff
,
int
verbose
,
const
char
*
restart_file
)
{
/* Store the values and initialise global fields. */
...
...
@@ -5293,7 +5293,8 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par
engine_rank
=
nodeID
;
/* Get the number of queues */
int
nr_queues
=
parser_get_opt_param_int
(
params
,
"Scheduler:nr_queues"
,
nr_threads
);
int
nr_queues
=
parser_get_opt_param_int
(
params
,
"Scheduler:nr_queues"
,
nr_threads
);
if
(
nr_queues
<=
0
)
nr_queues
=
e
->
nr_threads
;
if
(
nr_queues
!=
nr_threads
)
message
(
"Number of task queues set to %d"
,
nr_queues
);
...
...
@@ -5441,7 +5442,8 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par
char
energyfileName
[
200
]
=
""
;
parser_get_opt_param_string
(
params
,
"Statistics:energy_file_name"
,
energyfileName
,
engine_default_energy_file_name
);
energyfileName
,
engine_default_energy_file_name
);
sprintf
(
energyfileName
+
strlen
(
energyfileName
),
".txt"
);
e
->
file_stats
=
fopen
(
energyfileName
,
mode
);
...
...
@@ -5457,9 +5459,9 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par
}
char
timestepsfileName
[
200
]
=
""
;
parser_get_opt_param_string
(
params
,
"Statistics:timestep_file_name"
,
timestepsfileName
,
engine_default_timesteps_file_name
);
parser_get_opt_param_string
(
params
,
"Statistics:timestep_file_name"
,
timestepsfileName
,
engine_default_timesteps_file_name
);
sprintf
(
timestepsfileName
+
strlen
(
timestepsfileName
),
"_%d.txt"
,
nr_nodes
*
nr_threads
);
...
...
@@ -5572,20 +5574,21 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par
e
->
restart_onexit
=
parser_get_opt_param_int
(
params
,
"Restarts:onexit"
,
0
);
/* Hours between restart dumps. Can be changed on restart. */
float
dhours
=
parser_get_opt_param_float
(
params
,
"Restarts:delta_hours"
,
6
.
0
);
float
dhours
=
parser_get_opt_param_float
(
params
,
"Restarts:delta_hours"
,
6
.
0
);
if
(
e
->
nodeID
==
0
)
{
if
(
e
->
restart_dump
)
if
(
e
->
restart_dump
)
message
(
"Restarts will be dumped every %f hours"
,
dhours
);
else
message
(
"WARNING: restarts will not be dumped"
);
if
(
e
->
verbose
&&
e
->
restart_onexit
)
if
(
e
->
verbose
&&
e
->
restart_onexit
)
message
(
"Restarts will be dumped after the final step"
);
}
/* Internally we use ticks, so convert into a delta ticks. Assumes we can
* convert from ticks into milliseconds. */
e
->
restart_dt
=
clocks_to_ticks
(
dhours
*
60
.
0
*
60
.
0
*
1000
.
0
);
e
->
restart_dt
=
clocks_to_ticks
(
dhours
*
60
.
0
*
60
.
0
*
1000
.
0
);
/* The first dump will happen no sooner than restart_dt ticks in the
* future. */
...
...
@@ -5613,17 +5616,17 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par
* On restart this number cannot be estimated (no cells yet), so we recover
* from the end of the dumped run. Can be changed on restart.
*/
e
->
tasks_per_cell
=
parser_get_opt_param_int
(
params
,
"Scheduler:tasks_per_cell"
,
0
);
e
->
tasks_per_cell
=
parser_get_opt_param_int
(
params
,
"Scheduler:tasks_per_cell"
,
0
);
int
maxtasks
=
0
;
if
(
restart
)
maxtasks
=
e
->
restart_max_tasks
;
maxtasks
=
e
->
restart_max_tasks
;
else
maxtasks
=
engine_estimate_nr_tasks
(
e
);
maxtasks
=
engine_estimate_nr_tasks
(
e
);
/* Init the scheduler. */
scheduler_init
(
&
e
->
sched
,
e
->
s
,
maxtasks
,
nr_queues
,
(
e
->
policy
&
scheduler_flag_steal
),
e
->
nodeID
,
&
e
->
threadpool
);
(
e
->
policy
&
scheduler_flag_steal
),
e
->
nodeID
,
&
e
->
threadpool
);
/* Maximum size of MPI task messages, in KB, that should not be buffered,
* that is sent using MPI_Issend, not MPI_Isend. 4Mb by default. Can be
...
...
@@ -5796,7 +5799,8 @@ void engine_struct_dump(struct engine *e, FILE *stream) {
/* Dump the engine. Save the current tasks_per_cell estimate. */
e
->
restart_max_tasks
=
engine_estimate_nr_tasks
(
e
);
restart_write_blocks
(
e
,
sizeof
(
struct
engine
),
1
,
stream
,
"engine"
,
"engine struct"
);
restart_write_blocks
(
e
,
sizeof
(
struct
engine
),
1
,
stream
,
"engine"
,
"engine struct"
);
/* And all the engine pointed data, these use their own dump functions. */
space_struct_dump
(
e
->
s
,
stream
);
...
...
@@ -5828,7 +5832,8 @@ void engine_struct_dump(struct engine *e, FILE *stream) {
void
engine_struct_restore
(
struct
engine
*
e
,
FILE
*
stream
)
{
/* Read the engine. */
restart_read_blocks
(
e
,
sizeof
(
struct
engine
),
1
,
stream
,
NULL
,
"engine struct"
);
restart_read_blocks
(
e
,
sizeof
(
struct
engine
),
1
,
stream
,
NULL
,
"engine struct"
);
/* Re-initializations as necessary for our struct and its members. */
e
->
sched
.
tasks
=
NULL
;
...
...
src/engine.h
View file @
6d62ad47
...
...
@@ -330,8 +330,9 @@ void engine_init(
const
struct
external_potential
*
potential
,
const
struct
cooling_function_data
*
cooling_func
,
const
struct
chemistry_data
*
chemistry
,
struct
sourceterms
*
sourceterms
);
void
engine_config
(
int
restart
,
struct
engine
*
e
,
const
struct
swift_params
*
params
,
int
nr_nodes
,
int
nodeID
,
int
nr_threads
,
int
with_aff
,
int
verbose
,
void
engine_config
(
int
restart
,
struct
engine
*
e
,
const
struct
swift_params
*
params
,
int
nr_nodes
,
int
nodeID
,
int
nr_threads
,
int
with_aff
,
int
verbose
,
const
char
*
restart_file
);
void
engine_launch
(
struct
engine
*
e
);
void
engine_prepare
(
struct
engine
*
e
);
...
...
src/gravity_properties.c
View file @
6d62ad47
...
...
@@ -116,6 +116,6 @@ void gravity_props_struct_dump(const struct gravity_props *p, FILE *stream) {
* @param stream the file stream
*/
void
gravity_props_struct_restore
(
const
struct
gravity_props
*
p
,
FILE
*
stream
)
{
restart_read_blocks
((
void
*
)
p
,
sizeof
(
struct
gravity_props
),
1
,
stream
,
NULL
,
"gravity props"
);
restart_read_blocks
((
void
*
)
p
,
sizeof
(
struct
gravity_props
),
1
,
stream
,
NULL
,
"gravity props"
);
}
src/hydro_properties.c
View file @
6d62ad47
...
...
@@ -147,6 +147,6 @@ void hydro_props_struct_dump(const struct hydro_props *p, FILE *stream) {
* @param stream the file stream
*/
void
hydro_props_struct_restore
(
const
struct
hydro_props
*
p
,
FILE
*
stream
)
{
restart_read_blocks
((
void
*
)
p
,
sizeof
(
struct
hydro_props
),
1
,
stream
,
NULL
,
"hydro props"
);
restart_read_blocks
((
void
*
)
p
,
sizeof
(
struct
hydro_props
),
1
,
stream
,
NULL
,
"hydro props"
);
}
src/parallel_io.c
View file @
6d62ad47
...
...
@@ -1157,7 +1157,8 @@ void write_output_parallel(struct engine* e, const char* baseName,
#endif
/* Write LXMF file descriptor */
if
(
mpi_rank
==
0
)
xmf_write_outputfooter
(
xmfFile
,
e
->
snapshotOutputCount
,
e
->
time
);
if
(
mpi_rank
==
0
)
xmf_write_outputfooter
(
xmfFile
,
e
->
snapshotOutputCount
,
e
->
time
);
#ifdef IO_SPEED_MEASUREMENT
MPI_Barrier
(
MPI_COMM_WORLD
);
...
...
src/partition.c
View file @
6d62ad47
...
...
@@ -1259,7 +1259,7 @@ int partition_space_to_space(double *oldh, double *oldcdim, int *oldnodeIDs,
/**
* @brief save the nodeIDs of the current top-level cells by adding them to a
* repartition struct. Used when restarting application.
* repartition struct. Used when restarting application.
*
* @param s the space with the top-level cells.
* @param reparttype struct to update with the a list of nodeIDs.
...
...
@@ -1284,7 +1284,8 @@ void partition_store_celllist(struct space *s, struct repartition *reparttype) {
* @param reparttype struct with the list of nodeIDs saved,
*
*/
void
partition_restore_celllist
(
struct
space
*
s
,
struct
repartition
*
reparttype
)
{
void
partition_restore_celllist
(
struct
space
*
s
,
struct
repartition
*
reparttype
)
{
if
(
reparttype
->
ncelllist
>
0
)
{
if
(
reparttype
->
ncelllist
==
s
->
nr_cells
)
{
for
(
int
i
=
0
;
i
<
s
->
nr_cells
;
i
++
)
{
...
...
@@ -1294,9 +1295,10 @@ void partition_restore_celllist(struct space *s, struct repartition *reparttype)
error
(
"Not all ranks are present in the restored partition"
);
}
}
else
{
error
(
"Cannot apply the saved partition celllist as the number of"
"top-level cells (%d) is different to the saved number (%d)"
,
s
->
nr_cells
,
reparttype
->
ncelllist
);
error
(
"Cannot apply the saved partition celllist as the number of"
"top-level cells (%d) is different to the saved number (%d)"
,
s
->
nr_cells
,
reparttype
->
ncelllist
);
}
}
}
...
...
@@ -1326,15 +1328,15 @@ void partition_struct_dump(struct repartition *reparttype, FILE *stream) {
* @param stream the file stream
*/
void
partition_struct_restore
(
struct
repartition
*
reparttype
,
FILE
*
stream
)
{
restart_read_blocks
(
reparttype
,
sizeof
(
struct
repartition
),
1
,
stream
,
NULL
,
"repartition params"
);
restart_read_blocks
(
reparttype
,
sizeof
(
struct
repartition
),
1
,
stream
,
NULL
,
"repartition params"
);
/* Also restore the celllist, if we have one. */
if
(
reparttype
->
ncelllist
>
0
)
{
reparttype
->
celllist
=
malloc
(
sizeof
(
int
)
*
reparttype
->
ncelllist
);
if
(
reparttype
->
celllist
==
NULL
)
error
(
"Failed to allocate celllist"
);
restart_read_blocks
(
reparttype
->
celllist
,
sizeof
(
int
)
*
reparttype
->
ncelllist
,
1
,
stream
,
NULL
,
"repartition celllist"
);
sizeof
(
int
)
*
reparttype
->
ncelllist
,
1
,
stream
,
NULL
,
"repartition celllist"
);
}
}
src/partition.h
View file @
6d62ad47
...
...
@@ -80,7 +80,8 @@ void partition_init(struct partition *partition,
/* Dump/restore. */
void
partition_store_celllist
(
struct
space
*
s
,
struct
repartition
*
reparttype
);
void
partition_restore_celllist
(
struct
space
*
s
,
struct
repartition
*
reparttype
);
void
partition_restore_celllist
(
struct
space
*
s
,
struct
repartition
*
reparttype
);
void
partition_struct_dump
(
struct
repartition
*
reparttype
,
FILE
*
stream
);
void
partition_struct_restore
(
struct
repartition
*
reparttype
,
FILE
*
stream
);
...
...
src/restart.c
View file @
6d62ad47
...
...
@@ -47,8 +47,8 @@
/* Structure for a dumped header. */
struct
header
{
size_t
len
;
/* Total length of data in bytes. */
char
label
[
LABLEN
+
1
];
/* A label for data */
size_t
len
;
/* Total length of data in bytes. */
char
label
[
LABLEN
+
1
];
/* A label for data */
};
/**
...
...
@@ -85,7 +85,8 @@ char **restart_locate(const char *dir, const char *basename, int *nfiles) {
/* Construct the glob pattern for locating files. */
char
pattern
[
FNAMELEN
];
if
(
snprintf
(
pattern
,
FNAMELEN
,
"%s/%s_[0-9]*.rst"
,
dir
,
basename
)
<
FNAMELEN
)
{
if
(
snprintf
(
pattern
,
FNAMELEN
,
"%s/%s_[0-9]*.rst"
,
dir
,
basename
)
<
FNAMELEN
)
{
glob_t
globbuf
;
char
**
files
=
NULL
;
...
...
@@ -196,24 +197,24 @@ void restart_read(struct engine *e, const char *filename) {
void
restart_read_blocks
(
void
*
ptr
,
size_t
size
,
size_t
nblocks
,
FILE
*
stream
,
char
*
label
,
const
char
*
errstr
)
{
if
(
size
>
0
)
{
struct
header
head
;
size_t
nread
=
fread
(
&
head
,
sizeof
(
struct
header
),
1
,
stream
);
if
(
nread
!=
1
)
error
(
"Failed to read the %s header from restart file (%s)"
,
errstr
,
strerror
(
errno
));
/* Check that the stored length is the same as the expected one. */
if
(
head
.
len
!=
nblocks
*
size
)
error
(
"Mismatched data length in restart file for %s (%zu != %zu)"
,
errstr
,
head
.
len
,
nblocks
*
size
);
/* Return label, if required. */
if
(
label
!=
NULL
)
strncpy
(
label
,
head
.
label
,
LABLEN
);
nread
=
fread
(
ptr
,
size
,
nblocks
,
stream
);
if
(
nread
!=
nblocks
)
error
(
"Failed to restore %s from restart file (%s)"
,
errstr
,
ferror
(
stream
)
?
strerror
(
errno
)
:
"unexpected end of file"
);
struct
header
head
;
size_t
nread
=
fread
(
&
head
,
sizeof
(
struct
header
),
1
,
stream
);
if
(
nread
!=
1
)
error
(
"Failed to read the %s header from restart file (%s)"
,
errstr
,
strerror
(
errno
));
/* Check that the stored length is the same as the expected one. */
if
(
head
.
len
!=
nblocks
*
size
)
error
(
"Mismatched data length in restart file for %s (%zu != %zu)"
,
errstr
,
head
.
len
,
nblocks
*
size
);
/* Return label, if required. */
if
(
label
!=
NULL
)
strncpy
(
label
,
head
.
label
,
LABLEN
);
nread
=
fread
(
ptr
,
size
,
nblocks
,
stream
);
if
(
nread
!=
nblocks
)
error
(
"Failed to restore %s from restart file (%s)"
,
errstr
,
ferror
(
stream
)
?
strerror
(
errno
)
:
"unexpected end of file"
);
}
}
...
...
@@ -231,23 +232,24 @@ void restart_read_blocks(void *ptr, size_t size, size_t nblocks, FILE *stream,
*/
void
restart_write_blocks
(
void
*
ptr
,
size_t
size
,
size_t
nblocks
,
FILE
*
stream
,
const
char
*
label
,
const
char
*
errstr
)
{
if
(
size
>
0
)
{
/* Add a preamble header. */
struct
header
head
;
head
.
len
=
nblocks
*
size
;
strncpy
(
head
.
label
,
label
,
LABLEN
);
head
.
label
[
LABLEN
]
=
'\0'
;
/* Now dump it and the data. */
size_t
nwrite
=
fwrite
(
&
head
,
sizeof
(
struct
header
),
1
,
stream
);
if
(
nwrite
!=
1
)
error
(
"Failed to save %s header to restart file (%s)"
,
errstr
,
strerror
(
errno
));
nwrite
=
fwrite
(
ptr
,
size
,
nblocks
,
stream
);
if
(
nwrite
!=
nblocks
)
error
(
"Failed to save %s to restart file (%s)"
,
errstr
,
strerror
(
errno
));
}
if
(
size
>
0
)
{
/* Add a preamble header. */
struct
header
head
;
head
.
len
=
nblocks
*
size
;
strncpy
(
head
.
label
,
label
,
LABLEN
);
head
.
label
[
LABLEN
]
=
'\0'
;
/* Now dump it and the data. */
size_t
nwrite
=
fwrite
(
&
head
,
sizeof
(
struct
header
),
1
,
stream
);
if
(
nwrite
!=
1
)
error
(
"Failed to save %s header to restart file (%s)"
,
errstr
,
strerror
(
errno
));
nwrite
=
fwrite
(
ptr
,
size
,
nblocks
,
stream
);
if
(
nwrite
!=
nblocks
)
error
(
"Failed to save %s to restart file (%s)"
,
errstr
,
strerror
(
errno
));
}
}
/**
...
...
@@ -266,11 +268,11 @@ int restart_stop_now(const char *dir, int cleanup) {
strcpy
(
filename
,
dir
);
strcat
(
filename
,
"/stop"
);
if
(
stat
(
filename
,
&
buf
)
==
0
)
{
if
(
cleanup
&&
unlink
(
filename
)
!=
0
)
{
/* May not be fatal, so press on. */
message
(
"Failed to delete restart stop file (%s)"
,
strerror
(
errno
));
}
return
1
;
if
(
cleanup
&&
unlink
(
filename
)
!=
0
)
{
/* May not be fatal, so press on. */
message
(
"Failed to delete restart stop file (%s)"
,
strerror
(
errno
));
}
return
1
;
}
return
0
;
}
src/serial_io.c
View file @
6d62ad47
...
...
@@ -1001,7 +1001,8 @@ void write_output_serial(struct engine* e, const char* baseName,
}
/* Write footer of LXMF file descriptor */
if
(
mpi_rank
==
0
)
xmf_write_outputfooter
(
xmfFile
,
e
->
snapshotOutputCount
,
e
->
time
);
if
(
mpi_rank
==
0
)
xmf_write_outputfooter
(
xmfFile
,
e
->
snapshotOutputCount
,
e
->
time
);
/* message("Done writing particles..."); */
e
->
snapshotOutputCount
++
;
...
...
src/space.c
View file @
6d62ad47
...
...
@@ -385,12 +385,11 @@ void space_regrid(struct space *s, int verbose) {
}
}
/* Are we about to allocate new top level cells without a regrid?
/* Are we about to allocate new top level cells without a regrid?
* Can happen when restarting the application. */
int
no_regrid
=
(
s
->
cells_top
==
NULL
&&
oldnodeIDs
==
NULL
);
#endif
/* Do we need to re-build the upper-level cells? */
// tic = getticks();
if
(
s
->
cells_top
==
NULL
||
cdim
[
0
]
<
s
->
cdim
[
0
]
||
cdim
[
1
]
<
s
->
cdim
[
1
]
||
...
...
@@ -520,19 +519,19 @@ void space_regrid(struct space *s, int verbose) {
free
(
oldnodeIDs
);
}
else
if
(
no_regrid
&&
s
->
e
!=
NULL
)
{
/* If we have created the top-levels cells and not done an initial
* partition (can happen when restarting), then the top-level cells
* are not assigned to a node, we must do that and then associate the
* particles with the cells. Note requires that
* partition_store_celllist() was called once before, or just before
* dumping the restart files.*/
partition_restore_celllist
(
s
,
s
->
e
->
reparttype
);
/* Now re-distribute the particles, should just add to cells? */
engine_redistribute
(
s
->
e
);
/* Make the proxies. */
engine_makeproxies
(
s
->
e
);
/* If we have created the top-levels cells and not done an initial
* partition (can happen when restarting), then the top-level cells
* are not assigned to a node, we must do that and then associate the
* particles with the cells. Note requires that
* partition_store_celllist() was called once before, or just before
* dumping the restart files.*/
partition_restore_celllist
(
s
,
s
->
e
->
reparttype
);
/* Now re-distribute the particles, should just add to cells? */
engine_redistribute
(
s
->
e
);
/* Make the proxies. */
engine_makeproxies
(
s
->
e
);
}
#endif
/* WITH_MPI */
...
...
@@ -3249,7 +3248,8 @@ void space_clean(struct space *s) {
*/
void
space_struct_dump
(
struct
space
*
s
,
FILE
*
stream
)
{
restart_write_blocks
(
s
,
sizeof
(
struct
space
),
1
,
stream
,
"space"
,
"space struct"
);
restart_write_blocks
(
s
,
sizeof
(
struct
space
),
1
,
stream
,
"space"
,
"space struct"
);
/* More things to write. */
if
(
s
->
nr_parts
>
0
)
{
...
...
src/units.c
View file @
6d62ad47
...
...
@@ -622,6 +622,6 @@ void units_struct_dump(const struct unit_system* us, FILE* stream) {
* @param stream the file stream
*/
void
units_struct_restore
(
const
struct
unit_system
*
us
,
FILE
*
stream
)
{
restart_read_blocks
((
void
*
)
us
,
sizeof
(
struct
unit_system
),
1
,
stream
,
NULL
,
"units"
);
restart_read_blocks
((
void
*
)
us
,
sizeof
(
struct
unit_system
),
1
,
stream
,
NULL
,
"units"
);
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment