Commit 6d62ad47 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Formatting

parent 45945643
...@@ -472,7 +472,8 @@ int main(int argc, char *argv[]) { ...@@ -472,7 +472,8 @@ int main(int argc, char *argv[]) {
/* Work out where we will read and write restart files. */ /* Work out where we will read and write restart files. */
char restart_dir[PARSER_MAX_LINE_SIZE]; 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. */ /* The directory must exist. */
if (myrank == 0) { if (myrank == 0) {
...@@ -481,9 +482,9 @@ int main(int argc, char *argv[]) { ...@@ -481,9 +482,9 @@ int main(int argc, char *argv[]) {
error("Cannot restart as no restart subdirectory: %s (%s)", restart_dir, error("Cannot restart as no restart subdirectory: %s (%s)", restart_dir,
strerror(errno)); strerror(errno));
} else { } else {
if (mkdir(restart_dir, 0777) != 0) if (mkdir(restart_dir, 0777) != 0)
error("Failed to create restart directory: %s (%s)", restart_dir, error("Failed to create restart directory: %s (%s)", restart_dir,
strerror(errno)); strerror(errno));
} }
} }
} }
...@@ -495,7 +496,8 @@ int main(int argc, char *argv[]) { ...@@ -495,7 +496,8 @@ int main(int argc, char *argv[]) {
/* How often to check for the stop file and dump restarts and exit the /* How often to check for the stop file and dump restarts and exit the
* application. */ * 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 restarting, look for the restart files. */
if (restart) { if (restart) {
...@@ -508,7 +510,8 @@ int main(int argc, char *argv[]) { ...@@ -508,7 +510,8 @@ int main(int argc, char *argv[]) {
message("Restarting SWIFT"); message("Restarting SWIFT");
/* Locate the restart files. */ /* 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) if (restart_nfiles == 0)
error("Failed to locate any restart files in %s", restart_dir); error("Failed to locate any restart files in %s", restart_dir);
...@@ -553,8 +556,8 @@ int main(int argc, char *argv[]) { ...@@ -553,8 +556,8 @@ int main(int argc, char *argv[]) {
/* And initialize the engine with the space and policies. */ /* And initialize the engine with the space and policies. */
if (myrank == 0) clocks_gettime(&tic); if (myrank == 0) clocks_gettime(&tic);
engine_config(1, &e, params, nr_nodes, myrank, nr_threads, with_aff, talking, engine_config(1, &e, params, nr_nodes, myrank, nr_threads, with_aff,
restart_file); talking, restart_file);
if (myrank == 0) { if (myrank == 0) {
clocks_gettime(&toc); clocks_gettime(&toc);
message("engine_config took %.3f %s.", clocks_diff(&tic, &toc), message("engine_config took %.3f %s.", clocks_diff(&tic, &toc),
...@@ -663,7 +666,8 @@ int main(int argc, char *argv[]) { ...@@ -663,7 +666,8 @@ int main(int argc, char *argv[]) {
if (myrank == 0) if (myrank == 0)
message( 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.", "ICs.",
N_total[0], N_total[2], N_total[1]); N_total[0], N_total[2], N_total[1]);
...@@ -680,7 +684,7 @@ int main(int argc, char *argv[]) { ...@@ -680,7 +684,7 @@ int main(int argc, char *argv[]) {
fflush(stdout); 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) #if defined(WITH_MPI)
N_long[0] = s.nr_parts; N_long[0] = s.nr_parts;
N_long[1] = s.nr_gparts; N_long[1] = s.nr_gparts;
...@@ -762,8 +766,8 @@ int main(int argc, char *argv[]) { ...@@ -762,8 +766,8 @@ int main(int argc, char *argv[]) {
talking, &reparttype, &us, &prog_const, &hydro_properties, talking, &reparttype, &us, &prog_const, &hydro_properties,
&gravity_properties, &potential, &cooling_func, &chemistry, &gravity_properties, &potential, &cooling_func, &chemistry,
&sourceterms); &sourceterms);
engine_config(0, &e, params, nr_nodes, myrank, nr_threads, with_aff, talking, engine_config(0, &e, params, nr_nodes, myrank, nr_threads, with_aff,
restart_file); talking, restart_file);
if (myrank == 0) { if (myrank == 0) {
clocks_gettime(&toc); clocks_gettime(&toc);
message("engine_init took %.3f %s.", clocks_diff(&tic, &toc), message("engine_init took %.3f %s.", clocks_diff(&tic, &toc),
...@@ -837,13 +841,15 @@ int main(int argc, char *argv[]) { ...@@ -837,13 +841,15 @@ int main(int argc, char *argv[]) {
if (with_verbose_timers) timers_open_file(myrank); if (with_verbose_timers) timers_open_file(myrank);
/* Create a name for restart file of this rank. */ /* 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"); error("Failed to generate restart filename");
/* Main simulation loop */ /* Main simulation loop */
/* ==================== */ /* ==================== */
int force_stop = 0; 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 */ /* Reset timers */
timers_reset_all(); timers_reset_all();
...@@ -854,17 +860,20 @@ int main(int argc, char *argv[]) { ...@@ -854,17 +860,20 @@ int main(int argc, char *argv[]) {
/* Print the timers. */ /* Print the timers. */
if (with_verbose_timers) timers_print(e.step); 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. */ * files. */
if (j % restart_stop_steps == 0) { if (j % restart_stop_steps == 0) {
force_stop = restart_stop_now(restart_dir, 0); force_stop = restart_stop_now(restart_dir, 0);
if (myrank == 0 && force_stop) if (myrank == 0 && force_stop)
message("Forcing application exit, dumping restart files..."); 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). */ * 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 #ifdef SWIFT_DEBUG_TASKS
/* Dump the task data using the given frequency. */ /* Dump the task data using the given frequency. */
......
...@@ -230,12 +230,9 @@ double clocks_from_ticks(ticks tics) { ...@@ -230,12 +230,9 @@ double clocks_from_ticks(ticks tics) {
* @result the number of ticks, if possible. * @result the number of ticks, if possible.
*/ */
ticks clocks_to_ticks(double ms) { 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. * @brief return the time units.
* *
......
...@@ -4552,7 +4552,6 @@ void engine_dump_restarts(struct engine *e, int drifted_all, int force) { ...@@ -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 * @brief Returns 1 if the simulation has reached its end point, 0 otherwise
*/ */
...@@ -5257,7 +5256,7 @@ void engine_init( ...@@ -5257,7 +5256,7 @@ void engine_init(
* *
* @param restart true when restarting the application. * @param restart true when restarting the application.
* @param e The #engine. * @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 nr_nodes The number of MPI ranks.
* @param nodeID The MPI rank of this node. * @param nodeID The MPI rank of this node.
* @param nr_threads The number of threads per MPI rank. * @param nr_threads The number of threads per MPI rank.
...@@ -5265,8 +5264,9 @@ void engine_init( ...@@ -5265,8 +5264,9 @@ void engine_init(
* @param verbose Is this #engine talkative ? * @param verbose Is this #engine talkative ?
* @param restart_file The name of our restart file. * @param restart_file The name of our restart file.
*/ */
void engine_config(int restart, struct engine *e, const struct swift_params *params, void engine_config(int restart, struct engine *e,
int nr_nodes, int nodeID, int nr_threads, int with_aff, int verbose, const struct swift_params *params, int nr_nodes, int nodeID,
int nr_threads, int with_aff, int verbose,
const char *restart_file) { const char *restart_file) {
/* Store the values and initialise global fields. */ /* Store the values and initialise global fields. */
...@@ -5293,7 +5293,8 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par ...@@ -5293,7 +5293,8 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par
engine_rank = nodeID; engine_rank = nodeID;
/* Get the number of queues */ /* 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 <= 0) nr_queues = e->nr_threads;
if (nr_queues != nr_threads) if (nr_queues != nr_threads)
message("Number of task queues set to %d", nr_queues); 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 ...@@ -5441,7 +5442,8 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par
char energyfileName[200] = ""; char energyfileName[200] = "";
parser_get_opt_param_string(params, "Statistics:energy_file_name", 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"); sprintf(energyfileName + strlen(energyfileName), ".txt");
e->file_stats = fopen(energyfileName, mode); e->file_stats = fopen(energyfileName, mode);
...@@ -5457,9 +5459,9 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par ...@@ -5457,9 +5459,9 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par
} }
char timestepsfileName[200] = ""; char timestepsfileName[200] = "";
parser_get_opt_param_string( parser_get_opt_param_string(params, "Statistics:timestep_file_name",
params, "Statistics:timestep_file_name", timestepsfileName, timestepsfileName,
engine_default_timesteps_file_name); engine_default_timesteps_file_name);
sprintf(timestepsfileName + strlen(timestepsfileName), "_%d.txt", sprintf(timestepsfileName + strlen(timestepsfileName), "_%d.txt",
nr_nodes * nr_threads); nr_nodes * nr_threads);
...@@ -5572,20 +5574,21 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par ...@@ -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); e->restart_onexit = parser_get_opt_param_int(params, "Restarts:onexit", 0);
/* Hours between restart dumps. Can be changed on restart. */ /* 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->nodeID == 0) {
if(e->restart_dump) if (e->restart_dump)
message("Restarts will be dumped every %f hours", dhours); message("Restarts will be dumped every %f hours", dhours);
else else
message("WARNING: restarts will not be dumped"); 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"); message("Restarts will be dumped after the final step");
} }
/* Internally we use ticks, so convert into a delta ticks. Assumes we can /* Internally we use ticks, so convert into a delta ticks. Assumes we can
* convert from ticks into milliseconds. */ * 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 /* The first dump will happen no sooner than restart_dt ticks in the
* future. */ * future. */
...@@ -5613,17 +5616,17 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par ...@@ -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 * 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. * 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; int maxtasks = 0;
if (restart) if (restart)
maxtasks = e->restart_max_tasks; maxtasks = e->restart_max_tasks;
else else
maxtasks = engine_estimate_nr_tasks(e); maxtasks = engine_estimate_nr_tasks(e);
/* Init the scheduler. */ /* Init the scheduler. */
scheduler_init(&e->sched, e->s, maxtasks, nr_queues, scheduler_init(&e->sched, e->s, maxtasks, nr_queues,
(e->policy & scheduler_flag_steal), e->nodeID, (e->policy & scheduler_flag_steal), e->nodeID, &e->threadpool);
&e->threadpool);
/* Maximum size of MPI task messages, in KB, that should not be buffered, /* 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 * 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) { ...@@ -5796,7 +5799,8 @@ void engine_struct_dump(struct engine *e, FILE *stream) {
/* Dump the engine. Save the current tasks_per_cell estimate. */ /* Dump the engine. Save the current tasks_per_cell estimate. */
e->restart_max_tasks = engine_estimate_nr_tasks(e); 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. */ /* And all the engine pointed data, these use their own dump functions. */
space_struct_dump(e->s, stream); space_struct_dump(e->s, stream);
...@@ -5828,7 +5832,8 @@ void engine_struct_dump(struct engine *e, FILE *stream) { ...@@ -5828,7 +5832,8 @@ void engine_struct_dump(struct engine *e, FILE *stream) {
void engine_struct_restore(struct engine *e, FILE *stream) { void engine_struct_restore(struct engine *e, FILE *stream) {
/* Read the engine. */ /* 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. */ /* Re-initializations as necessary for our struct and its members. */
e->sched.tasks = NULL; e->sched.tasks = NULL;
......
...@@ -330,8 +330,9 @@ void engine_init( ...@@ -330,8 +330,9 @@ void engine_init(
const struct external_potential *potential, const struct external_potential *potential,
const struct cooling_function_data *cooling_func, const struct cooling_function_data *cooling_func,
const struct chemistry_data *chemistry, struct sourceterms *sourceterms); const struct chemistry_data *chemistry, struct sourceterms *sourceterms);
void engine_config(int restart, struct engine *e, const struct swift_params *params, void engine_config(int restart, struct engine *e,
int nr_nodes, int nodeID, int nr_threads, int with_aff, int verbose, const struct swift_params *params, int nr_nodes, int nodeID,
int nr_threads, int with_aff, int verbose,
const char *restart_file); const char *restart_file);
void engine_launch(struct engine *e); void engine_launch(struct engine *e);
void engine_prepare(struct engine *e); void engine_prepare(struct engine *e);
......
...@@ -116,6 +116,6 @@ void gravity_props_struct_dump(const struct gravity_props *p, FILE *stream) { ...@@ -116,6 +116,6 @@ void gravity_props_struct_dump(const struct gravity_props *p, FILE *stream) {
* @param stream the file stream * @param stream the file stream
*/ */
void gravity_props_struct_restore(const struct gravity_props *p, 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, restart_read_blocks((void *)p, sizeof(struct gravity_props), 1, stream, NULL,
NULL, "gravity props"); "gravity props");
} }
...@@ -147,6 +147,6 @@ void hydro_props_struct_dump(const struct hydro_props *p, FILE *stream) { ...@@ -147,6 +147,6 @@ void hydro_props_struct_dump(const struct hydro_props *p, FILE *stream) {
* @param stream the file stream * @param stream the file stream
*/ */
void hydro_props_struct_restore(const struct hydro_props *p, 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, restart_read_blocks((void *)p, sizeof(struct hydro_props), 1, stream, NULL,
NULL, "hydro props"); "hydro props");
} }
...@@ -1157,7 +1157,8 @@ void write_output_parallel(struct engine* e, const char* baseName, ...@@ -1157,7 +1157,8 @@ void write_output_parallel(struct engine* e, const char* baseName,
#endif #endif
/* Write LXMF file descriptor */ /* 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 #ifdef IO_SPEED_MEASUREMENT
MPI_Barrier(MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD);
......
...@@ -1259,7 +1259,7 @@ int partition_space_to_space(double *oldh, double *oldcdim, int *oldnodeIDs, ...@@ -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 * @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 s the space with the top-level cells.
* @param reparttype struct to update with the a list of nodeIDs. * @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) { ...@@ -1284,7 +1284,8 @@ void partition_store_celllist(struct space *s, struct repartition *reparttype) {
* @param reparttype struct with the list of nodeIDs saved, * @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 > 0) {
if (reparttype->ncelllist == s->nr_cells) { if (reparttype->ncelllist == s->nr_cells) {
for (int i = 0; i < s->nr_cells; i++) { for (int i = 0; i < s->nr_cells; i++) {
...@@ -1294,9 +1295,10 @@ void partition_restore_celllist(struct space *s, struct repartition *reparttype) ...@@ -1294,9 +1295,10 @@ void partition_restore_celllist(struct space *s, struct repartition *reparttype)
error("Not all ranks are present in the restored partition"); error("Not all ranks are present in the restored partition");
} }
} else { } else {
error("Cannot apply the saved partition celllist as the number of" error(
"top-level cells (%d) is different to the saved number (%d)", "Cannot apply the saved partition celllist as the number of"
s->nr_cells, reparttype->ncelllist); "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) { ...@@ -1326,15 +1328,15 @@ void partition_struct_dump(struct repartition *reparttype, FILE *stream) {
* @param stream the file stream * @param stream the file stream
*/ */
void partition_struct_restore(struct repartition *reparttype, FILE *stream) { void partition_struct_restore(struct repartition *reparttype, FILE *stream) {
restart_read_blocks(reparttype, sizeof(struct repartition), 1, stream, restart_read_blocks(reparttype, sizeof(struct repartition), 1, stream, NULL,
NULL, "repartition params"); "repartition params");
/* Also restore the celllist, if we have one. */ /* Also restore the celllist, if we have one. */
if (reparttype->ncelllist > 0) { if (reparttype->ncelllist > 0) {
reparttype->celllist = malloc(sizeof(int) * reparttype->ncelllist); reparttype->celllist = malloc(sizeof(int) * reparttype->ncelllist);
if (reparttype->celllist == NULL) error("Failed to allocate celllist"); if (reparttype->celllist == NULL) error("Failed to allocate celllist");
restart_read_blocks(reparttype->celllist, restart_read_blocks(reparttype->celllist,
sizeof(int) * reparttype->ncelllist, 1, stream, sizeof(int) * reparttype->ncelllist, 1, stream, NULL,
NULL, "repartition celllist"); "repartition celllist");
} }
} }
...@@ -80,7 +80,8 @@ void partition_init(struct partition *partition, ...@@ -80,7 +80,8 @@ void partition_init(struct partition *partition,
/* Dump/restore. */ /* Dump/restore. */
void partition_store_celllist(struct space *s, struct repartition *reparttype); 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_dump(struct repartition *reparttype, FILE *stream);
void partition_struct_restore(struct repartition *reparttype, FILE *stream); void partition_struct_restore(struct repartition *reparttype, FILE *stream);
......
...@@ -47,8 +47,8 @@ ...@@ -47,8 +47,8 @@
/* Structure for a dumped header. */ /* Structure for a dumped header. */
struct header { struct header {
size_t len; /* Total length of data in bytes. */ size_t len; /* Total length of data in bytes. */
char label[LABLEN+1]; /* A label for data */ char label[LABLEN + 1]; /* A label for data */
}; };
/** /**
...@@ -85,7 +85,8 @@ char **restart_locate(const char *dir, const char *basename, int *nfiles) { ...@@ -85,7 +85,8 @@ char **restart_locate(const char *dir, const char *basename, int *nfiles) {
/* Construct the glob pattern for locating files. */ /* Construct the glob pattern for locating files. */
char pattern[FNAMELEN]; 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; glob_t globbuf;
char **files = NULL; char **files = NULL;
...@@ -196,24 +197,24 @@ void restart_read(struct engine *e, const char *filename) { ...@@ -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, void restart_read_blocks(void *ptr, size_t size, size_t nblocks, FILE *stream,
char *label, const char *errstr) { char *label, const char *errstr) {
if (size > 0) { if (size > 0) {
struct header head; struct header head;
size_t nread = fread(&head, sizeof(struct header), 1, stream); size_t nread = fread(&head, sizeof(struct header), 1, stream);
if (nread != 1) if (nread != 1)
error("Failed to read the %s header from restart file (%s)", errstr, strerror(errno)); 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) /* Check that the stored length is the same as the expected one. */
error("Mismatched data length in restart file for %s (%zu != %zu)", if (head.len != nblocks * size)
errstr, 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) /* Return label, if required. */
strncpy(label, head.label, LABLEN); if (label != NULL) strncpy(label, head.label, LABLEN);
nread = fread(ptr, size, nblocks, stream); nread = fread(ptr, size, nblocks, stream);
if (nread != nblocks) if (nread != nblocks)
error("Failed to restore %s from restart file (%s)", errstr, error("Failed to restore %s from restart file (%s)", errstr,
ferror(stream) ? strerror(errno) : "unexpected end of file"); 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, ...@@ -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, void restart_write_blocks(void *ptr, size_t size, size_t nblocks, FILE *stream,
const char *label, const char *errstr) { const char *label, const char *errstr) {
if (size > 0) { if (size > 0) {