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
63553400
Commit
63553400
authored
Feb 16, 2018
by
lhausamm
Committed by
Loic Hausammann
Oct 31, 2018
Browse files
Clean logger code
parent
e12b3e21
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/dump.c
View file @
63553400
...
...
@@ -85,13 +85,8 @@ void dump_ensure(struct dump *d, size_t size) {
/* Re-map starting at the end of the file. */
if
((
d
->
data
=
mmap
(
NULL
,
d
->
size
,
PROT_WRITE
,
MAP_SHARED
,
d
->
fd
,
d
->
file_offset
))
==
MAP_FAILED
)
{
size_t
mega
=
1e6
;
if
(
d
->
size
>
mega
)
error
(
"Failed to allocate map of size %zi Mbytes (%s)."
,
d
->
size
/
mega
,
strerror
(
errno
));
else
error
(
"Failed to allocate map of size %zi bytes (%s)."
,
d
->
size
,
strerror
(
errno
));
error
(
"Failed to allocate map of size %zi bytes (%s)."
,
d
->
size
,
strerror
(
errno
));
}
}
...
...
src/gravity/Default/gravity.h
View file @
63553400
...
...
@@ -22,11 +22,13 @@
#include
<float.h>
/* Local includes. */
#include
"cosmology.h"
#include
"gravity_properties.h"
#include
"kernel_gravity.h"
#include
"minmax.h"
/**
* @brief Returns the mass of a particle
*
...
...
@@ -228,11 +230,6 @@ __attribute__((always_inline)) INLINE static void gravity_first_init_gpart(
gp
->
time_bin
=
0
;
gravity_init_gpart
(
gp
);
#ifdef WITH_LOGGER
gp
->
last_output
=
SHRT_MAX
;
gp
->
last_offset
=
0
;
#endif
}
#endif
/* SWIFT_DEFAULT_GRAVITY_H */
src/gravity/Default/gravity_io.h
View file @
63553400
...
...
@@ -117,32 +117,4 @@ INLINE static void darkmatter_write_particles(const struct gpart* gparts,
UNIT_CONV_NO_UNITS
,
gparts
,
id_or_neg_offset
);
}
/**
* @brief Specifies which g-particle fields to write to a dataset
*
* @param gparts The g-particle array.
* @param list The list of i/o properties to write.
* @param num_fields The number of i/o fields to write.
*
* In this version, we only want the ids and the offset.
*/
void
darkmatter_write_index
(
struct
gpart
*
gparts
,
struct
io_props
*
list
,
int
*
num_fields
)
{
#ifdef WITH_LOGGER
/* Say how much we want to read */
*
num_fields
=
2
;
/* List what we want to read */
list
[
0
]
=
io_make_output_field
(
"ParticleIDs"
,
ULONGLONG
,
1
,
UNIT_CONV_NO_UNITS
,
gparts
,
id_or_neg_offset
);
list
[
1
]
=
io_make_output_field
(
"Offset"
,
ULONGLONG
,
1
,
UNIT_CONV_NO_UNITS
,
gparts
,
last_offset
);
#else
error
(
"Cannot write index without logger"
);
#endif
}
#endif
/* SWIFT_DEFAULT_GRAVITY_IO_H */
src/gravity/Default/gravity_part.h
View file @
63553400
...
...
@@ -75,14 +75,6 @@ struct gpart {
double
potential_exact
;
#endif
#ifdef WITH_LOGGER
/* Number of time step since last output */
short
int
last_output
;
/* offset at last writing */
size_t
last_offset
;
#endif
}
SWIFT_STRUCT_ALIGN
;
#endif
/* SWIFT_DEFAULT_GRAVITY_PART_H */
src/hydro/Gadget2/hydro.h
View file @
63553400
...
...
@@ -35,6 +35,7 @@
#include
"approx_math.h"
#include
"cosmology.h"
#include
"dimension.h"
#include
"engine.h"
#include
"equation_of_state.h"
#include
"hydro_properties.h"
#include
"hydro_space.h"
...
...
@@ -777,4 +778,19 @@ hydro_set_init_internal_energy(struct part *p, float u_init) {
p
->
entropy
=
u_init
;
}
#ifdef WITH_LOGGER
/**
* @brief Should this particle write its data now ?
*
* @param xp The #xpart.
* @param e The #engine containing information about the current time.
* @return 1 if the #part should write, 0 otherwise.
*/
__attribute__
((
always_inline
))
INLINE
static
int
xpart_should_write
(
const
struct
xpart
*
xp
,
const
struct
engine
*
e
)
{
return
(
xp
->
last_output
>
e
->
logger_max_steps
);
}
#endif
#endif
/* SWIFT_GADGET2_HYDRO_H */
src/logger.c
View file @
63553400
...
...
@@ -51,6 +51,36 @@ const unsigned int logger_data_size[logger_data_count] = {
1
,
};
/**
* @brief write chunk header
*
* @param buff The writing buffer
* @param mask The mask to write
* @param offset The old offset
* @param offset_new The new offset
*
* @return updated buff
*/
__attribute__
((
always_inline
))
INLINE
static
char
*
logger_write_chunk_header
(
char
*
buff
,
const
unsigned
int
*
mask
,
const
size_t
*
offset
,
const
size_t
offset_new
)
{
memcpy
(
buff
,
mask
,
logger_size_mask
);
buff
+=
logger_size_mask
;
size_t
diff_offset
=
offset_new
-
*
offset
;
memcpy
(
buff
,
&
diff_offset
,
logger_size_offset
);
buff
+=
logger_size_offset
;
return
buff
;
}
/**
* @brief write a data to the file
*
* @param d #dump file
* @param offset offset at which to write
* @param size number of bytes to write
* @param p pointer to the data
*/
void
logger_write_data
(
struct
dump
*
d
,
size_t
*
offset
,
const
size_t
size
,
void
*
const
p
)
{
char
*
buff
=
dump_get
(
d
,
size
,
offset
);
...
...
@@ -58,7 +88,16 @@ void logger_write_data(struct dump *d, size_t *offset, const size_t size, void *
}
/**
* WARNING: name should be at max of size log->name
* @brief write a general data to the file
*
* write data in the following order: name, data type, data
*
* @param d #dump file
* @param log #logger_const file format informations
* @param offset offset at which to write (moved by the data size)
* @param p pointer to the data
* @param name data name (should be smaller than log->name)
* @param data_type #logger_datatype to write
*/
void
logger_write_general_data
(
struct
dump
*
d
,
struct
logger_const
*
log
,
size_t
*
offset
,
void
*
p
,
char
*
name
,
size_t
data_type
)
...
...
@@ -271,11 +310,15 @@ void logger_log_gpart(struct gpart *p, unsigned int mask, size_t *offset,
*
offset
=
offset_new
;
}
/**
* @brief write a timestamp
*
* @param timestamp time to write
* @param offset In: previous offset, out: offset of this chunk
* @param dump #dump file
*/
void
logger_log_timestamp
(
integertime_t
timestamp
,
size_t
*
offset
,
struct
dump
*
dump
)
{
#ifdef SWIFT_DEBUG_CHECKS
message
(
"writing timestamp: %llu"
,
timestamp
);
#endif
/* Start by computing the size of the message. */
const
int
size
=
logger_size
(
logger_mask_timestamp
);
...
...
@@ -295,6 +338,12 @@ void logger_log_timestamp(integertime_t timestamp, size_t *offset,
}
/**
* @brief ensure that the input parameter logger size is large enough
*
* @param total_nr_nparts total number of particle
* @param logger_size requested file size upate
*/
void
logger_ensure_size
(
size_t
total_nr_parts
,
size_t
logger_size
)
{
size_t
limit
,
i
;
struct
logger_const
log_const
;
...
...
@@ -304,7 +353,8 @@ void logger_ensure_size(size_t total_nr_parts, size_t logger_size) {
limit
=
log_const
.
offset
+
log_const
.
mask
;
for
(
i
=
0
;
i
<
log_const
.
nber_mask
;
i
++
)
{
limit
+=
log_const
.
masks_size
[
i
];
if
(
log_const
.
masks
[
i
]
!=
logger_mask_timestamp
)
limit
+=
log_const
.
masks_size
[
i
];
}
limit
*=
total_nr_parts
;
...
...
@@ -397,6 +447,11 @@ void logger_write_file_header(struct dump *dump, struct engine *e) {
free
(
name
);
}
/**
* @brief initialize the #logger_const with the format informations
*
* @param log_const #logger_const to initialize
*/
void
logger_const_init
(
struct
logger_const
*
log_const
)
{
log_const
->
name
=
20
;
log_const
->
offset
=
7
;
...
...
@@ -471,6 +526,11 @@ void logger_const_init(struct logger_const* log_const) {
}
/**
* @brief free the memory allocated when initializing the #logger_const
*
* @param log_const #logger_const to clean
*/
void
logger_const_free
(
struct
logger_const
*
log_const
)
{
free
(
log_const
->
masks
);
free
(
log_const
->
masks_name
);
...
...
src/logger.h
View file @
63553400
...
...
@@ -78,16 +78,19 @@ struct dump;
#define logger_mask_consts 64
#define logger_mask_timestamp 128
#define logger_size_mask 1 // size of the mask
#define logger_size_offset 7 // size of the offset
/* header constants
* Thoses are definitions from the format and therefore should not be changed!
* Size in bytes
*/
#define LOGGER_VERSION_SIZE 20 // size of the version message
#define LOGGER_NAME_SIZE 2 // size of the labels size
#define LOGGER_MASK_SIZE 1 // size of the masks size
#define LOGGER_NBER_SIZE 1 // size of the number of elements
size
#define LOGGER_NAME_SIZE 2 // size of the labels size
information
#define LOGGER_MASK_SIZE 1 // size of the masks size
information
#define LOGGER_NBER_SIZE 1 // size of the number of elements
information
#define LOGGER_OFFSET_SIZE 1// size of the offset size information
#define LOGGER_DATATYPE_SIZE 1
#define LOGGER_DATATYPE_SIZE 1
// size of the data type information
extern
char
LOGGER_VERSION
[
LOGGER_VERSION_SIZE
];
...
...
@@ -132,66 +135,6 @@ void logger_const_init(struct logger_const* log_const);
void
logger_const_free
(
struct
logger_const
*
log_const
);
void
logger_ensure_size
(
size_t
total_nr_parts
,
size_t
logger_size
);
/**
* @brief write chunk header
*
* @param buff The writing buffer
* @param maks The mask to write
* @param offset The old offset
* @param offset_new The new offset
*
* @return updated buff
*/
__attribute__
((
always_inline
))
INLINE
static
char
*
logger_write_chunk_header
(
char
*
buff
,
const
unsigned
int
*
mask
,
const
size_t
*
offset
,
const
size_t
offset_new
)
{
memcpy
(
buff
,
mask
,
1
);
buff
+=
1
;
size_t
diff_offset
=
offset_new
-
*
offset
;
memcpy
(
buff
,
&
diff_offset
,
7
);
buff
+=
7
;
return
buff
;
}
/**
* @brief Should this particle write its data now ?
*
* @param xp The #xpart.
* @param e The #engine containing information about the current time.
* @return 1 if the #part should write, 0 otherwise.
*/
__attribute__
((
always_inline
))
INLINE
static
int
xpart_should_write
(
const
struct
xpart
*
xp
,
const
struct
engine
*
e
)
{
return
(
xp
->
last_output
>
e
->
logger_max_steps
);
}
/**
* @brief Should this particle write its data now ?
*
* @param p The #gpart.
* @param e The #engine containing information about the current time.
* @return 1 if the #gpart should write, 0 otherwise.
*/
__attribute__
((
always_inline
))
INLINE
static
int
gpart_should_write
(
const
struct
gpart
*
gp
,
const
struct
engine
*
e
)
{
return
(
gp
->
last_output
>
e
->
logger_max_steps
);
}
/**
* @brief Should this particle write its data now ?
*
* @param p The #spart.
* @param e The #engine containing information about the current time.
* @return 1 if the #spart should write, 0 otherwise.
*/
__attribute__
((
always_inline
))
INLINE
static
int
spart_should_write
(
const
struct
spart
*
sp
,
const
struct
engine
*
e
)
{
return
(
sp
->
last_output
>
e
->
logger_max_steps
);
}
#endif
/* WITH_LOGGER */
#endif
/* SWIFT_LOGGER_H */
src/logger_io.c
View file @
63553400
...
...
@@ -838,7 +838,7 @@ void write_index_single(struct engine* e, const char* baseName,
int
periodic
=
e
->
s
->
periodic
;
int
numFiles
=
1
;
struct
part
*
parts
=
e
->
s
->
parts
;
struct
gpart
*
gparts
=
e
->
s
->
gparts
;
//
struct gpart* gparts = e->s->gparts;
struct
gpart
*
dmparts
=
NULL
;
//struct spart* sparts = e->s->sparts;
static
int
outputCount
=
0
;
...
...
@@ -1009,20 +1009,9 @@ void write_index_single(struct engine* e, const char* baseName,
break
;
case
swift_type_dark_matter
:
/* Allocate temporary array */
if
(
posix_memalign
((
void
*
)
&
dmparts
,
gpart_align
,
Ndm
*
sizeof
(
struct
gpart
))
!=
0
)
error
(
"Error while allocating temporart memory for DM particles"
);
bzero
(
dmparts
,
Ndm
*
sizeof
(
struct
gpart
));
/* Collect the DM particles from gpart */
io_collect_dm_gparts
(
gparts
,
Ntot
,
dmparts
,
Ndm
);
/* Write DM particles */
N
=
Ndm
;
darkmatter_write_index
(
dmparts
,
list
,
&
num_fields
);
break
;
error
(
"TODO"
);
break
;
case
swift_type_star
:
N
=
Nstars
;
error
(
"TODO"
);
...
...
src/runner.c
View file @
63553400
...
...
@@ -2710,9 +2710,7 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) {
const
struct
engine
*
e
=
r
->
e
;
struct
part
*
restrict
parts
=
c
->
parts
;
struct
xpart
*
restrict
xparts
=
c
->
xparts
;
struct
gpart
*
restrict
gparts
=
c
->
gparts
;
const
int
count
=
c
->
count
;
const
int
gcount
=
c
->
gcount
;
/* Anything to do here? */
if
(
!
cell_is_starting_hydro
(
c
,
e
)
&&
!
cell_is_starting_gravity
(
c
,
e
))
...
...
@@ -2751,32 +2749,6 @@ void runner_do_logger(struct runner *r, struct cell *c, int timer) {
}
}
/* Loop over the gparts in this cell. */
for
(
int
k
=
0
;
k
<
gcount
;
k
++
)
{
/* Get a handle on the part. */
struct
gpart
*
restrict
gp
=
&
gparts
[
k
];
/* If particle needs to be kicked */
if
(
gpart_is_starting
(
gp
,
e
))
{
if
(
gpart_should_write
(
gp
,
e
))
{
/* Write particle */
logger_log_gpart
(
gp
,
logger_mask_x
|
logger_mask_v
|
logger_mask_a
|
logger_mask_h
|
logger_mask_consts
,
&
gp
->
last_offset
,
e
->
logger_dump
);
/* Set counter back to zero */
gp
->
last_output
=
0
;
}
else
{
/* Update counter */
gp
->
last_output
+=
1
;
}
}
}
}
if
(
timer
)
TIMER_TOC
(
timer_logger
);
...
...
src/stars/Default/stars_part.h
View file @
63553400
...
...
@@ -62,9 +62,6 @@ struct spart {
}
density
;
/* Number of time step since last output */
short
int
last_output
;
#ifdef SWIFT_DEBUG_CHECKS
/* Time of the last drift */
...
...
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