Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
f1c5e800
Commit
f1c5e800
authored
8 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Update the global statistics atomically
parent
df254615
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!269
Stats after kick
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/engine.c
+16
-17
16 additions, 17 deletions
src/engine.c
src/statistics.c
+20
-48
20 additions, 48 deletions
src/statistics.c
src/statistics.h
+4
-0
4 additions, 0 deletions
src/statistics.h
with
40 additions
and
65 deletions
src/engine.c
+
16
−
17
View file @
f1c5e800
...
...
@@ -2503,19 +2503,18 @@ void engine_print_stats(struct engine *e) {
/* } */
#endif
//
const double
e
_tot =
e_kin + e_int + e
_pot;
const
double
E
_tot
=
stats
.
E_kin
+
stats
.
E_int
+
stats
.
E
_pot
;
/* Print info */
/* if (e->nodeID == 0) { */
/* fprintf(e->file_stats, */
/* " %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e
* %14e " */
/* "%14e\n", */
/* e->time, mass, e_tot, e_kin, e_int, e_pot, e_rad, entropy,
* mom[0], */
/* mom[1], mom[2], ang_mom[0], ang_mom[1], ang_mom[2]); */
/* fflush(e->file_stats); */
/* } */
if
(
e
->
nodeID
==
0
)
{
fprintf
(
e
->
file_stats
,
" %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e %14e "
"%14e
\n
"
,
e
->
time
,
stats
.
mass
,
E_tot
,
stats
.
E_kin
,
stats
.
E_int
,
stats
.
E_pot
,
stats
.
E_rad
,
stats
.
entropy
,
stats
.
mom
[
0
],
stats
.
mom
[
1
],
stats
.
mom
[
2
],
stats
.
ang_mom
[
0
],
stats
.
ang_mom
[
1
],
stats
.
ang_mom
[
2
]);
fflush
(
e
->
file_stats
);
}
if
(
e
->
verbose
)
message
(
"took %.3f %s."
,
clocks_from_ticks
(
getticks
()
-
tic
),
...
...
@@ -2726,12 +2725,6 @@ void engine_step(struct engine *e) {
fflush
(
e
->
file_timesteps
);
}
/* Save some statistics */
if
(
e
->
time
-
e
->
timeLastStatistics
>=
e
->
deltaTimeStatistics
)
{
engine_print_stats
(
e
);
e
->
timeLastStatistics
+=
e
->
deltaTimeStatistics
;
}
/* Drift only the necessary particles, that means all particles
* if we are about to repartition. */
int
repart
=
(
e
->
forcerepart
!=
REPART_NONE
);
...
...
@@ -2828,6 +2821,12 @@ void engine_step(struct engine *e) {
engine_launch
(
e
,
e
->
nr_threads
,
mask
,
submask
);
TIMER_TOC
(
timer_runners
);
/* Save some statistics */
if
(
e
->
time
-
e
->
timeLastStatistics
>=
e
->
deltaTimeStatistics
)
{
engine_print_stats
(
e
);
e
->
timeLastStatistics
+=
e
->
deltaTimeStatistics
;
}
TIMER_TOC2
(
timer_step
);
clocks_gettime
(
&
time2
);
...
...
This diff is collapsed.
Click to expand it.
src/statistics.c
+
20
−
48
View file @
f1c5e800
...
...
@@ -27,6 +27,7 @@
#include
"statistics.h"
/* Local headers. */
#include
"atomic.h"
#include
"cooling.h"
#include
"engine.h"
#include
"error.h"
...
...
@@ -38,8 +39,6 @@
*/
struct
index_data
{
const
struct
space
*
s
;
int
chunk_size
;
int
num_threads
;
struct
statistics
*
stats
;
};
...
...
@@ -50,10 +49,9 @@ void stats_collect_part_mapper(void *map_data, int nr_parts, void *extra_data) {
const
struct
space
*
s
=
data
->
s
;
struct
part
*
restrict
parts
=
(
struct
part
*
)
map_data
;
struct
xpart
*
restrict
xparts
=
s
->
xparts
+
(
ptrdiff_t
)(
parts
-
s
->
parts
);
const
int
chunk_size
=
data
->
chunk_size
;
const
int
num_threads
=
data
->
num_threads
;
const
int
ti_current
=
s
->
e
->
ti_current
;
const
double
timeBase
=
s
->
e
->
timeBase
;
struct
statistics
*
const
global_stats
=
data
->
stats
;
/* Local accumulator */
struct
statistics
stats
;
...
...
@@ -97,61 +95,35 @@ void stats_collect_part_mapper(void *map_data, int nr_parts, void *extra_data) {
stats
.
entropy
+=
m
*
hydro_get_entropy
(
p
,
dt
);
}
/* Where do we write back ? */
const
int
thread_id
=
((
ptrdiff_t
)(
parts
-
s
->
parts
)
/
chunk_size
)
%
num_threads
;
/* Now write back to memory */
data
->
stats
[
thread_id
].
E_kin
+=
stats
.
E_kin
;
data
->
stats
[
thread_id
].
E_int
+=
stats
.
E_int
;
data
->
stats
[
thread_id
].
E_pot
+=
stats
.
E_pot
;
data
->
stats
[
thread_id
].
E_rad
+=
stats
.
E_rad
;
data
->
stats
[
thread_id
].
entropy
+=
stats
.
entropy
;
data
->
stats
[
thread_id
].
mass
+=
stats
.
mass
;
data
->
stats
[
thread_id
].
mom
[
0
]
+=
stats
.
mom
[
0
];
data
->
stats
[
thread_id
].
mom
[
1
]
+=
stats
.
mom
[
1
];
data
->
stats
[
thread_id
].
mom
[
2
]
+=
stats
.
mom
[
2
];
data
->
stats
[
thread_id
].
ang_mom
[
0
]
+=
stats
.
ang_mom
[
0
];
data
->
stats
[
thread_id
].
ang_mom
[
1
]
+=
stats
.
ang_mom
[
1
];
data
->
stats
[
thread_id
].
ang_mom
[
2
]
+=
stats
.
ang_mom
[
2
];
if
(
lock_lock
(
&
global_stats
->
lock
)
==
0
)
{
global_stats
->
E_int
+=
stats
.
E_int
;
global_stats
->
E_pot
+=
stats
.
E_pot
;
global_stats
->
E_rad
+=
stats
.
E_rad
;
global_stats
->
entropy
+=
stats
.
entropy
;
global_stats
->
mass
+=
stats
.
mass
;
global_stats
->
mom
[
0
]
+=
stats
.
mom
[
0
];
global_stats
->
mom
[
1
]
+=
stats
.
mom
[
1
];
global_stats
->
mom
[
2
]
+=
stats
.
mom
[
2
];
global_stats
->
ang_mom
[
0
]
+=
stats
.
ang_mom
[
0
];
global_stats
->
ang_mom
[
1
]
+=
stats
.
ang_mom
[
1
];
global_stats
->
ang_mom
[
2
]
+=
stats
.
ang_mom
[
2
];
}
if
(
lock_unlock
(
&
global_stats
->
lock
)
!=
0
)
error
(
"Failed to unlock stats holder."
);
}
void
stats_collect
(
const
struct
space
*
s
,
struct
statistics
*
stats
)
{
const
int
num_threads
=
s
->
e
->
threadpool
.
num_threads
;
const
int
chunk_size
=
s
->
nr_parts
/
num_threads
;
const
int
chunk_size
=
1000
;
/* Prepare the data */
struct
index_data
extra_data
;
extra_data
.
s
=
s
;
extra_data
.
chunk_size
=
chunk_size
;
extra_data
.
num_threads
=
num_threads
;
extra_data
.
stats
=
malloc
(
sizeof
(
struct
statistics
)
*
num_threads
);
if
(
extra_data
.
stats
==
NULL
)
error
(
"Impossible to allocate memory for statistics"
);
bzero
(
&
extra_data
.
stats
,
sizeof
(
struct
statistics
)
*
num_threads
);
extra_data
.
stats
=
stats
;
/* Run parallel collection of statistics */
threadpool_map
(
&
s
->
e
->
threadpool
,
stats_collect_part_mapper
,
s
->
parts
,
s
->
nr_parts
,
sizeof
(
struct
part
),
chunk_size
,
&
extra_data
);
/* Collect data from all the threads in the pool */
for
(
int
i
=
0
;
i
<
num_threads
;
++
i
)
{
stats
->
E_kin
+=
extra_data
.
stats
[
i
].
E_kin
;
stats
->
E_int
+=
extra_data
.
stats
[
i
].
E_int
;
stats
->
E_pot
+=
extra_data
.
stats
[
i
].
E_pot
;
stats
->
E_rad
+=
extra_data
.
stats
[
i
].
E_rad
;
stats
->
entropy
+=
extra_data
.
stats
[
i
].
entropy
;
stats
->
mass
+=
extra_data
.
stats
[
i
].
mass
;
stats
->
mom
[
0
]
+=
extra_data
.
stats
[
i
].
mom
[
0
];
stats
->
mom
[
1
]
+=
extra_data
.
stats
[
i
].
mom
[
1
];
stats
->
mom
[
2
]
+=
extra_data
.
stats
[
i
].
mom
[
2
];
stats
->
ang_mom
[
0
]
+=
extra_data
.
stats
[
i
].
ang_mom
[
0
];
stats
->
ang_mom
[
1
]
+=
extra_data
.
stats
[
i
].
ang_mom
[
1
];
stats
->
ang_mom
[
2
]
+=
extra_data
.
stats
[
i
].
ang_mom
[
2
];
}
/* Free stuff */
free
(
extra_data
.
stats
);
}
This diff is collapsed.
Click to expand it.
src/statistics.h
+
4
−
0
View file @
f1c5e800
...
...
@@ -23,6 +23,7 @@
#include
"../config.h"
/* Local headers. */
#include
"lock.h"
#include
"space.h"
/**
...
...
@@ -53,6 +54,9 @@ struct statistics {
/*! Angular momentum */
double
ang_mom
[
3
];
/*! Lock for threaded access */
swift_lock_type
lock
;
};
void
stats_collect
(
const
struct
space
*
s
,
struct
statistics
*
stats
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment