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
b562e3d8
Commit
b562e3d8
authored
Mar 04, 2017
by
Matthieu Schaller
Browse files
Simplified the calculation of active/inactive by pre-computing the largest active time-bin
parent
52c52f4d
Changes
5
Hide whitespace changes
Inline
Side-by-side
examples/main.c
View file @
b562e3d8
...
...
@@ -602,7 +602,7 @@ int main(int argc, char *argv[]) {
clocks_getunit
());
/* Main simulation loop */
for
(
int
j
=
0
;
!
engine_is_done
(
&
e
)
&&
e
.
step
!=
nsteps
;
j
++
)
{
for
(
int
j
=
0
;
!
engine_is_done
(
&
e
)
&&
e
.
step
-
1
!=
nsteps
;
j
++
)
{
/* Reset timers */
timers_reset
(
timers_mask_all
);
...
...
src/active.h
View file @
b562e3d8
...
...
@@ -105,10 +105,12 @@ __attribute__((always_inline)) INLINE static int cell_is_all_active(
__attribute__
((
always_inline
))
INLINE
static
int
part_is_active
(
const
struct
part
*
p
,
const
struct
engine
*
e
)
{
const
integertime_t
ti_current
=
e
->
ti_current
;
const
integertime_t
ti_end
=
get_integer_time_end
(
ti_current
,
p
->
time_bin
)
;
const
timebin_t
max_active_bin
=
e
->
max_active_bin
;
const
timebin_t
part_bin
=
p
->
time_bin
;
#ifdef SWIFT_DEBUG_CHECKS
const
integertime_t
ti_current
=
e
->
ti_current
;
const
integertime_t
ti_end
=
get_integer_time_end
(
ti_current
,
p
->
time_bin
);
if
(
ti_end
<
ti_current
)
error
(
"particle in an impossible time-zone! p->ti_end=%lld "
...
...
@@ -116,7 +118,7 @@ __attribute__((always_inline)) INLINE static int part_is_active(
ti_end
,
ti_current
);
#endif
return
(
ti_end
==
ti_current
);
return
(
part_bin
<=
max_active_bin
);
}
/**
...
...
@@ -129,10 +131,13 @@ __attribute__((always_inline)) INLINE static int part_is_active(
__attribute__
((
always_inline
))
INLINE
static
int
gpart_is_active
(
const
struct
gpart
*
gp
,
const
struct
engine
*
e
)
{
const
timebin_t
max_active_bin
=
e
->
max_active_bin
;
const
timebin_t
gpart_bin
=
gp
->
time_bin
;
#ifdef SWIFT_DEBUG_CHECKS
const
integertime_t
ti_current
=
e
->
ti_current
;
const
integertime_t
ti_end
=
get_integer_time_end
(
ti_current
,
gp
->
time_bin
);
#ifdef SWIFT_DEBUG_CHECKS
if
(
ti_end
<
ti_current
)
error
(
"g-particle in an impossible time-zone! gp->ti_end=%lld "
...
...
@@ -140,7 +145,7 @@ __attribute__((always_inline)) INLINE static int gpart_is_active(
ti_end
,
ti_current
);
#endif
return
(
ti_end
==
ti_current
);
return
(
gpart_bin
<=
max_active_bin
);
}
/**
...
...
@@ -153,10 +158,13 @@ __attribute__((always_inline)) INLINE static int gpart_is_active(
__attribute__
((
always_inline
))
INLINE
static
int
spart_is_active
(
const
struct
spart
*
sp
,
const
struct
engine
*
e
)
{
const
timebin_t
max_active_bin
=
e
->
max_active_bin
;
const
timebin_t
spart_bin
=
sp
->
time_bin
;
#ifdef SWIFT_DEBUG_CHECKS
const
integertime_t
ti_current
=
e
->
ti_current
;
const
integertime_t
ti_end
=
get_integer_time_end
(
ti_current
,
sp
->
time_bin
);
#ifdef SWIFT_DEBUG_CHECKS
if
(
ti_end
<
ti_current
)
error
(
"s-particle in an impossible time-zone! sp->ti_end=%lld "
...
...
@@ -164,7 +172,7 @@ __attribute__((always_inline)) INLINE static int spart_is_active(
ti_end
,
ti_current
);
#endif
return
(
ti_end
==
ti_current
);
return
(
spart_bin
<=
max_active_bin
);
}
/* Are cells / particles active for kick1 tasks ? */
...
...
@@ -201,11 +209,14 @@ __attribute__((always_inline)) INLINE static int cell_is_starting(
__attribute__
((
always_inline
))
INLINE
static
int
part_is_starting
(
const
struct
part
*
p
,
const
struct
engine
*
e
)
{
const
timebin_t
max_active_bin
=
e
->
max_active_bin
;
const
timebin_t
part_bin
=
p
->
time_bin
;
#ifdef SWIFT_DEBUG_CHECKS
const
integertime_t
ti_current
=
e
->
ti_current
;
const
integertime_t
ti_beg
=
get_integer_time_begin
(
ti_current
+
1
,
p
->
time_bin
);
#ifdef SWIFT_DEBUG_CHECKS
if
(
ti_beg
>
ti_current
)
error
(
"particle in an impossible time-zone! p->ti_beg=%lld "
...
...
@@ -213,7 +224,7 @@ __attribute__((always_inline)) INLINE static int part_is_starting(
ti_beg
,
ti_current
);
#endif
return
(
ti_beg
==
ti_current
);
return
(
part_bin
<=
max_active_bin
);
}
/**
...
...
@@ -226,11 +237,14 @@ __attribute__((always_inline)) INLINE static int part_is_starting(
__attribute__
((
always_inline
))
INLINE
static
int
gpart_is_starting
(
const
struct
gpart
*
gp
,
const
struct
engine
*
e
)
{
const
timebin_t
max_active_bin
=
e
->
max_active_bin
;
const
timebin_t
gpart_bin
=
gp
->
time_bin
;
#ifdef SWIFT_DEBUG_CHECKS
const
integertime_t
ti_current
=
e
->
ti_current
;
const
integertime_t
ti_beg
=
get_integer_time_begin
(
ti_current
+
1
,
gp
->
time_bin
);
#ifdef SWIFT_DEBUG_CHECKS
if
(
ti_beg
>
ti_current
)
error
(
"g-particle in an impossible time-zone! gp->ti_beg=%lld "
...
...
@@ -238,7 +252,7 @@ __attribute__((always_inline)) INLINE static int gpart_is_starting(
ti_beg
,
ti_current
);
#endif
return
(
ti_beg
==
ti_current
);
return
(
gpart_bin
<=
max_active_bin
);
}
/**
...
...
@@ -251,11 +265,14 @@ __attribute__((always_inline)) INLINE static int gpart_is_starting(
__attribute__
((
always_inline
))
INLINE
static
int
spart_is_starting
(
const
struct
spart
*
sp
,
const
struct
engine
*
e
)
{
const
timebin_t
max_active_bin
=
e
->
max_active_bin
;
const
timebin_t
spart_bin
=
sp
->
time_bin
;
#ifdef SWIFT_DEBUG_CHECKS
const
integertime_t
ti_current
=
e
->
ti_current
;
const
integertime_t
ti_beg
=
get_integer_time_begin
(
ti_current
+
1
,
sp
->
time_bin
);
#ifdef SWIFT_DEBUG_CHECKS
if
(
ti_beg
>
ti_current
)
error
(
"s-particle in an impossible time-zone! sp->ti_beg=%lld "
...
...
@@ -263,6 +280,6 @@ __attribute__((always_inline)) INLINE static int spart_is_starting(
ti_beg
,
ti_current
);
#endif
return
(
ti_beg
==
ti_current
);
return
(
spart_bin
<=
max_active_bin
);
}
#endif
/* SWIFT_ACTIVE_H */
src/engine.c
View file @
b562e3d8
...
...
@@ -2804,6 +2804,18 @@ void engine_print_stats(struct engine *e) {
const
ticks
tic
=
getticks
();
#ifdef SWIFT_DEBUG_CHECKS
/* Check that all cells have been drifted to the current time.
* That can include cells that have not
* previously been active on this rank. */
space_check_drift_point
(
e
->
s
,
e
->
ti_current
);
/* Be verbose about this */
message
(
"Saving statistics at t=%e."
,
e
->
time
);
#else
if
(
e
->
verbose
)
message
(
"Saving statistics at t=%e."
,
e
->
time
);
#endif
e
->
save_stats
=
0
;
struct
statistics
stats
;
...
...
@@ -3010,7 +3022,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs) {
#endif
/* Ready to go */
e
->
step
=
-
1
;
e
->
step
=
0
;
e
->
forcerebuild
=
1
;
e
->
wallclock_time
=
(
float
)
clocks_diff
(
&
time1
,
&
time2
);
...
...
@@ -3031,20 +3043,12 @@ void engine_step(struct engine *e) {
e
->
tic_step
=
getticks
();
/* Move forward in time */
e
->
ti_old
=
e
->
ti_current
;
e
->
ti_current
=
e
->
ti_end_min
;
e
->
step
+=
1
;
e
->
time
=
e
->
ti_current
*
e
->
timeBase
+
e
->
timeBegin
;
e
->
timeOld
=
e
->
ti_old
*
e
->
timeBase
+
e
->
timeBegin
;
e
->
timeStep
=
(
e
->
ti_current
-
e
->
ti_old
)
*
e
->
timeBase
;
if
(
e
->
nodeID
==
0
)
{
/* Print some information to the screen */
printf
(
" %6d %14e %14e %10zu %10zu %10zu %21.3f
\n
"
,
e
->
step
,
e
->
time
,
e
->
timeStep
,
e
->
updates
,
e
->
g_updates
,
e
->
s_updates
,
e
->
wallclock_time
);
printf
(
" %6d %14e
%d
%14e %10zu %10zu %10zu %21.3f
\n
"
,
e
->
step
,
e
->
time
,
e
->
max_active_bin
,
e
->
timeStep
,
e
->
updates
,
e
->
g_updates
,
e
->
s_updates
,
e
->
wallclock_time
);
fflush
(
stdout
);
fprintf
(
e
->
file_timesteps
,
" %6d %14e %14e %10zu %10zu %10zu %21.3f
\n
"
,
...
...
@@ -3053,6 +3057,15 @@ void engine_step(struct engine *e) {
fflush
(
e
->
file_timesteps
);
}
/* Move forward in time */
e
->
ti_old
=
e
->
ti_current
;
e
->
ti_current
=
e
->
ti_end_min
;
e
->
max_active_bin
=
get_max_active_bin
(
e
->
ti_end_min
);
e
->
step
+=
1
;
e
->
time
=
e
->
ti_current
*
e
->
timeBase
+
e
->
timeBegin
;
e
->
timeOld
=
e
->
ti_old
*
e
->
timeBase
+
e
->
timeBegin
;
e
->
timeStep
=
(
e
->
ti_current
-
e
->
ti_old
)
*
e
->
timeBase
;
/* Prepare the tasks to be launched, rebuild or repartition if needed. */
engine_prepare
(
e
);
...
...
@@ -3566,6 +3579,7 @@ void engine_init(struct engine *e, struct space *s,
e
->
time
=
e
->
timeBegin
;
e
->
ti_old
=
0
;
e
->
ti_current
=
0
;
e
->
max_active_bin
=
num_time_bins
;
e
->
timeStep
=
0
.;
e
->
timeBase
=
0
.;
e
->
timeBase_inv
=
0
.;
...
...
src/engine.h
View file @
b562e3d8
...
...
@@ -122,6 +122,9 @@ struct engine {
double
time
;
integertime_t
ti_current
;
/* The highest active bin at this time */
timebin_t
max_active_bin
;
/* Time step */
double
timeStep
;
...
...
src/timeline.h
View file @
b562e3d8
...
...
@@ -37,7 +37,8 @@ typedef char timebin_t;
/*! The maximal number of timesteps in a simulation */
#define max_nr_timesteps (1LL << (num_time_bins + 1))
#define time_bin_inactive (num_time_bins + 2)
/*! Fictious time-bin to hold inhibited particles */
#define time_bin_inhibited (num_time_bins + 2)
/**
* @brief Returns the integer time interval corresponding to a time bin
...
...
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