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
704826e2
Commit
704826e2
authored
Apr 03, 2016
by
Matthieu Schaller
Browse files
The engine initialisation is now done via the parameter file
parent
e9e40394
Changes
4
Hide whitespace changes
Inline
Side-by-side
examples/main.c
View file @
704826e2
...
...
@@ -42,11 +42,16 @@
#define ENGINE_POLICY engine_policy_none
#endif
/**
* @brief Help messages for the command line parameters.
*/
void
print_help_message
()
{
printf
(
"
\n
Usage: swift [OPTION] PARAMFILE
\n\n
"
);
printf
(
"Valid options are:
\n
"
);
printf
(
" %2s %8s %s
\n
"
,
"-c"
,
""
,
"Run with cosmological time integration"
);
printf
(
" %2s %8s %s
\n
"
,
"-e"
,
""
,
"Enable floating-point exceptions (debugging mode)"
);
printf
(
" %2s %8s %s
\n
"
,
"-f"
,
"[value] "
,
"Overwrites the CPU frequency (Hz) to be used for time measurements"
);
printf
(
" %2s %8s %s
\n
"
,
"-g"
,
""
,
...
...
@@ -68,13 +73,7 @@ void print_help_message() {
*/
int
main
(
int
argc
,
char
*
argv
[])
{
int
c
,
icount
;
double
time_end
=
DBL_MAX
;
struct
clocks_time
tic
,
toc
;
float
dt_max
=
0
.
0
f
,
dt_min
=
0
.
0
f
;
int
nr_nodes
=
1
,
myrank
=
0
;
int
with_outputs
=
0
;
int
nr_threads
,
nr_queues
;
#ifdef WITH_MPI
struct
partition
initial_partition
;
...
...
@@ -91,9 +90,7 @@ int main(int argc, char *argv[]) {
#endif
#endif
/* Choke on FP-exceptions. */
// feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
int
nr_nodes
=
1
,
myrank
=
0
;
#ifdef WITH_MPI
/* Start by initializing MPI. */
int
res
=
0
,
prov
=
0
;
...
...
@@ -147,15 +144,20 @@ int main(int argc, char *argv[]) {
int
with_external_gravity
=
0
;
int
with_self_gravity
=
0
;
int
with_hydro
=
0
;
int
with_fp_exceptions
=
0
;
int
verbose
=
0
;
char
paramFileName
[
200
]
=
""
;
unsigned
long
long
cpufreq
=
0
;
/* Parse the parameters */
while
((
c
=
getopt
(
argc
,
argv
,
"cf:gGhsv:y"
))
!=
-
1
)
switch
(
c
)
{
int
c
;
while
((
c
=
getopt
(
argc
,
argv
,
"cef:gGhsv:y"
))
!=
-
1
)
switch
(
c
)
{
case
'c'
:
with_cosmology
=
1
;
break
;
case
'e'
:
with_fp_exceptions
=
1
;
break
;
case
'f'
:
if
(
sscanf
(
optarg
,
"%llu"
,
&
cpufreq
)
!=
1
)
{
if
(
myrank
==
0
)
printf
(
"Error parsing CPU frequency (-f).
\n
"
);
...
...
@@ -216,6 +218,12 @@ int main(int argc, char *argv[]) {
message
(
"CPU frequency used for tick conversion: %llu Hz"
,
cpufreq
);
}
/* Do we choke on FP-exceptions ? */
if
(
with_fp_exceptions
)
{
feenableexcept
(
FE_DIVBYZERO
|
FE_INVALID
|
FE_OVERFLOW
);
if
(
myrank
==
0
)
message
(
"Floating point exceptions will be reported."
);
}
/* How large are the parts? */
if
(
myrank
==
0
)
{
message
(
"sizeof(struct part) is %4zi bytes."
,
sizeof
(
struct
part
));
...
...
@@ -223,12 +231,21 @@ int main(int argc, char *argv[]) {
message
(
"sizeof(struct gpart) is %4zi bytes."
,
sizeof
(
struct
gpart
));
}
/* How vocal are we ? */
const
int
talking
=
(
verbose
==
1
&&
myrank
==
0
)
||
(
verbose
==
2
);
/* Read the parameter file */
struct
swift_params
params
;
message
(
"Reading parameters from file '%s'"
,
paramFileName
);
parser_read_file
(
paramFileName
,
&
params
);
// parser_print_params(¶ms);
if
(
myrank
==
0
)
parser_write_params_to_file
(
&
params
,
"used_parameters.yml"
);
if
(
myrank
==
0
)
{
message
(
"Reading parameters from file '%s'"
,
paramFileName
);
parser_read_file
(
paramFileName
,
&
params
);
// parser_print_params(¶ms);
parser_write_params_to_file
(
&
params
,
"used_parameters.yml"
);
}
#ifdef WITH_MPI
/* Broadcast the parameter file */
MPI_Bcast
(
&
params
,
sizeof
(
struct
swift_params
),
MPI_BYTE
,
MPI_COMM_WORLD
);
#endif
/* Initialize unit system */
struct
UnitSystem
us
;
...
...
@@ -284,12 +301,13 @@ int main(int argc, char *argv[]) {
#endif
if
(
myrank
==
0
)
{
clocks_gettime
(
&
toc
);
message
(
"Reading
particle properties took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
),
clocks_getunit
());
message
(
"Reading
initial conditions took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
)
,
clocks_getunit
());
fflush
(
stdout
);
}
/* Discard gparts if we don't have gravity */
/* Discard gparts if we don't have gravity
* (Better implementation of i/o will come)*/
if
(
!
with_external_gravity
&&
!
with_self_gravity
)
{
free
(
gparts
);
gparts
=
NULL
;
...
...
@@ -300,18 +318,15 @@ int main(int argc, char *argv[]) {
/* Get the total number of particles across all nodes. */
long
long
N_total
[
2
]
=
{
0
,
0
};
#if defined(WITH_MPI)
N_long
[
0
]
=
Ngas
;
N_long
[
1
]
=
Ngpart
;
long
long
N_long
[
2
]
=
{
Ngas
,
Ngpart
};
MPI_Reduce
(
&
N_long
,
&
N_total
,
2
,
MPI_LONG_LONG
,
MPI_SUM
,
0
,
MPI_COMM_WORLD
);
if
(
myrank
==
0
)
message
(
"Read %lld gas particles and %lld gparts from the ICs"
,
N_total
[
0
],
N_total
[
1
]);
#else
N_total
[
0
]
=
Ngas
;
N_total
[
1
]
=
Ngpart
;
message
(
"Read %lld gas particles and %lld gparts from the ICs"
,
N_total
[
0
],
N_total
[
1
]);
#endif
if
(
myrank
==
0
)
message
(
"Read %lld gas particles and %lld gparts from the ICs."
,
N_total
[
0
],
N_total
[
1
]);
/* Apply h scaling */
const
double
scaling
=
...
...
@@ -340,23 +355,13 @@ int main(int argc, char *argv[]) {
}
}
return
0
;
double
h_max
;
/* Set default number of queues. */
// if (nr_queues < 0) nr_queues = nr_threads;
/* How vocal are we ? */
const
int
talking
=
(
verbose
==
1
&&
myrank
==
0
)
||
(
verbose
==
2
);
/* Initialize the space with this data. */
struct
space
s
;
bzero
(
&
s
,
sizeof
(
struct
space
));
const
double
h_max
=
parser_get_param_double
(
&
params
,
"SPH:max_smoothing_length"
);
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
space_init
(
&
s
,
dim
,
parts
,
gparts
,
Ngas
,
Ngpart
,
periodic
,
h_max
,
myrank
==
0
);
if
(
myrank
==
0
&&
verbose
)
{
space_init
(
&
s
,
dim
,
parts
,
gparts
,
Ngas
,
Ngpart
,
periodic
,
h_max
,
talking
);
if
(
talking
)
{
clocks_gettime
(
&
toc
);
message
(
"space_init took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
),
clocks_getunit
());
...
...
@@ -364,7 +369,7 @@ int main(int argc, char *argv[]) {
}
/* Say a few nice things about the space we just created. */
if
(
myrank
==
0
)
{
if
(
talking
)
{
message
(
"space dimensions are [ %.3f %.3f %.3f ]."
,
s
.
dim
[
0
],
s
.
dim
[
1
],
s
.
dim
[
2
]);
message
(
"space %s periodic."
,
s
.
periodic
?
"is"
:
"isn't"
);
...
...
@@ -376,14 +381,14 @@ int main(int argc, char *argv[]) {
}
/* Verify that each particle is in it's proper cell. */
if
(
myrank
==
0
)
{
icount
=
0
;
if
(
talking
)
{
int
icount
=
0
;
space_map_cells_pre
(
&
s
,
0
,
&
map_cellcheck
,
&
icount
);
message
(
"map_cellcheck picked up %i parts."
,
icount
);
}
/* Verify the maximal depth of cells. */
if
(
myrank
==
0
)
{
if
(
talking
)
{
int
data
[
2
]
=
{
s
.
maxdepth
,
0
};
space_map_cells_pre
(
&
s
,
0
,
&
map_maxdepth
,
data
);
message
(
"nr of cells at depth %i is %i."
,
data
[
0
],
data
[
1
]);
...
...
@@ -396,14 +401,11 @@ int main(int argc, char *argv[]) {
if
(
with_external_gravity
)
engine_policies
|=
engine_policy_external_gravity
;
if
(
with_cosmology
)
engine_policies
|=
engine_policy_cosmology
;
/* Initialize the engine with th
is
space. */
/* Initialize the engine with th
e
space
and policies
. */
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
if
(
myrank
==
0
)
message
(
"nr_nodes is %i."
,
nr_nodes
);
struct
engine
e
;
bzero
(
&
e
,
sizeof
(
struct
engine
));
engine_init
(
&
e
,
&
s
,
dt_max
,
nr_threads
,
nr_queues
,
nr_nodes
,
myrank
,
engine_policies
,
0
,
time_end
,
dt_min
,
dt_max
,
talking
);
if
(
myrank
==
0
&&
verbose
)
{
engine_init
(
&
e
,
&
s
,
&
params
,
nr_nodes
,
myrank
,
engine_policies
,
talking
);
if
(
talking
)
{
clocks_gettime
(
&
toc
);
message
(
"engine_init took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
),
clocks_getunit
());
...
...
@@ -416,6 +418,7 @@ int main(int argc, char *argv[]) {
engine_redistribute
(
&
e
);
#endif
int
with_outputs
=
1
;
if
(
with_outputs
)
{
/* Write the state of the system before starting time integration. */
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
...
...
@@ -448,7 +451,7 @@ int main(int argc, char *argv[]) {
message
(
"Running on %lld gas particles and %lld DM particles until t=%.3e with "
"%i threads and %i queues (dt_min=%.3e, dt_max=%.3e)..."
,
N_total
[
0
],
N_total
[
1
],
time
_e
nd
,
e
.
nr_threads
,
e
.
sched
.
nr_queues
,
N_total
[
0
],
N_total
[
1
],
e
.
time
E
nd
,
e
.
nr_threads
,
e
.
sched
.
nr_queues
,
e
.
dt_min
,
e
.
dt_max
);
fflush
(
stdout
);
}
...
...
@@ -459,10 +462,12 @@ int main(int argc, char *argv[]) {
/* Legend */
if
(
myrank
==
0
)
printf
(
"# Step Time time-step Number of updates Number of updates "
"# Step Time time-step Number of updates Number of
g-
updates "
"CPU Wall-clock time [%s]
\n
"
,
clocks_getunit
());
return
0
;
/* Let loose a runner on the space. */
for
(
int
j
=
0
;
!
engine_is_done
(
&
e
);
j
++
)
{
...
...
src/engine.c
View file @
704826e2
...
...
@@ -1648,7 +1648,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
),
...
...
@@ -2331,17 +2331,17 @@ static bool hyperthreads_present(void) {
* @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
,
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
;
...
...
@@ -2350,15 +2350,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
=
timeB
egin
;
e
->
timeEnd
=
timeEnd
;
e
->
timeOld
=
timeBegin
;
e
->
time
=
timeBegin
;
e
->
timeBegin
=
parser_get_param_double
(
params
,
"TimeIntegration:time_b
egin
"
)
;
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
;
...
...
@@ -2368,6 +2368,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
];
...
...
@@ -2466,11 +2471,11 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
if
(
e
->
nodeID
==
0
)
message
(
"Hydrodynamic scheme: %s"
,
SPH_IMPLEMENTATION
);
/* 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
)
...
...
@@ -2480,7 +2485,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 */
...
...
@@ -2499,12 +2504,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
);
...
...
@@ -2538,10 +2543,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
+
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
++
)
...
...
@@ -2551,10 +2555,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
;
...
...
@@ -2566,7 +2570,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
;
...
...
@@ -2585,7 +2589,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 );
...
...
src/engine.h
View file @
704826e2
...
...
@@ -38,6 +38,7 @@
#include
"scheduler.h"
#include
"space.h"
#include
"task.h"
#include
"parser.h"
#include
"partition.h"
/* Some constants. */
...
...
@@ -127,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
;
...
...
@@ -167,10 +168,8 @@ 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
,
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
);
...
...
src/space.c
View file @
704826e2
...
...
@@ -1281,6 +1281,9 @@ void space_init(struct space *s, double dim[3], struct part *parts,
struct
gpart
*
gparts
,
size_t
Ngas
,
size_t
Ngpart
,
int
periodic
,
double
h_max
,
int
verbose
)
{
/* Clean-up everything */
bzero
(
s
,
sizeof
(
struct
space
));
/* Store everything in the space. */
s
->
dim
[
0
]
=
dim
[
0
];
s
->
dim
[
1
]
=
dim
[
1
];
...
...
@@ -1293,7 +1296,7 @@ void space_init(struct space *s, double dim[3], struct part *parts,
s
->
size_gparts
=
Ngpart
;
s
->
gparts
=
gparts
;
s
->
cell_min
=
h_max
;
s
->
nr_queues
=
1
;
s
->
nr_queues
=
1
;
/* Temporary value until engine construction */
s
->
size_parts_foreign
=
0
;
/* Check that all the gas particle positions are reasonable, wrap if periodic.
...
...
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