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
f0e93abf
Commit
f0e93abf
authored
Oct 02, 2017
by
lhausamm
Committed by
Loic Hausammann
Oct 31, 2018
Browse files
Split logger with hdf5 files
parent
13345589
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
configure.ac
View file @
f0e93abf
...
...
@@ -54,6 +54,19 @@ AX_COMPILER_VERSION
# Restrict support.
AC_C_RESTRICT
# logger
AC_ARG_ENABLE([logger],
[AS_HELP_STRING([--enable-logger],
[enable the logger output format]
)],
[with_logger="${enableval}"],
[with_logger="no"]
)
if test "$with_logger" = "yes"; then
AC_DEFINE([WITH_LOGGER], 1, [logger enabled])
fi
# Interprocedural optimization support. Needs special handling for linking and
# archiving as well as compilation with Intels, needs to be done before
# libtool is configured (to use correct LD).
...
...
@@ -1609,6 +1622,7 @@ AC_MSG_RESULT([
CPU profiler : $have_profiler
Pthread barriers : $have_pthread_barrier
VELOCIraptor enabled : $have_velociraptor
Logger : $with_logger
Hydro scheme : $with_hydro
Dimensionality : $with_dimension
...
...
src/Makefile.am
View file @
f0e93abf
...
...
@@ -48,7 +48,8 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \
dump.h logger.h active.h timeline.h xmf.h gravity_properties.h gravity_derivatives.h
\
gravity_softened_derivatives.h vector_power.h collectgroup.h hydro_space.h sort_part.h
\
chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h space_getsid.h utilities.h
\
mesh_gravity.h cbrt.h velociraptor_interface.h swift_velociraptor_part.h outputlist.h
mesh_gravity.h cbrt.h velociraptor_interface.h swift_velociraptor_part.h outputlist.h
\
logger_io.h
# Common source files
AM_SOURCES
=
space.c runner.c queue.c task.c cell.c engine.c
\
...
...
@@ -61,13 +62,14 @@ AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
part_type.c xmf.c gravity_properties.c gravity.c
\
collectgroup.c hydro_space.c equation_of_state.c
\
chemistry.c cosmology.c restart.c mesh_gravity.c velociraptor_interface.c
\
outputlist.c velociraptor_dummy.c
outputlist.c velociraptor_dummy.c
logger_io.c
# Include files for distribution, not installation.
nobase_noinst_HEADERS
=
align.h approx_math.h atomic.h barrier.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h
\
gravity_iact.h kernel_long_gravity.h vector.h cache.h runner_doiact.h runner_doiact_vec.h runner_doiact_grav.h
\
runner_doiact_nosort.h runner_doiact_stars.h units.h intrinsics.h minmax.h kick.h timestep.h drift.h
\
adiabatic_index.h io_properties.h dimension.h part_type.h periodic.h memswap.h dump.h logger.h sign.h
\
logger_io.h
\
gravity.h gravity_io.h gravity_cache.h
\
gravity/Default/gravity.h gravity/Default/gravity_iact.h gravity/Default/gravity_io.h
\
gravity/Default/gravity_debug.h gravity/Default/gravity_part.h
\
...
...
src/active.h
View file @
f0e93abf
...
...
@@ -444,43 +444,4 @@ __attribute__((always_inline)) INLINE static int spart_is_starting(
return
(
spart_bin
<=
max_active_bin
);
}
/**
* @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
/* SWIFT_ACTIVE_H */
src/engine.c
View file @
f0e93abf
...
...
@@ -67,6 +67,7 @@
#include
"gravity.h"
#include
"gravity_cache.h"
#include
"hydro.h"
#include
"logger_io.h"
#include
"map.h"
#include
"memswap.h"
#include
"minmax.h"
...
...
src/logger.c
View file @
f0e93abf
...
...
@@ -26,6 +26,7 @@
#include
<stdint.h>
#include
<stdlib.h>
#include
<string.h>
#include
<hdf5.h>
/* This object's header. */
#include
"logger.h"
...
...
@@ -35,6 +36,8 @@
#include
"dump.h"
#include
"error.h"
#include
"part.h"
#include
"units.h"
#include
"engine.h"
/**
* @brief Compute the size of a message given its mask.
...
...
src/logger.h
View file @
f0e93abf
...
...
@@ -21,6 +21,9 @@
/* Includes. */
#include
"part.h"
#include
"units.h"
#include
"engine.h"
#include
"common_io.h"
/* Forward declaration */
struct
dump
;
...
...
@@ -86,4 +89,45 @@ int logger_read_gpart(struct gpart *p, size_t *offset, const char *buff);
int
logger_read_timestamp
(
unsigned
long
long
int
*
t
,
size_t
*
offset
,
const
char
*
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
/* SWIFT_LOGGER_H */
src/logger_io.c
0 → 100644
View file @
f0e93abf
This diff is collapsed.
Click to expand it.
src/logger_io.h
0 → 100644
View file @
f0e93abf
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2012 Matthieu Schaller (matthieu.schaller@durham.ac.uk).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#ifndef SWIFT_LOGGER_IO_H
#define SWIFT_LOGGER_IO_H
/* Config parameters. */
#include
"../config.h"
#if defined(HAVE_HDF5) && !defined(WITH_MPI) && defined(WITH_LOGGER)
/* Includes. */
#include
"engine.h"
#include
"part.h"
#include
"units.h"
void
read_ic_single
(
char
*
fileName
,
const
struct
unit_system
*
internal_units
,
double
dim
[
3
],
struct
part
**
parts
,
struct
gpart
**
gparts
,
struct
spart
**
sparts
,
size_t
*
Ngas
,
size_t
*
Ndm
,
size_t
*
Nstars
,
int
*
periodic
,
int
*
flag_entropy
,
int
with_hydro
,
int
with_gravity
,
int
with_stars
,
int
dry_run
);
void
write_output_single
(
struct
engine
*
e
,
const
char
*
baseName
,
const
struct
unit_system
*
internal_units
,
const
struct
unit_system
*
snapshot_units
);
void
write_index_single
(
struct
engine
*
e
,
const
char
*
baseName
,
const
struct
unit_system
*
internal_units
,
const
struct
unit_system
*
snapshot_units
);
#endif
#endif
/* SWIFT_LOGGER_IO_H */
src/parallel_io.c
View file @
f0e93abf
...
...
@@ -21,7 +21,7 @@
/* Config parameters. */
#include
"../config.h"
#if defined(HAVE_HDF5) && defined(WITH_MPI) && defined(HAVE_PARALLEL_HDF5)
#if defined(HAVE_HDF5) && defined(WITH_MPI) && defined(HAVE_PARALLEL_HDF5)
&& !defined(WITH_LOGGER)
/* Some standard headers. */
#include
<hdf5.h>
...
...
src/serial_io.c
View file @
f0e93abf
...
...
@@ -21,7 +21,7 @@
/* Config parameters. */
#include
"../config.h"
#if defined(HAVE_HDF5) && defined(WITH_MPI) && !defined(HAVE_PARALLEL_HDF5)
#if defined(HAVE_HDF5) && defined(WITH_MPI) && !defined(HAVE_PARALLEL_HDF5)
&& !defined(WITH_LOGGER)
/* Some standard headers. */
#include
<hdf5.h>
...
...
src/single_io.c
View file @
f0e93abf
...
...
@@ -21,7 +21,7 @@
/* Config parameters. */
#include
"../config.h"
#if defined(HAVE_HDF5) && !defined(WITH_MPI)
#if defined(HAVE_HDF5) && !defined(WITH_MPI)
&& !defined(WITH_LOGGER)
/* Some standard headers. */
#include
<hdf5.h>
...
...
@@ -998,248 +998,4 @@ void write_output_single(struct engine* e, const char* baseName,
}
/**
* @brief Writes an HDF5 index file
*
* @param e The engine containing all the system.
* @param baseName The common part of the snapshot file name.
* @param internal_units The #unit_system used internally
* @param snapshot_units The #unit_system used in the snapshots
*
* Creates an HDF5 output file and writes the offset and id of particles contained
* in the engine. If such a file already exists, it is erased and replaced
* by the new one.
*
* Calls #error() if an error occurs.
*
*/
void
write_index_single
(
struct
engine
*
e
,
const
char
*
baseName
,
const
struct
unit_system
*
internal_units
,
const
struct
unit_system
*
snapshot_units
)
{
hid_t
h_file
=
0
,
h_grp
=
0
;
const
size_t
Ngas
=
e
->
s
->
nr_parts
;
const
size_t
Nstars
=
e
->
s
->
nr_sparts
;
const
size_t
Ntot
=
e
->
s
->
nr_gparts
;
int
periodic
=
e
->
s
->
periodic
;
int
numFiles
=
1
;
struct
part
*
parts
=
e
->
s
->
parts
;
struct
gpart
*
gparts
=
e
->
s
->
gparts
;
struct
gpart
*
dmparts
=
NULL
;
//struct spart* sparts = e->s->sparts;
static
int
outputCount
=
0
;
/* Number of unassociated gparts */
const
size_t
Ndm
=
Ntot
>
0
?
Ntot
-
(
Ngas
+
Nstars
)
:
0
;
long
long
N_total
[
swift_type_count
]
=
{
Ngas
,
Ndm
,
0
,
0
,
Nstars
,
0
};
/* File name */
char
fileName
[
FILENAME_BUFFER_SIZE
];
snprintf
(
fileName
,
FILENAME_BUFFER_SIZE
,
"%s_%04i.hdf5"
,
baseName
,
outputCount
);
/* Open file */
/* message("Opening file '%s'.", fileName); */
h_file
=
H5Fcreate
(
fileName
,
H5F_ACC_TRUNC
,
H5P_DEFAULT
,
H5P_DEFAULT
);
if
(
h_file
<
0
)
{
error
(
"Error while opening file '%s'."
,
fileName
);
}
/* Open header to write simulation properties */
/* message("Writing runtime parameters..."); */
h_grp
=
H5Gcreate
(
h_file
,
"/RuntimePars"
,
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
if
(
h_grp
<
0
)
error
(
"Error while creating runtime parameters group
\n
"
);
/* Write the relevant information */
io_write_attribute
(
h_grp
,
"PeriodicBoundariesOn"
,
INT
,
&
periodic
,
1
);
int
index
=
1
;
io_write_attribute
(
h_grp
,
"IsIndexFile"
,
INT
,
&
index
,
1
);
/* Close runtime parameters */
H5Gclose
(
h_grp
);
/* Open header to write simulation properties */
/* message("Writing file header..."); */
h_grp
=
H5Gcreate
(
h_file
,
"/Header"
,
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
if
(
h_grp
<
0
)
error
(
"Error while creating file header
\n
"
);
/* Print the relevant information and print status */
io_write_attribute
(
h_grp
,
"BoxSize"
,
DOUBLE
,
e
->
s
->
dim
,
3
);
double
dblTime
=
e
->
time
;
io_write_attribute
(
h_grp
,
"Time"
,
DOUBLE
,
&
dblTime
,
1
);
int
dimension
=
(
int
)
hydro_dimension
;
io_write_attribute
(
h_grp
,
"Dimension"
,
INT
,
&
dimension
,
1
);
/* GADGET-2 legacy values */
/* Number of particles of each type */
unsigned
int
numParticles
[
swift_type_count
]
=
{
0
};
unsigned
int
numParticlesHighWord
[
swift_type_count
]
=
{
0
};
for
(
int
ptype
=
0
;
ptype
<
swift_type_count
;
++
ptype
)
{
numParticles
[
ptype
]
=
(
unsigned
int
)
N_total
[
ptype
];
numParticlesHighWord
[
ptype
]
=
(
unsigned
int
)(
N_total
[
ptype
]
>>
32
);
}
io_write_attribute
(
h_grp
,
"NumPart_ThisFile"
,
LONGLONG
,
N_total
,
swift_type_count
);
io_write_attribute
(
h_grp
,
"NumPart_Total"
,
UINT
,
numParticles
,
swift_type_count
);
io_write_attribute
(
h_grp
,
"NumPart_Total_HighWord"
,
UINT
,
numParticlesHighWord
,
swift_type_count
);
double
MassTable
[
swift_type_count
]
=
{
0
};
io_write_attribute
(
h_grp
,
"MassTable"
,
DOUBLE
,
MassTable
,
swift_type_count
);
unsigned
int
flagEntropy
[
swift_type_count
]
=
{
0
};
flagEntropy
[
0
]
=
writeEntropyFlag
();
io_write_attribute
(
h_grp
,
"Flag_Entropy_ICs"
,
UINT
,
flagEntropy
,
swift_type_count
);
io_write_attribute
(
h_grp
,
"NumFilesPerSnapshot"
,
INT
,
&
numFiles
,
1
);
/* Close header */
H5Gclose
(
h_grp
);
/* Print the code version */
io_write_code_description
(
h_file
);
/* Print the SPH parameters */
if
(
e
->
policy
&
engine_policy_hydro
)
{
h_grp
=
H5Gcreate
(
h_file
,
"/HydroScheme"
,
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
if
(
h_grp
<
0
)
error
(
"Error while creating SPH group"
);
hydro_props_print_snapshot
(
h_grp
,
e
->
hydro_properties
);
writeSPHflavour
(
h_grp
);
H5Gclose
(
h_grp
);
}
/* Print the gravity parameters */
if
(
e
->
policy
&
engine_policy_self_gravity
)
{
h_grp
=
H5Gcreate
(
h_file
,
"/GravityScheme"
,
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
if
(
h_grp
<
0
)
error
(
"Error while creating gravity group"
);
gravity_props_print_snapshot
(
h_grp
,
e
->
gravity_properties
);
H5Gclose
(
h_grp
);
}
/* Print the runtime parameters */
h_grp
=
H5Gcreate
(
h_file
,
"/Parameters"
,
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
if
(
h_grp
<
0
)
error
(
"Error while creating parameters group"
);
parser_write_params_to_hdf5
(
e
->
parameter_file
,
h_grp
);
H5Gclose
(
h_grp
);
/* Print the system of Units used in the spashot */
io_write_unit_system
(
h_file
,
snapshot_units
,
"Units"
);
/* Print the system of Units used internally */
io_write_unit_system
(
h_file
,
internal_units
,
"InternalCodeUnits"
);
/* Tell the user if a conversion will be needed */
if
(
e
->
verbose
)
{
if
(
units_are_equal
(
snapshot_units
,
internal_units
))
{
message
(
"Snapshot and internal units match. No conversion needed."
);
}
else
{
message
(
"Conversion needed from:"
);
message
(
"(Snapshot) Unit system: U_M = %e g."
,
snapshot_units
->
UnitMass_in_cgs
);
message
(
"(Snapshot) Unit system: U_L = %e cm."
,
snapshot_units
->
UnitLength_in_cgs
);
message
(
"(Snapshot) Unit system: U_t = %e s."
,
snapshot_units
->
UnitTime_in_cgs
);
message
(
"(Snapshot) Unit system: U_I = %e A."
,
snapshot_units
->
UnitCurrent_in_cgs
);
message
(
"(Snapshot) Unit system: U_T = %e K."
,
snapshot_units
->
UnitTemperature_in_cgs
);
message
(
"to:"
);
message
(
"(internal) Unit system: U_M = %e g."
,
internal_units
->
UnitMass_in_cgs
);
message
(
"(internal) Unit system: U_L = %e cm."
,
internal_units
->
UnitLength_in_cgs
);
message
(
"(internal) Unit system: U_t = %e s."
,
internal_units
->
UnitTime_in_cgs
);
message
(
"(internal) Unit system: U_I = %e A."
,
internal_units
->
UnitCurrent_in_cgs
);
message
(
"(internal) Unit system: U_T = %e K."
,
internal_units
->
UnitTemperature_in_cgs
);
}
}
/* Loop over all particle types */
for
(
int
ptype
=
0
;
ptype
<
swift_type_count
;
ptype
++
)
{
/* Don't do anything if no particle of this kind */
if
(
numParticles
[
ptype
]
==
0
)
continue
;
/* Open the particle group in the file */
char
partTypeGroupName
[
PARTICLE_GROUP_BUFFER_SIZE
];
snprintf
(
partTypeGroupName
,
PARTICLE_GROUP_BUFFER_SIZE
,
"/PartType%d"
,
ptype
);
h_grp
=
H5Gcreate
(
h_file
,
partTypeGroupName
,
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
if
(
h_grp
<
0
)
{
error
(
"Error while creating particle group.
\n
"
);
}
int
num_fields
=
0
;
struct
io_props
list
[
100
];
size_t
N
=
0
;
/* Write particle fields from the particle structure */
switch
(
ptype
)
{
case
swift_type_gas
:
N
=
Ngas
;
hydro_write_index
(
parts
,
list
,
&
num_fields
);
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
;
case
swift_type_star
:
N
=
Nstars
;
error
(
"TODO"
);
//star_write_index(sparts, list, &num_fields);
break
;
default:
error
(
"Particle Type %d not yet supported. Aborting"
,
ptype
);
}
/* Write everything */
for
(
int
i
=
0
;
i
<
num_fields
;
++
i
)
writeArray
(
e
,
h_grp
,
fileName
,
NULL
,
partTypeGroupName
,
list
[
i
],
N
,
internal_units
,
snapshot_units
);
/* Free temporary array */
if
(
dmparts
)
{
free
(
dmparts
);
dmparts
=
NULL
;
}
/* Close particle group */
H5Gclose
(
h_grp
);
}
/* message("Done writing particles..."); */
/* Close file */
H5Fclose
(
h_file
);
++
outputCount
;
}
#endif
/* HAVE_HDF5 */
src/single_io.h
View file @
f0e93abf
...
...
@@ -45,6 +45,7 @@ void write_output_single(struct engine* e, const char* baseName,
void
write_index_single
(
struct
engine
*
e
,
const
char
*
baseName
,
const
struct
unit_system
*
internal_units
,
const
struct
unit_system
*
snapshot_units
);
#endif
/* HAVE_HDF5 && !WITH_MPI */
#endif
/* SWIFT_SINGLE_IO_H */
src/swift.h
View file @
f0e93abf
...
...
@@ -46,6 +46,7 @@
#include
"hydro_properties.h"
#include
"lock.h"
#include
"logger.h"
#include
"logger_io.h"
#include
"map.h"
#include
"mesh_gravity.h"
#include
"multipole.h"
...
...
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