diff --git a/README b/README index 2dedb32a04a7cf143c3e65560c45a68c0e5d1c2a..3425a5952897b14ba0853ead66ce40ca89c24154 100644 --- a/README +++ b/README @@ -15,28 +15,30 @@ Usage: swift [OPTION]... PARAMFILE swift_mpi [OPTION]... PARAMFILE Valid options are: - -a Pin runners using processor affinity. - -c Run with cosmological time integration. - -C Run with cooling. - -d Dry run. Read the parameter file, allocate memory but does not read - the particles from ICs and exit before the start of time integration. - Allows user to check validy of parameter and IC files as well as memory limits. - -D Always drift all particles even the ones far from active particles. This emulates - Gadget-[23] and GIZMO's default behaviours. - -e Enable floating-point exceptions (debugging mode). - -f {int} Overwrite the CPU frequency (Hz) to be used for time measurements. - -g Run with an external gravitational potential. - -G Run with self-gravity. - -M Reconstruct the multipoles every time-step. - -n {int} Execute a fixed number of time steps. When unset use the time_end parameter to stop. - -s Run with hydrodynamics. - -S Run with stars. - -t {int} The number of threads to use on each MPI rank. Defaults to 1 if not specified. - -T Print timers every time-step. - -v [12] Increase the level of verbosity - 1: MPI-rank 0 writes - 2: All MPI-ranks write - -y {int} Time-step frequency at which task graphs are dumped. - -h Print this help message and exit. + -a Pin runners using processor affinity. + -c Run with cosmological time integration. + -C Run with cooling. + -d Dry run. Read the parameter file, allocate memory but does not read + the particles from ICs and exit before the start of time integration. + Allows user to check validy of parameter and IC files as well as memory limits. + -D Always drift all particles even the ones far from active particles. This emulates + Gadget-[23] and GIZMO's default behaviours. + -e Enable floating-point exceptions (debugging mode). + -f {int} Overwrite the CPU frequency (Hz) to be used for time measurements. + -g Run with an external gravitational potential. + -G Run with self-gravity. + -M Reconstruct the multipoles every time-step. + -n {int} Execute a fixed number of time steps. When unset use the time_end parameter to stop. + -P {sec:par:val} Set parameter value and overwrites values read from the parameters file. Can be used more than once. + -s Run with hydrodynamics. + -S Run with stars. + -t {int} The number of threads to use on each MPI rank. Defaults to 1 if not specified. + -T Print timers every time-step. + -v [12] Increase the level of verbosity: + 1: MPI-rank 0 writes, + 2: All MPI-ranks write. + -y {int} Time-step frequency at which task graphs are dumped. + -h Print this help message and exit. + +See the file parameter_example.yml for an example of parameter file. -See the file examples/parameter_example.yml for an example of parameter file. diff --git a/examples/main.c b/examples/main.c index 631117148addd3ab7ad49ed2760855b793757870..ad28d16c25024f07f1f8d3433bc35c14fa24a426 100644 --- a/examples/main.c +++ b/examples/main.c @@ -57,48 +57,51 @@ void print_help_message() { printf(" swift_mpi [OPTION]... PARAMFILE\n\n"); printf("Valid options are:\n"); - printf(" %2s %8s %s\n", "-a", "", "Pin runners using processor affinity."); - printf(" %2s %8s %s\n", "-c", "", "Run with cosmological time integration."); - printf(" %2s %8s %s\n", "-C", "", "Run with cooling."); + printf(" %2s %14s %s\n", "-a", "", "Pin runners using processor affinity."); + printf(" %2s %14s %s\n", "-c", "", + "Run with cosmological time integration."); + printf(" %2s %14s %s\n", "-C", "", "Run with cooling."); printf( - " %2s %8s %s\n", "-d", "", + " %2s %14s %s\n", "-d", "", "Dry run. Read the parameter file, allocate memory but does not read "); printf( - " %2s %8s %s\n", "", "", + " %2s %14s %s\n", "", "", "the particles from ICs and exit before the start of time integration."); - printf(" %2s %8s %s\n", "", "", + printf(" %2s %14s %s\n", "", "", "Allows user to check validy of parameter and IC files as well as " "memory limits."); - printf(" %2s %8s %s\n", "-D", "", + printf(" %2s %14s %s\n", "-D", "", "Always drift all particles even the ones far from active particles. " "This emulates"); - printf(" %2s %8s %s\n", "", "", + printf(" %2s %14s %s\n", "", "", "Gadget-[23] and GIZMO's default behaviours."); - printf(" %2s %8s %s\n", "-e", "", + printf(" %2s %14s %s\n", "-e", "", "Enable floating-point exceptions (debugging mode)."); - printf(" %2s %8s %s\n", "-f", "{int}", + printf(" %2s %14s %s\n", "-f", "{int}", "Overwrite the CPU frequency (Hz) to be used for time measurements."); - printf(" %2s %8s %s\n", "-g", "", + printf(" %2s %14s %s\n", "-g", "", "Run with an external gravitational potential."); - printf(" %2s %8s %s\n", "-F", "", "Run with feedback."); - printf(" %2s %8s %s\n", "-G", "", "Run with self-gravity."); - printf(" %2s %8s %s\n", "-M", "", + printf(" %2s %14s %s\n", "-G", "", "Run with self-gravity."); + printf(" %2s %14s %s\n", "-M", "", "Reconstruct the multipoles every time-step."); - printf(" %2s %8s %s\n", "-n", "{int}", + printf(" %2s %14s %s\n", "-n", "{int}", "Execute a fixed number of time steps. When unset use the time_end " "parameter to stop."); - printf(" %2s %8s %s\n", "-s", "", "Run with hydrodynamics."); - printf(" %2s %8s %s\n", "-S", "", "Run with stars."); - printf(" %2s %8s %s\n", "-t", "{int}", + printf(" %2s %14s %s\n", "-P", "{sec:par:val}", + "Set parameter value and overwrites values read from the parameters " + "file. Can be used more than once."); + printf(" %2s %14s %s\n", "-s", "", "Run with hydrodynamics."); + printf(" %2s %14s %s\n", "-S", "", "Run with stars."); + printf(" %2s %14s %s\n", "-t", "{int}", "The number of threads to use on each MPI rank. Defaults to 1 if not " "specified."); - printf(" %2s %8s %s\n", "-T", "", "Print timers every time-step."); - printf(" %2s %8s %s\n", "-v", "[12]", "Increase the level of verbosity."); - printf(" %2s %8s %s\n", "", "", "1: MPI-rank 0 writes "); - printf(" %2s %8s %s\n", "", "", "2: All MPI-ranks write"); - printf(" %2s %8s %s\n", "-y", "{int}", + printf(" %2s %14s %s\n", "-T", "", "Print timers every time-step."); + printf(" %2s %14s %s\n", "-v", "[12]", "Increase the level of verbosity:"); + printf(" %2s %14s %s\n", "", "", "1: MPI-rank 0 writes,"); + printf(" %2s %14s %s\n", "", "", "2: All MPI-ranks write."); + printf(" %2s %14s %s\n", "-y", "{int}", "Time-step frequency at which task graphs are dumped."); - printf(" %2s %8s %s\n", "-h", "", "Print this help message and exit."); + printf(" %2s %14s %s\n", "-h", "", "Print this help message and exit."); printf( "\nSee the file parameter_example.yml for an example of " "parameter file.\n"); @@ -170,12 +173,14 @@ int main(int argc, char *argv[]) { int verbose = 0; int nr_threads = 1; int with_verbose_timers = 0; + int nparams = 0; + char *cmdparams[PARSER_MAX_NO_OF_PARAMS]; char paramFileName[200] = ""; unsigned long long cpufreq = 0; /* Parse the parameters */ int c; - while ((c = getopt(argc, argv, "acCdDef:FgGhMn:sSt:Tv:y:")) != -1) + while ((c = getopt(argc, argv, "acCdDef:FgGhMn:P:sSt:Tv:y:")) != -1) switch (c) { case 'a': with_aff = 1; @@ -224,6 +229,10 @@ int main(int argc, char *argv[]) { return 1; } break; + case 'P': + cmdparams[nparams] = optarg; + nparams++; + break; case 's': with_hydro = 1; break; @@ -351,6 +360,12 @@ int main(int argc, char *argv[]) { if (myrank == 0) { message("Reading runtime parameters from file '%s'", paramFileName); parser_read_file(paramFileName, params); + + /* Handle any command-line overrides. */ + if (nparams > 0) + for (int k = 0; k < nparams; k++) parser_set_param(params, cmdparams[k]); + + /* And dump the parameters as used. */ // parser_print_params(¶ms); parser_write_params_to_file(params, "used_parameters.yml"); } diff --git a/src/parser.c b/src/parser.c index 41a3e8637630eceb3beb9383acb3344028d38659..02970c0526072013c14ee27c4486c8915ec67b25 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,6 +1,7 @@ /******************************************************************************* * This file is part of SWIFT. * Copyright (c) 2016 James Willis (james.s.willis@durham.ac.uk) + * 2017 Peter W. Draper (p.w.draper@durham.ac.uk) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -89,6 +90,62 @@ void parser_read_file(const char *file_name, struct swift_params *params) { fclose(file); } +/** + * @brief Set or update a parameter using a compressed format. + * + * The compressed format allows a value to be given as a single + * string and has the format "section:parameter:value", with all + * names as would be given in the parameter file. + * + * @param params Structure that holds the parameters. + * @param namevalue the parameter name and value as described. + */ +void parser_set_param(struct swift_params *params, const char *namevalue) { + + /* Get the various parts. */ + char name[PARSER_MAX_LINE_SIZE]; + char value[PARSER_MAX_LINE_SIZE]; + name[0] = '\0'; + value[0] = '\0'; + + /* Name is part until second colon. */ + char *p1 = strchr(namevalue, ':'); + if (p1 != NULL) { + char *p2 = strchr(p1 + 1, ':'); + if (p2 != NULL) { + memcpy(name, namevalue, p2 - namevalue); + name[p2 - namevalue] = '\0'; + + /* Value is rest after second colon. */ + p2++; + strcpy(value, p2); + } + } + + /* Sanity check. */ + if (strlen(name) == 0 || strlen(value) == 0 || strchr(value, ':') != NULL) + error( + "Cannot parse compressed parameter string: '%s', check syntax " + "should be section:parameter:value", + namevalue); + + /* And update or set. */ + int updated = 0; + for (int i = 0; i < params->paramCount; i++) { + if (strcmp(name, params->data[i].name) == 0) { + strcpy(params->data[i].value, value); + updated = 1; + } + } + if (!updated) { + strcpy(params->data[params->paramCount].name, name); + strcpy(params->data[params->paramCount].value, value); + params->paramCount++; + if (params->paramCount == PARSER_MAX_NO_OF_PARAMS) + error("Too many parameters, current maximum is %d.", params->paramCount); + } +} + /** * @brief Counts the number of times a specific character appears in a string. * @@ -238,7 +295,7 @@ static void parse_value(char *line, struct swift_params *params) { /* Check for more than one value on the same line. */ if (count_char(line, PARSER_VALUE_CHAR) > 1) { - error("Inavlid line:%d '%s', only one value allowed per line.", lineNumber, + error("Invalid line:%d '%s', only one value allowed per line.", lineNumber, line); } diff --git a/src/parser.h b/src/parser.h index b78e21194d256ed7b50b8a09718c9725d52a1e0b..bab6d8b25f5334546ac2aaf39a3f25ef7fb6ff57 100644 --- a/src/parser.h +++ b/src/parser.h @@ -1,6 +1,7 @@ /******************************************************************************* * This file is part of SWIFT. * Copyright (c) 2016 James Willis (james.s.willis@durham.ac.uk) + * 2017 Peter W. Draper (p.w.draper@durham.ac.uk) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -55,6 +56,7 @@ void parser_read_file(const char *file_name, struct swift_params *params); void parser_print_params(const struct swift_params *params); void parser_write_params_to_file(const struct swift_params *params, const char *file_name); +void parser_set_param(struct swift_params *params, const char *desc); char parser_get_param_char(const struct swift_params *params, const char *name); int parser_get_param_int(const struct swift_params *params, const char *name); diff --git a/src/potential/disc_patch/potential.h b/src/potential/disc_patch/potential.h index 5ba1f4fff5c91ce16f1c8ad62bc55d44a1a6a780..d323d18c03b9903785957954beae99320e3522a5 100644 --- a/src/potential/disc_patch/potential.h +++ b/src/potential/disc_patch/potential.h @@ -190,8 +190,9 @@ __attribute__((always_inline)) INLINE static void external_gravity_acceleration( } else if (abs_dz < z_max) { /* Acc. 2 pi sigma tanh(z/b) [1/2 + 1/2cos((z-zmax)/(pi z_trans))] */ - a_z = reduction_factor * norm_over_G * tanhf(abs_dz * b_inv) * - (0.5f + 0.5f * cosf((float)(M_PI) * (abs_dz - z_trunc) * z_trans_inv)); + a_z = + reduction_factor * norm_over_G * tanhf(abs_dz * b_inv) * + (0.5f + 0.5f * cosf((float)(M_PI) * (abs_dz - z_trunc) * z_trans_inv)); } else { /* Acc. 0 */