Skip to content
Snippets Groups Projects
Commit cbefe349 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'Parameter-File' into 'master'

First version of main() using a parameter file to get constants.

That's pretty big but does not touch the physics, the parallelisation nor MPI.

In brief:
 - Latest version of the parser from @jwillis 
 - More uniform name of functions in the unit module.
 - Added the ability for the `engine`, `space`, `unit` and `partition` objects to construct themselves from a parsed parameter file.
 - Added an example yaml file with full documentation.
 - Added yaml files and run scripts for the Sedov, Sod and uniform examples. 
 - General tidying of the `main()`.
 - Dropped the dependency on z-lib which we don't use.
 - Updated the README to reflect the new command-line parameters.
 - Cleaned-up the `main()` such that the only command-line parameters read in are policies and debugging options. 
 - Added the option to do a 'dry run'. This reads the parameter file, allocates the memory required by the ICs but does not read anything and constructs a space and engine. This allows us to check the validity of a given parameter file.

Happy to guide you through the changes if need be. 

This closes #81.

See merge request !140
parents 6497e9a5 32f64881
No related branches found
No related tags found
1 merge request!140First version of main() using a parameter file to get constants.
Showing
with 616 additions and 473 deletions
......@@ -43,6 +43,7 @@ tests/testTimeIntegration
tests/testSPHStep
tests/testKernel
tests/testParser
tests/parser_output.yml
theory/latex/swift.pdf
theory/kernel/kernels.pdf
......
Welcome to the cosmological code
Welcome to the cosmological hydrodynamical code
______ _________________
/ ___/ | / / _/ ___/_ __/
\__ \| | /| / // // /_ / /
......@@ -6,8 +6,26 @@
/____/ |__/|__/___/_/ /_/
SPH With Inter-dependent Fine-grained Tasking
Website: www.swiftsim.com
Twitter: @SwiftSimulation
Website: www.swiftsim.com
Twitter: @SwiftSimulation
See INSTALL.swift for instructions.
See INSTALL.swift for install instructions.
Usage: swift [OPTION] PARAMFILE
Valid options are:
-c Run with cosmological time integration
-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.
-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
-s Run with SPH
-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 examples/parameter_example.yml for an example of parameter file.
......@@ -287,11 +287,11 @@ AC_SUBST([METIS_LIBS])
AC_SUBST([METIS_INCS])
AM_CONDITIONAL([HAVEMETIS],[test -n "$METIS_LIBS"])
# Check for zlib.
AC_CHECK_LIB([z],[gzopen],[
AC_DEFINE([HAVE_LIBZ],[1],[Set to 1 if zlib is installed.])
LDFLAGS="$LDFLAGS -lz"
],[])
# # Check for zlib.
# AC_CHECK_LIB([z],[gzopen],[
# AC_DEFINE([HAVE_LIBZ],[1],[Set to 1 if zlib is installed.])
# LDFLAGS="$LDFLAGS -lz"
# ],[])
# Check for HDF5. This is required.
......
# Define the system of units to use internally.
UnitSystem:
UnitMass_in_cgs: 1 # Grams
UnitLength_in_cgs: 1 # Centimeters
UnitVelocity_in_cgs: 1 # Centimeters per second
UnitCurrent_in_cgs: 1 # Amperes
UnitTemp_in_cgs: 1 # Kelvin
# Parameters for the task scheduling
Scheduler:
nr_threads: 16 # The number of threads per MPI rank to use.
nr_queues: 0 # The number of task queues to use. Use 0 to let the system decide.
cell_max_size: 8000000 # Maximal number of interactions per task (this is the default value).
cell_sub_size: 5000 # Maximal number of interactions per sub-task (this is the default value).
cell_split_size: 400 # Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration:
time_begin: 0. # The starting time of the simulation (in internal units).
time_end: 1. # The end time of the simulation (in internal units).
dt_min: 1e-6 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-2 # The maximal time-step size of the simulation (in internal units).
# Parameters for the hydrodynamics scheme
SPH:
resolution_eta: 1.2349 # Target smoothing length in units of the mean inter-particle separation (1.2349 == 48Ngbs with the cubic spline kernel).
delta_neighbours: 1. # The tolerance for the targetted number of neighbours.
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
max_ghost_iterations: 30 # Maximal number of iterations allowed to converge towards the smoothing length.
max_smoothing_length: 0.6 # Maximal smoothing length allowed (in internal units).
# Parameters related to the initial conditions
InitialConditions:
file_name: ./cosmoVolume.hdf5 # The file to read
h_scaling: 1. # A scaling factor to apply to all smoothing lengths in the ICs.
shift_x: 0. # A shift to apply to all particles read from the ICs (in internal units).
shift_y: 0.
shift_z: 0.
# Parameters govering domain decomposition
DomainDecomposition:
initial_type: m # The initial strategy ("g", "m", "w", or "v"). See documentation for details.
initial_grid_x: 10 # Grid size if the 'g' strategy is chosen.
initial_grid_y: 10
initial_grid_z: 10
repartition_type: b # The re-decomposition strategy ("n", "b", "v", "e" or "x"). See documentation for details.
#!/bin/bash
# Generate the initial conditions if they are not present.
if [ ! -e cosmoVolume.hdf5 ]
then
echo "Fetching initial conditions for the cosmo volume example..."
./getIC.sh
fi
../swift -s cosmoVolume.yml
#!/bin/bash
# Generate the initial conditions if they are not present.
if [ ! -e sedov.hdf5 ]
then
echo "Generating initial conditions for the SedovBlast example..."
python makeIC_fcc.py
fi
../swift -s sedov.yml
# Define the system of units to use internally.
UnitSystem:
UnitMass_in_cgs: 1 # Grams
UnitLength_in_cgs: 1 # Centimeters
UnitVelocity_in_cgs: 1 # Centimeters per second
UnitCurrent_in_cgs: 1 # Amperes
UnitTemp_in_cgs: 1 # Kelvin
# Parameters for the task scheduling
Scheduler:
nr_threads: 16 # The number of threads per MPI rank to use.
nr_queues: 0 # The number of task queues to use. Use 0 to let the system decide.
cell_max_size: 8000000 # Maximal number of interactions per task (this is the default value).
cell_sub_size: 5000 # Maximal number of interactions per sub-task (this is the default value).
cell_split_size: 400 # Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration:
time_begin: 0. # The starting time of the simulation (in internal units).
time_end: 1. # The end time of the simulation (in internal units).
dt_min: 1e-7 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-2 # The maximal time-step size of the simulation (in internal units).
# Parameters for the hydrodynamics scheme
SPH:
resolution_eta: 1.2349 # Target smoothing length in units of the mean inter-particle separation (1.2349 == 48Ngbs with the cubic spline kernel).
delta_neighbours: 1. # The tolerance for the targetted number of neighbours.
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
max_ghost_iterations: 30 # Maximal number of iterations allowed to converge towards the smoothing length.
max_smoothing_length: 1. # Maximal smoothing length allowed (in internal units).
# Parameters related to the initial conditions
InitialConditions:
file_name: ./sedov.hdf5 # The file to read
h_scaling: 1. # A scaling factor to apply to all smoothing lengths in the ICs.
shift_x: 0. # A shift to apply to all particles read from the ICs (in internal units).
shift_y: 0.
shift_z: 0.
# Parameters govering domain decomposition
DomainDecomposition:
initial_type: m # The initial strategy ("g", "m", "w", or "v"). See documentation for details.
initial_grid_x: 10 # Grid size if the 'g' strategy is chosen.
initial_grid_y: 10
initial_grid_z: 10
repartition_type: b # The re-decomposition strategy ("n", "b", "v", "e" or "x"). See documentation for details.
#!/bin/bash
# Generate the initial conditions if they are not present.
if [ ! -e sodShock.hdf5 ]
then
echo "Generating initial conditions for the SodShock example..."
python makeIC.py
fi
../swift -s sodShock.yml
# Define the system of units to use internally.
UnitSystem:
UnitMass_in_cgs: 1 # Grams
UnitLength_in_cgs: 1 # Centimeters
UnitVelocity_in_cgs: 1 # Centimeters per second
UnitCurrent_in_cgs: 1 # Amperes
UnitTemp_in_cgs: 1 # Kelvin
# Parameters for the task scheduling
Scheduler:
nr_threads: 16 # The number of threads per MPI rank to use.
nr_queues: 0 # The number of task queues to use. Use 0 to let the system decide.
cell_max_size: 8000000 # Maximal number of interactions per task (this is the default value).
cell_sub_size: 5000 # Maximal number of interactions per sub-task.
cell_split_size: 400 # Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration:
time_begin: 0. # The starting time of the simulation (in internal units).
time_end: 1. # The end time of the simulation (in internal units).
dt_min: 1e-7 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-2 # The maximal time-step size of the simulation (in internal units).
# Parameters for the hydrodynamics scheme
SPH:
resolution_eta: 1.2349 # Target smoothing length in units of the mean inter-particle separation (1.2349 == 48Ngbs with the cubic spline kernel).
delta_neighbours: 1. # The tolerance for the targetted number of neighbours.
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
max_ghost_iterations: 30 # Maximal number of iterations allowed to converge towards the smoothing length.
max_smoothing_length: 0.01 # Maximal smoothing length allowed (in internal units).
# Parameters related to the initial conditions
InitialConditions:
file_name: ./sodShock.hdf5 # The file to read
h_scaling: 1. # A scaling factor to apply to all smoothing lengths in the ICs.
shift_x: 0. # A shift to apply to all particles read from the ICs (in internal units).
shift_y: 0.
shift_z: 0.
# Parameters govering domain decomposition
DomainDecomposition:
initial_type: m # The initial strategy ("g", "m", "w", or "v"). See documentation for details.
initial_grid_x: 10 # Grid size if the 'g' strategy is chosen.
initial_grid_y: 10
initial_grid_z: 10
repartition_type: b # The re-decomposition strategy ("n", "b", "v", "e" or "x"). See documentation for details.
#!/bin/bash
# Generate the initial conditions if they are not present.
if [ ! -e uniformBox.hdf5 ]
then
echo "Generating initial conditions for the uniform box example..."
python makeIC.py 100
fi
../swift -s uniformBox.yml
# Define the system of units to use internally.
UnitSystem:
UnitMass_in_cgs: 1 # Grams
UnitLength_in_cgs: 1 # Centimeters
UnitVelocity_in_cgs: 1 # Centimeters per second
UnitCurrent_in_cgs: 1 # Amperes
UnitTemp_in_cgs: 1 # Kelvin
# Parameters for the task scheduling
Scheduler:
nr_threads: 16 # The number of threads per MPI rank to use.
nr_queues: 0 # The number of task queues to use. Use 0 to let the system decide.
cell_max_size: 8000000 # Maximal number of interactions per task (this is the default value).
cell_sub_size: 5000 # Maximal number of interactions per sub-task (this is the default value).
cell_split_size: 400 # Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration:
time_begin: 0. # The starting time of the simulation (in internal units).
time_end: 1. # The end time of the simulation (in internal units).
dt_min: 1e-6 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-2 # The maximal time-step size of the simulation (in internal units).
# Parameters for the hydrodynamics scheme
SPH:
resolution_eta: 1.2349 # Target smoothing length in units of the mean inter-particle separation (1.2349 == 48Ngbs with the cubic spline kernel).
delta_neighbours: 1. # The tolerance for the targetted number of neighbours.
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
max_ghost_iterations: 30 # Maximal number of iterations allowed to converge towards the smoothing length.
max_smoothing_length: 0.1 # Maximal smoothing length allowed (in internal units).
# Parameters related to the initial conditions
InitialConditions:
file_name: ./uniformBox.hdf5 # The file to read
h_scaling: 1. # A scaling factor to apply to all smoothing lengths in the ICs.
shift_x: 0. # A shift to apply to all particles read from the ICs (in internal units).
shift_y: 0.
shift_z: 0.
# Parameters govering domain decomposition
DomainDecomposition:
initial_type: m # The initial strategy ("g", "m", "w", or "v"). See documentation for details.
initial_grid_x: 10 # Grid size if the 'g' strategy is chosen.
initial_grid_y: 10
initial_grid_z: 10
repartition_type: b # The re-decomposition strategy ("n", "b", "v", "e" or "x"). See documentation for details.
This diff is collapsed.
# Define the system of units to use internally.
UnitSystem:
UnitMass_in_cgs: 1 # Grams
UnitLength_in_cgs: 1 # Centimeters
UnitVelocity_in_cgs: 1 # Centimeters per second
UnitCurrent_in_cgs: 1 # Amperes
UnitTemp_in_cgs: 1 # Kelvin
# Parameters for the task scheduling
Scheduler:
nr_threads: 2 # The number of threads per MPI rank to use.
nr_queues: 0 # The number of task queues to use. Use 0 to let the system decide.
cell_max_size: 8000000 # Maximal number of interactions per task (this is the default value).
cell_sub_size: 8000000 # Maximal number of interactions per sub-task (this is the default value).
cell_split_size: 400 # Maximal number of particles per cell (this is the default value).
# Parameters governing the time integration
TimeIntegration:
time_begin: 0. # The starting time of the simulation (in internal units).
time_end: 1. # The end time of the simulation (in internal units).
dt_min: 1e-6 # The minimal time-step size of the simulation (in internal units).
dt_max: 1e-2 # The maximal time-step size of the simulation (in internal units).
# Parameters for the hydrodynamics scheme
SPH:
resolution_eta: 1.2349 # Target smoothing length in units of the mean inter-particle separation (1.2349 == 48Ngbs with the cubic spline kernel).
delta_neighbours: 1. # The tolerance for the targetted number of neighbours.
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
max_ghost_iterations: 30 # Maximal number of iterations allowed to converge towards the smoothing length.
max_smoothing_length: 3. # Maximal smoothing length allowed (in internal units).
# Parameters related to the initial conditions
InitialConditions:
file_name: SedovBlast/sedov.hdf5 # The file to read
h_scaling: 1. # A scaling factor to apply to all smoothing lengths in the ICs.
shift_x: 0. # A shift to apply to all particles read from the ICs (in internal units).
shift_y: 0.
shift_z: 0.
# Parameters govering domain decomposition
DomainDecomposition:
initial_type: m # The initial strategy ("g", "m", "w", or "v"). See documentation for details.
initial_grid_x: 10 # Grid size if the 'g' strategy is chosen.
initial_grid_y: 10
initial_grid_z: 10
repartition_type: b # The re-decomposition strategy ("n", "b", "v", "e" or "x"). See documentation for details.
#!/bin/bash
# Set some global stuff
export OMP_WAIT_POLICY=PASSIVE
# Generate the initial conditions if they are not present.
if [ ! -e SodShock/sodShock.hdf5 ]
then
echo "Generating initial conditions for the SodShock example..."
cd SodShock
python makeIC.py
cd ..
fi
if [ ! -e SedovBlast/sedov.hdf5 ]
then
echo "Generating initial conditions for the SedovBlast example..."
cd SedovBlast/
python makeIC_fcc.py
cd ..
fi
if [ ! -e CosmoVolume/cosmoVolume.hdf5 ]
then
echo "Downloading initial conditions for the CosmoVolume example..."
cd CosmoVolume
./getIC.sh
cd ..
fi
# Loop over number of cores
for cpu in {1..32}
do
# Sod-Shock runs
if [ ! -e SodShock_${cpu}.dump ]
then
./swift -t $cpu -f SodShock/sodShock.hdf5 -m 0.01 -w 5000 -c 1. -d 1e-7 -e 0.01 > SodShock_fixed_${cpu}.dump
fi
# Sedov blast
if [ ! -e SedovBlast_${cpu}.dump ]
then
./swift -t $cpu -f SedovBlast/sedov.hdf5 -m 0.02 -w 5000 -c 1. -d 1e-7 -e 0.01 > SedovBlast_fixed_${cpu}.dump
fi
# Cosmological volume
if [ ! -e CosmoVolume_${cpu}.dump ]
then
./swift -t $cpu -f CosmoVolume/cosmoVolume.hdf5 -m 0.6 -w 5000 -c 1. -d 1e-7 -e 0.01 > CosmoVolume_fixed_${cpu}.dump
fi
done
......@@ -282,15 +282,15 @@ void writeUnitSystem(hid_t h_file, struct UnitSystem* us) {
if (h_grpunit < 0) error("Error while creating Unit System group");
writeAttribute_d(h_grpunit, "Unit mass in cgs (U_M)",
getBaseUnit(us, UNIT_MASS));
units_get_base_unit(us, UNIT_MASS));
writeAttribute_d(h_grpunit, "Unit length in cgs (U_L)",
getBaseUnit(us, UNIT_LENGTH));
units_get_base_unit(us, UNIT_LENGTH));
writeAttribute_d(h_grpunit, "Unit time in cgs (U_t)",
getBaseUnit(us, UNIT_TIME));
units_get_base_unit(us, UNIT_TIME));
writeAttribute_d(h_grpunit, "Unit current in cgs (U_I)",
getBaseUnit(us, UNIT_CURRENT));
units_get_base_unit(us, UNIT_CURRENT));
writeAttribute_d(h_grpunit, "Unit temperature in cgs (U_T)",
getBaseUnit(us, UNIT_TEMPERATURE));
units_get_base_unit(us, UNIT_TEMPERATURE));
H5Gclose(h_grpunit);
}
......
......@@ -70,9 +70,4 @@
#define GADGET2_SPH
//#define DEFAULT_SPH
/* System of units */
#define const_unit_length_in_cgs 1 /* 3.08567810e16 /\* 1Mpc *\/ */
#define const_unit_mass_in_cgs 1 /* 1.9891e33 /\* 1 M_sun *\/ */
#define const_unit_velocity_in_cgs 1 /* 1e5 /\* km s^-1 *\/ */
#endif /* SWIFT_CONST_H */
......@@ -56,10 +56,11 @@
#include "partition.h"
#include "timers.h"
const char *engine_policy_names[12] = {
"none", "rand", "steal", "keep",
"block", "fix_dt", "cpu_tight", "mpi",
"numa_affinity", "hydro", "self_gravity", "external_gravity"};
const char *engine_policy_names[13] = {
"none", "rand", "steal", "keep",
"block", "fix_dt", "cpu_tight", "mpi",
"numa_affinity", "hydro", "self_gravity", "external_gravity",
"cosmology_integration"};
/** The rank of the engine as a global variable (for messages). */
int engine_rank;
......@@ -1650,7 +1651,7 @@ void engine_rebuild(struct engine *e) {
error("engine_marktasks failed after space_rebuild.");
/* Print the status of the system */
engine_print_task_counts(e);
if (e->verbose) engine_print_task_counts(e);
if (e->verbose)
message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
......@@ -2026,8 +2027,8 @@ void engine_step(struct engine *e) {
if (e->nodeID == 0) {
/* Print some information to the screen */
printf("%d %e %e %d %d %.3f\n", e->step, e->time, e->timeStep, updates,
g_updates, e->wallclock_time);
printf(" %6d %14e %14e %10d %10d %21.3f\n", e->step, e->time, e->timeStep,
updates, g_updates, e->wallclock_time);
fflush(stdout);
/* Write some energy statistics */
......@@ -2320,30 +2321,25 @@ static bool hyperthreads_present(void) {
*
* @param e The #engine.
* @param s The #space in which this #runner will run.
* @param dt The initial time step to use.
* @param nr_threads The number of threads to spawn.
* @param nr_queues The number of task queues to create.
* @param params The parsed parameter file.
* @param nr_nodes The number of MPI ranks.
* @param nodeID The MPI rank of this node.
* @param policy The queuing policy to use.
* @param timeBegin Time at the begininning of the simulation.
* @param timeEnd Time at the end of the simulation.
* @param dt_min Minimal allowed timestep (unsed with fixdt policy)
* @param dt_max Maximal allowed timestep
* @param verbose Is this #engine talkative ?
*/
void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
int nr_queues, int nr_nodes, int nodeID, int policy,
float timeBegin, float timeEnd, float dt_min, float dt_max,
int verbose) {
void engine_init(struct engine *e, struct space *s,
const struct swift_params *params, int nr_nodes, int nodeID,
int policy, int verbose) {
/* Clean-up everything */
bzero(e, sizeof(struct engine));
/* Store the values. */
e->s = s;
e->nr_threads = nr_threads;
e->nr_threads = parser_get_param_int(params, "Scheduler:nr_threads");
e->policy = policy;
e->step = 0;
e->nullstep = 0;
e->nr_nodes = nr_nodes;
e->nodeID = nodeID;
e->proxy_ind = NULL;
......@@ -2352,15 +2348,15 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
e->forcerepart = REPART_NONE;
e->links = NULL;
e->nr_links = 0;
e->timeBegin = timeBegin;
e->timeEnd = timeEnd;
e->timeOld = timeBegin;
e->time = timeBegin;
e->timeBegin = parser_get_param_double(params, "TimeIntegration:time_begin");
e->timeEnd = parser_get_param_double(params, "TimeIntegration:time_end");
e->timeOld = e->timeBegin;
e->time = e->timeBegin;
e->ti_old = 0;
e->ti_current = 0;
e->timeStep = 0.;
e->dt_min = dt_min;
e->dt_max = dt_max;
e->dt_min = parser_get_param_double(params, "TimeIntegration:dt_min");
e->dt_max = parser_get_param_double(params, "TimeIntegration:dt_max");
e->file_stats = NULL;
e->verbose = verbose;
e->count_step = 0;
......@@ -2370,6 +2366,11 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
/* Make the space link back to the engine. */
s->e = e;
/* Get the number of queues */
int nr_queues = parser_get_param_int(params, "Scheduler:nr_queues");
if (nr_queues <= 0) nr_queues = e->nr_threads;
s->nr_queues = nr_queues;
#if defined(HAVE_SETAFFINITY)
const int nr_cores = sysconf(_SC_NPROCESSORS_ONLN);
int cpuid[nr_cores];
......@@ -2465,15 +2466,19 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
engine_print_policy(e);
/* Print information about the hydro scheme */
if (e->nodeID == 0) message("Hydrodynamic scheme: %s", SPH_IMPLEMENTATION);
if (e->nodeID == 0) message("Hydrodynamic kernel: %s", kernel_name);
if ((e->policy & engine_policy_hydro) == engine_policy_hydro) {
if (e->nodeID == 0) message("Hydrodynamic scheme: %s.", SPH_IMPLEMENTATION);
if (e->nodeID == 0)
message("Hydrodynamic kernel: %s with %.2f +/- %.2f neighbours.",
kernel_name, kernel_nwneigh, const_delta_nwneigh);
}
/* Check we have sensible time bounds */
if (timeBegin >= timeEnd)
if (e->timeBegin >= e->timeEnd)
error(
"Final simulation time (t_end = %e) must be larger than the start time "
"(t_beg = %e)",
timeEnd, timeBegin);
e->timeEnd, e->timeBegin);
/* Check we have sensible time-step values */
if (e->dt_min > e->dt_max)
......@@ -2483,7 +2488,7 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
e->dt_min, e->dt_max);
/* Deal with timestep */
e->timeBase = (timeEnd - timeBegin) / max_nr_timesteps;
e->timeBase = (e->timeEnd - e->timeBegin) / max_nr_timesteps;
e->ti_current = 0;
/* Fixed time-step case */
......@@ -2502,12 +2507,12 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
if (e->nodeID == 0) {
message("Absolute minimal timestep size: %e", e->timeBase);
float dt_min = timeEnd - timeBegin;
float dt_min = e->timeEnd - e->timeBegin;
while (dt_min > e->dt_min) dt_min /= 2.f;
message("Minimal timestep size (on time-line): %e", dt_min);
float dt_max = timeEnd - timeBegin;
float dt_max = e->timeEnd - e->timeBegin;
while (dt_max > e->dt_max) dt_max /= 2.f;
message("Maximal timestep size (on time-line): %e", dt_max);
......@@ -2541,10 +2546,9 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
e->barrier_launchcount = 0;
/* Init the scheduler with enough tasks for the initial sorting tasks. */
int nr_tasks = 2 * s->tot_cells + e->nr_threads;
const int nr_tasks = 2 * s->tot_cells + 2 * e->nr_threads;
scheduler_init(&e->sched, e->s, nr_tasks, nr_queues, scheduler_flag_steal,
e->nodeID);
s->nr_queues = nr_queues;
/* Create the sorting tasks. */
for (int i = 0; i < e->nr_threads; i++) {
......@@ -2558,10 +2562,10 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
scheduler_ranktasks(&e->sched);
/* Allocate and init the threads. */
if ((e->runners =
(struct runner *)malloc(sizeof(struct runner) * nr_threads)) == NULL)
if ((e->runners = (struct runner *)malloc(sizeof(struct runner) *
e->nr_threads)) == NULL)
error("Failed to allocate threads array.");
for (int k = 0; k < nr_threads; k++) {
for (int k = 0; k < e->nr_threads; k++) {
e->runners[k].id = k;
e->runners[k].e = e;
e->barrier_running += 1;
......@@ -2573,7 +2577,7 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
/* Set a reasonable queue ID. */
e->runners[k].cpuid = cpuid[k % nr_cores];
if (nr_queues < nr_threads)
if (nr_queues < e->nr_threads)
e->runners[k].qid = cpuid[k % nr_cores] * nr_queues / nr_cores;
else
e->runners[k].qid = k;
......@@ -2592,7 +2596,7 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
#endif
} else {
e->runners[k].cpuid = k;
e->runners[k].qid = k * nr_queues / nr_threads;
e->runners[k].qid = k * nr_queues / e->nr_threads;
}
// message( "runner %i on cpuid=%i with qid=%i." , e->runners[k].id ,
// e->runners[k].cpuid , e->runners[k].qid );
......
......@@ -38,6 +38,7 @@
#include "scheduler.h"
#include "space.h"
#include "task.h"
#include "parser.h"
#include "partition.h"
/* Some constants. */
......@@ -53,7 +54,8 @@ enum engine_policy {
engine_policy_setaffinity = (1 << 7),
engine_policy_hydro = (1 << 8),
engine_policy_self_gravity = (1 << 9),
engine_policy_external_gravity = (1 << 10)
engine_policy_external_gravity = (1 << 10),
engine_policy_cosmology = (1 << 11)
};
extern const char *engine_policy_names[];
......@@ -126,7 +128,7 @@ struct engine {
FILE *file_stats;
/* The current step number. */
int step, nullstep;
int step;
/* The number of particles updated in the previous step. */
int count_step;
......@@ -166,10 +168,9 @@ struct engine {
/* Function prototypes. */
void engine_barrier(struct engine *e, int tid);
void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
int nr_queues, int nr_nodes, int nodeID, int policy,
float timeBegin, float timeEnd, float dt_min, float dt_max,
int verbose);
void engine_init(struct engine *e, struct space *s,
const struct swift_params *params, int nr_nodes, int nodeID,
int policy, int verbose);
void engine_launch(struct engine *e, int nr_runners, unsigned int mask,
unsigned int submask);
void engine_prepare(struct engine *e);
......
......@@ -274,11 +274,11 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile,
type);
/* Write unit conversion factors for this data set */
conversionString(buffer, us, convFactor);
units_conversion_string(buffer, us, convFactor);
writeAttribute_d(h_data, "CGS conversion factor",
conversionFactor(us, convFactor));
writeAttribute_f(h_data, "h-scale exponent", hFactor(us, convFactor));
writeAttribute_f(h_data, "a-scale exponent", aFactor(us, convFactor));
units_conversion_factor(us, convFactor));
writeAttribute_f(h_data, "h-scale exponent", units_h_factor(us, convFactor));
writeAttribute_f(h_data, "a-scale exponent", units_a_factor(us, convFactor));
writeAttribute_s(h_data, "Conversion factor", buffer);
/* Free and close everything */
......@@ -349,6 +349,7 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile,
* @param parts (output) The array of #part read from the file.
* @param N (output) The number of particles read from the file.
* @param periodic (output) 1 if the volume is periodic, 0 if not.
* @param dry_run If 1, don't read the particle. Only allocates the arrays.
*
* Opens the HDF5 file fileName and reads the particles contained
* in the parts array. N is the returned number of particles found
......@@ -363,7 +364,7 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile,
void read_ic_parallel(char* fileName, double dim[3], struct part** parts,
struct gpart** gparts, size_t* Ngas, size_t* Ngparts,
int* periodic, int mpi_rank, int mpi_size, MPI_Comm comm,
MPI_Info info) {
MPI_Info info, int dry_run) {
hid_t h_file = 0, h_grp = 0;
/* GADGET has only cubic boxes (in cosmological mode) */
double boxSize[3] = {0.0, -1.0, -1.0};
......@@ -469,13 +470,15 @@ void read_ic_parallel(char* fileName, double dim[3], struct part** parts,
switch (ptype) {
case GAS:
hydro_read_particles(h_grp, N[ptype], N_total[ptype], offset[ptype],
*parts);
if (!dry_run)
hydro_read_particles(h_grp, N[ptype], N_total[ptype], offset[ptype],
*parts);
break;
case DM:
darkmatter_read_particles(h_grp, N[ptype], N_total[ptype],
offset[ptype], *gparts);
if (!dry_run)
darkmatter_read_particles(h_grp, N[ptype], N_total[ptype],
offset[ptype], *gparts);
break;
default:
......@@ -487,10 +490,10 @@ void read_ic_parallel(char* fileName, double dim[3], struct part** parts,
}
/* Prepare the DM particles */
prepare_dm_gparts(*gparts, Ndm);
if (!dry_run) prepare_dm_gparts(*gparts, Ndm);
/* Now duplicate the hydro particle into gparts */
duplicate_hydro_gparts(*parts, *gparts, *Ngas, Ndm);
if (!dry_run) duplicate_hydro_gparts(*parts, *gparts, *Ngas, Ndm);
/* message("Done Reading particles..."); */
......
......@@ -34,7 +34,7 @@
void read_ic_parallel(char* fileName, double dim[3], struct part** parts,
struct gpart** gparts, size_t* Ngas, size_t* Ngparts,
int* periodic, int mpi_rank, int mpi_size, MPI_Comm comm,
MPI_Info info);
MPI_Info info, int dry_run);
void write_output_parallel(struct engine* e, struct UnitSystem* us,
int mpi_rank, int mpi_size, MPI_Comm comm,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment