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[]) {
/* 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) {
......@@ -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,7 +860,8 @@ 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);
......@@ -862,9 +869,11 @@ int main(int argc, char *argv[]) {
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. */
......
......@@ -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.
*
......
......@@ -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
*/
......@@ -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,8 +5459,8 @@ 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,
parser_get_opt_param_string(params, "Statistics:timestep_file_name",
timestepsfileName,
engine_default_timesteps_file_name);
sprintf(timestepsfileName + strlen(timestepsfileName), "_%d.txt",
......@@ -5572,9 +5574,10 @@ 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");
......@@ -5585,7 +5588,7 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par
/* 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,7 +5616,8 @@ 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;
......@@ -5622,8 +5626,7 @@ void engine_config(int restart, struct engine *e, const struct swift_params *par
/* 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;
......
......@@ -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);
......
......@@ -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");
}
......@@ -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");
}
......@@ -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);
......
......@@ -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,7 +1295,8 @@ 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"
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");
}
}
......@@ -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);
......
......@@ -48,7 +48,7 @@
/* Structure for a dumped header. */
struct header {
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) {
/* 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;
......@@ -199,7 +200,8 @@ void restart_read_blocks(void *ptr, size_t size, size_t nblocks, FILE *stream,
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));
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)
......@@ -207,8 +209,7 @@ void restart_read_blocks(void *ptr, size_t size, size_t nblocks, FILE *stream,
errstr, head.len, nblocks * size);
/* Return label, if required. */
if (label != NULL)
strncpy(label, head.label, LABLEN);
if (label != NULL) strncpy(label, head.label, LABLEN);
nread = fread(ptr, size, nblocks, stream);
if (nread != nblocks)
......@@ -242,7 +243,8 @@ void restart_write_blocks(void *ptr, size_t size, size_t nblocks, FILE *stream,
/* 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));
error("Failed to save %s header to restart file (%s)", errstr,
strerror(errno));
nwrite = fwrite(ptr, size, nblocks, stream);
if (nwrite != nblocks)
......
......@@ -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++;
......
......@@ -390,7 +390,6 @@ void space_regrid(struct space *s, int verbose) {
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] ||
......@@ -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) {
......
......@@ -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");
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment