10 #include <bigfile-mpi.h>
60 MPI_Comm_rank(MPI_COMM_WORLD, &
ThisTask);
76 MPI_Bcast(&
IO,
sizeof(
struct petaio_params), MPI_BYTE, 0, MPI_COMM_WORLD);
91 message(0,
"Aggregated IO is enabled\n");
94 message(0,
"Aggregated IO is disabled.\n");
95 big_file_mpi_set_aggregated_threshold(0);
118 int (*select_func)(
int i,
const struct particle_data * Parts)
125 for(i = 0; i < NumPart; i ++) {
128 if((select_func == NULL) || (select_func(i, Parts) != 0)) {
130 ptype_count[
ptype] ++;
133 for(i = 1; i < 6; i ++) {
134 ptype_offset[i] = ptype_offset[i-1] + ptype_count[i-1];
135 ptype_count[i-1] = 0;
139 for(i = 0; i < NumPart; i ++) {
143 if((select_func == NULL) || (select_func(i, Parts) != 0)) {
144 selection[ptype_offset[
ptype] + ptype_count[
ptype]] = i;
145 ptype_count[
ptype]++;
153 message(0,
"saving snapshot into %s\n", fname);
156 if(0 != big_file_mpi_create(&bf, fname, MPI_COMM_WORLD)) {
157 endrun(0,
"Failed to create snapshot at %s:%s\n", fname,
158 big_file_get_error_message());
161 int ptype_offset[6]={0};
162 int ptype_count[6]={0};
182 BigArray array = {0};
184 if(!(ptype < 6 && ptype >= 0)) {
195 MPI_Comm_rank(MPI_COMM_WORLD, &
ThisTask);
198 if(0 != big_file_mpi_close(&bf, MPI_COMM_WORLD)){
199 endrun(0,
"Failed to close snapshot at %s:%s\n", fname,
200 big_file_get_error_message());
224 message(0,
"Probing Header of snapshot file: %s\n", fname);
226 if(0 != big_file_mpi_open(&bf, fname, MPI_COMM_WORLD)) {
227 endrun(0,
"Failed to open snapshot at %s:%s\n", fname,
228 big_file_get_error_message());
233 head.neutrinonk = -1;
238 if(0 == big_file_mpi_open_block(&bf, &bn,
"Neutrino", MPI_COMM_WORLD)) {
239 if(0 != big_block_get_attr(&bn,
"Nkval", &head.neutrinonk,
"u8", 1))
240 endrun(0,
"Failed to read attr: %s\n", big_file_get_error_message());
241 big_block_mpi_close(&bn, MPI_COMM_WORLD);
245 if(0 != big_file_mpi_close(&bf, MPI_COMM_WORLD)) {
246 endrun(0,
"Failed to close snapshot at %s:%s\n", fname,
247 big_file_get_error_message());
259 const int ic = (num == -1);
261 message(0,
"Reading snapshot %s\n", fname);
263 if(0 != big_file_mpi_open(&bf, fname, Comm)) {
264 endrun(0,
"Failed to open snapshot at %s:%s\n", fname,
265 big_file_get_error_message());
293 BigArray array = {0};
294 if(!(ptype < 6 && ptype >= 0)) {
324 if(0 != big_file_mpi_close(&bf, Comm)) {
325 endrun(0,
"Failed to close snapshot at %s:%s\n", fname,
326 big_file_get_error_message());
341 #pragma omp parallel for
349 #pragma omp parallel for
353 for(k = 0; k < 3; k++)
363 if(0 != big_file_mpi_create_block(bf, &bh,
"Header", NULL, 0, 0, 0, MPI_COMM_WORLD)) {
364 endrun(0,
"Failed to create block at %s:%s\n",
"Header",
365 big_file_get_error_message());
370 double RSD = 1.0 / (atime * hubble);
378 (0 != big_block_set_attr(&bh,
"TotNumPart", NTotal,
"u8", 6)) ||
379 (0 != big_block_set_attr(&bh,
"TotNumPartInit", &data->
NTotalInit,
"u8", 6)) ||
380 (0 != big_block_set_attr(&bh,
"MassTable", &data->
MassTable,
"f8", 6)) ||
381 (0 != big_block_set_attr(&bh,
"Time", &atime,
"f8", 1)) ||
382 (0 != big_block_set_attr(&bh,
"TimeIC", &data->
TimeIC,
"f8", 1)) ||
383 (0 != big_block_set_attr(&bh,
"BoxSize", &data->
BoxSize,
"f8", 1)) ||
384 (0 != big_block_set_attr(&bh,
"OmegaLambda", &
CP->
OmegaLambda,
"f8", 1)) ||
385 (0 != big_block_set_attr(&bh,
"RSDFactor", &RSD,
"f8", 1)) ||
387 (0 != big_block_set_attr(&bh,
"Omega0", &
CP->
Omega0,
"f8", 1)) ||
388 (0 != big_block_set_attr(&bh,
"CMBTemperature", &
CP->
CMBTemperature,
"f8", 1)) ||
389 (0 != big_block_set_attr(&bh,
"OmegaBaryon", &
CP->
OmegaBaryon,
"f8", 1)) ||
390 (0 != big_block_set_attr(&bh,
"UnitLength_in_cm", &data->
UnitLength_in_cm,
"f8", 1)) ||
391 (0 != big_block_set_attr(&bh,
"UnitMass_in_g", &data->
UnitMass_in_g,
"f8", 1)) ||
395 (0 != big_block_set_attr(&bh,
"DensityKernel", &dk,
"i4", 1)) ||
396 (0 != big_block_set_attr(&bh,
"HubbleParam", &
CP->
HubbleParam,
"f8", 1)) ) {
397 endrun(0,
"Failed to write attributes %s\n",
398 big_file_get_error_message());
401 if(0 != big_block_mpi_close(&bh, MPI_COMM_WORLD)) {
402 endrun(0,
"Failed to close block %s\n",
403 big_file_get_error_message());
410 if(0 != big_block_get_attr(bh,
name, &foo,
"f8", 1)) {
419 if(0 != big_block_get_attr(bh,
name, &foo,
"i4", 1)) {
428 if(0 != big_file_mpi_open_block(bf, &bh,
"Header", MPI_COMM_WORLD)) {
429 endrun(0,
"Failed to create block at %s:%s\n",
"Header",
430 big_file_get_error_message());
434 (0 != big_block_get_attr(&bh,
"TotNumPart",
Header->
NTotal,
"u8", 6)) ||
435 (0 != big_block_get_attr(&bh,
"MassTable",
Header->
MassTable,
"f8", 6)) ||
436 (0 != big_block_get_attr(&bh,
"BoxSize", &
Header->
BoxSize,
"f8", 1)) ||
437 (0 != big_block_get_attr(&bh,
"Time", &Time,
"f8", 1))
439 endrun(0,
"Failed to read attr: %s\n",
440 big_file_get_error_message());
444 if(0!= big_block_get_attr(&bh,
"TimeIC", &
Header->
TimeIC,
"f8", 1))
462 if(0 == big_block_get_attr(&bh,
"OmegaBaryon", &
CP->
OmegaBaryon,
"f8", 1) &&
463 OmegaBaryon > 0 && fabs(
CP->
OmegaBaryon - OmegaBaryon) > 1e-3)
465 if(0 == big_block_get_attr(&bh,
"HubbleParam", &
CP->
HubbleParam,
"f8", 1) &&
466 HubbleParam > 0 && fabs(
CP->
HubbleParam - HubbleParam) > 1e-3)
467 message(0,
"IC Header has HubbleParam = %g but paramfile wants %g\n",
CP->
HubbleParam, HubbleParam);
468 if(0 == big_block_get_attr(&bh,
"OmegaLambda", &
CP->
OmegaLambda,
"f8", 1) &&
469 OmegaLambda > 0 && fabs(
CP->
OmegaLambda - OmegaLambda) > 1e-3)
478 if(0 != big_block_get_attr(&bh,
"TotNumPartInit",
Header->
NTotalInit,
"u8", 6)) {
485 if(0 != big_block_mpi_close(&bh, MPI_COMM_WORLD)) {
486 endrun(0,
"Failed to close block: %s\n",
487 big_file_get_error_message());
493 ptrdiff_t strides[2];
494 int elsize = dtype_itemsize(ent->
dtype);
497 dims[1] = ent->
items;
499 strides[0] = elsize * ent->
items;
500 char * buffer = (
char *)
mymalloc(
"IOBUFFER", dims[0] * dims[1] * elsize);
502 big_array_init(array, buffer, ent->
dtype, 2, dims, strides);
509 char * p = (
char *) array->data;
510 for(i = 0; i < PartManager->NumPart; i ++) {
513 p += array->strides[0];
523 if(selection == NULL) {
524 endrun(-1,
"NULL selection is not supported\n");
531 if(NumSelection == 0) {
538 const int tid = omp_get_thread_num();
539 const int NT = omp_get_num_threads();
540 const int start = NumSelection * (size_t) tid / NT;
541 const int end = NumSelection * ((size_t) tid + 1) / NT;
543 char * p = (
char *) array->data;
544 p += array->strides[0] * start;
545 for(i = start; i < end; i ++) {
546 const int j = selection[i];
548 endrun(2,
"Selection %d has type = %d != %d\n", j, Parts[j].
Type, ent->
ptype);
551 p += array->strides[0];
567 if(0 != big_file_mpi_open_block(bf, &bb, blockname, MPI_COMM_WORLD)) {
569 endrun(0,
"Failed to open block at %s:%s\n", blockname, big_file_get_error_message());
573 if(0 != big_block_seek(&bb, &ptr, 0)) {
574 endrun(1,
"Failed to seek block %s: %s\n", blockname, big_file_get_error_message());
576 if(0 != big_block_mpi_read(&bb, &ptr, array,
IO.
NumWriters, MPI_COMM_WORLD)) {
577 endrun(1,
"Failed to read from block %s: %s\n", blockname, big_file_get_error_message());
579 if(0 != big_block_mpi_close(&bb, MPI_COMM_WORLD)) {
580 endrun(0,
"Failed to close block at %s:%s\n", blockname,
581 big_file_get_error_message());
593 int elsize = big_file_dtype_itemsize(array->dtype);
604 message(0,
"Throttling NumWriters to %d.\n", NumWriters);
609 message(0,
"Throttling NumWriters to %d.\n", NumWriters);
612 NumFiles = NumWriters;
619 if(verbose && size > 0) {
620 message(0,
"Will write %td particles to %d Files for %s\n", size, NumFiles, blockname);
624 if(0 != big_file_mpi_create_block(bf, &bb, blockname, array->dtype, array->dims[1], NumFiles, size, MPI_COMM_WORLD)) {
625 endrun(0,
"Failed to create block at %s:%s\n", blockname,
626 big_file_get_error_message());
628 if(0 != big_block_seek(&bb, &ptr, 0)) {
629 endrun(0,
"Failed to seek:%s\n", big_file_get_error_message());
631 if(0 != big_block_mpi_write(&bb, &ptr, array, NumWriters, MPI_COMM_WORLD)) {
632 endrun(0,
"Failed to write :%s\n", big_file_get_error_message());
635 if(verbose && size > 0)
636 message(0,
"Done writing %td particles to %d Files\n", size, NumFiles);
638 if(0 != big_block_mpi_close(&bb, MPI_COMM_WORLD)) {
639 endrun(0,
"Failed to close block at %s:%s\n", blockname,
640 big_file_get_error_message());
673 ent->
name[63] =
'\0';
676 strncpy(ent->
dtype, dtype, 7);
677 ent->
dtype[7] =
'\0';
689 for(d = 0; d < 3; d ++) {
699 for(d = 0; d < 3; d ++) {
700 part[i].
Pos[d] = out[d];
704 #define SIMPLE_PROPERTY(name, field, type, items) \
705 SIMPLE_GETTER(GT ## name , field, type, items, struct particle_data) \
706 SIMPLE_SETTER(ST ## name , field, type, items, struct particle_data)
708 #define SIMPLE_PROPERTY_TYPE(name, ptype, field, type, items) \
709 SIMPLE_GETTER(GT ## ptype ## name , field, type, items, struct particle_data) \
710 SIMPLE_SETTER(ST ## ptype ## name , field, type, items, struct particle_data)
713 #define SIMPLE_GETTER_PI(name, field, dtype, items, slottype) \
714 static void name(int i, dtype * out, void * baseptr, void * smanptr, const struct conversions * params) { \
715 int PI = ((struct particle_data *) baseptr)[i].PI; \
716 int ptype = ((struct particle_data *) baseptr)[i].Type; \
717 struct slot_info * info = &(((struct slots_manager_type *) smanptr)->info[ptype]); \
718 slottype * sl = (slottype *) info->ptr; \
720 for(k = 0; k < items; k ++) { \
721 out[k] = *(&(sl[PI].field) + k); \
725 #define SIMPLE_SETTER_PI(name, field, dtype, items, slottype) \
726 static void name(int i, dtype * out, void * baseptr, void * smanptr, const struct conversions * params) { \
727 int PI = ((struct particle_data *) baseptr)[i].PI; \
728 int ptype = ((struct particle_data *) baseptr)[i].Type; \
729 struct slot_info * info = &(((struct slots_manager_type *) smanptr)->info[ptype]); \
730 slottype * sl = (slottype *) info->ptr; \
732 for(k = 0; k < items; k ++) { \
733 *(&(sl[PI].field) + k) = out[k]; \
737 #define SIMPLE_PROPERTY_PI(name, field, type, items, slottype) \
738 SIMPLE_GETTER_PI(GT ## name , field, type, items, slottype) \
739 SIMPLE_SETTER_PI(ST ## name , field, type, items, slottype)
740 #define SIMPLE_PROPERTY_TYPE_PI(name, ptype, field, type, items, slottype) \
741 SIMPLE_GETTER_PI(GT ## ptype ## name , field, type, items, slottype) \
742 SIMPLE_SETTER_PI(ST ## ptype ## name , field, type, items, slottype)
749 fac = 1.0 / params->
atime;
755 for(d = 0; d < 3; d ++) {
756 out[d] = fac * part[i].
Vel[d];
769 for(d = 0; d < 3; d ++) {
770 part[i].
Vel[d] = out[d] * fac;
813 for(d = 0; d < 3; d ++) {
823 double redshift = 1./params->atime - 1;
832 double redshift = 1./params->
atime - 1;
840 double redshift = 1./params->
atime - 1;
848 double redshift = 1./params->
atime - 1;
916 for(i = 0; i < 6; i ++) {
const char * GADGET_VERSION
const char * GADGET_COMPILER_SETTINGS
double hubble_function(const Cosmology *CP, double a)
enum DensityKernelType GetDensityKernelType(void)
void message(int where, const char *fmt,...)
void endrun(int where, const char *fmt,...)
static struct gravpm_params GravPM
int DensityIndependentSphOn(void)
#define mymalloc(name, size)
#define myrealloc(ptr, size)
#define mymalloc2(name, size)
void petaio_save_neutrinos(BigFile *bf, int ThisTask)
void petaio_read_neutrinos(BigFile *bf, int ThisTask)
void petaio_read_icnutransfer(BigFile *bf, int ThisTask)
void param_get_string2(ParameterSet *ps, const char *name, char *dst, size_t len)
int param_get_int(ParameterSet *ps, const char *name)
struct part_manager_type PartManager[1]
void petaio_destroy_buffer(BigArray *array)
#define SIMPLE_GETTER_PI(name, field, dtype, items, slottype)
static void GTHeliumIIFraction(int i, float *out, void *baseptr, void *smanptr, const struct conversions *params)
static void GTBlackholeMinPotPos(int i, double *out, void *baseptr, void *smanptr, const struct conversions *params)
static int _get_attr_int(BigBlock *bh, const char *name, const int def)
static void petaio_read_header_internal(BigFile *bf, Cosmology *CP, struct header_data *data)
void petaio_read_snapshot(int num, const char *OutputDir, Cosmology *CP, struct header_data *header, struct part_manager_type *PartManager, struct slots_manager_type *SlotsManager, MPI_Comm Comm)
#define SIMPLE_PROPERTY(name, field, type, items)
static void GTSwallowed(int i, unsigned char *out, void *baseptr, void *smanptr, const struct conversions *params)
static struct petaio_params IO
void io_register_io_block(const char *name, const char *dtype, int items, int ptype, property_getter getter, property_setter setter, int required, struct IOTable *IOTable)
static void STVelocity(int i, float *out, void *baseptr, void *smanptr, const struct conversions *params)
static void STPosition(int i, double *out, void *baseptr, void *smanptr, const struct conversions *params)
struct header_data petaio_read_header(int num, const char *OutputDir, Cosmology *CP)
static void GTVelocity(int i, float *out, void *baseptr, void *smanptr, const struct conversions *params)
void destroy_io_blocks(struct IOTable *IOTable)
static void GTHeIIIIonized(int i, unsigned char *out, void *baseptr, void *smanptr, const struct conversions *params)
static void GTNeutralHydrogenFraction(int i, float *out, void *baseptr, void *smanptr, const struct conversions *params)
static int order_by_type(const void *a, const void *b)
void register_io_blocks(struct IOTable *IOTable, int WriteGroupID, int MetalReturnOn)
static struct header_data Header
static void petaio_write_header(BigFile *bf, const double atime, const int64_t *NTotal, const Cosmology *CP, const struct header_data *data)
int petaio_read_block(BigFile *bf, const char *blockname, BigArray *array, int required)
static void GTHeliumIFraction(int i, float *out, void *baseptr, void *smanptr, const struct conversions *params)
static void STInternalEnergy(int i, float *out, void *baseptr, void *smanptr, const struct conversions *params)
#define SIMPLE_SETTER_PI(name, field, dtype, items, slottype)
void petaio_save_snapshot(const char *fname, struct IOTable *IOTable, int verbose, const double atime, const Cosmology *CP)
void register_debug_io_blocks(struct IOTable *IOTable)
char * petaio_get_snapshot_fname(int num, const char *OutputDir)
void petaio_build_selection(int *selection, int *ptype_offset, int *ptype_count, const struct particle_data *Parts, const int NumPart, int(*select_func)(int i, const struct particle_data *Parts))
void petaio_alloc_buffer(BigArray *array, IOTableEntry *ent, int64_t localsize)
int GetUsePeculiarVelocity(void)
static void GTHeliumIIIFraction(int i, float *out, void *baseptr, void *smanptr, const struct conversions *params)
static void STSwallowed(int i, unsigned char *out, void *baseptr, void *smanptr, const struct conversions *params)
void set_petaio_params(ParameterSet *ps)
static void GTInternalEnergy(int i, float *out, void *baseptr, void *smanptr, const struct conversions *params)
#define SIMPLE_PROPERTY_TYPE_PI(name, ptype, field, type, items, slottype)
static void STHeIIIIonized(int i, unsigned char *out, void *baseptr, void *smanptr, const struct conversions *params)
static void GTPosition(int i, double *out, void *baseptr, void *smanptr, const struct conversions *params)
void petaio_build_buffer(BigArray *array, IOTableEntry *ent, const int *selection, const int NumSelection, struct particle_data *Parts, struct slots_manager_type *SlotsManager, struct conversions *conv)
void petaio_readout_buffer(BigArray *array, IOTableEntry *ent, struct conversions *conv, struct part_manager_type *PartManager, struct slots_manager_type *SlotsManager)
#define SIMPLE_PROPERTY_PI(name, field, type, items, slottype)
void petaio_save_block(BigFile *bf, const char *blockname, BigArray *array, int verbose)
static double _get_attr_double(BigBlock *bh, const char *name, const double def)
void(* property_setter)(int i, void *target, void *baseptr, void *slotptr, const struct conversions *params)
#define SIMPLE_GETTER(name, field, type, items, stype)
#define IO_REG_WRONLY(name, dtype, items, ptype, IOTable)
void(* property_getter)(int i, void *result, void *baseptr, void *slotptr, const struct conversions *params)
#define IO_REG(name, dtype, items, ptype, IOTable)
#define IO_REG_NONFATAL(name, dtype, items, ptype, IOTable)
#define IO_REG_TYPE(name, dtype, items, ptype, IOTable)
double get_helium_neutral_fraction_sfreff(int ion, double redshift, double hubble, struct particle_data *partdata, struct sph_particle_data *sphdata)
double get_neutral_fraction_sfreff(double redshift, double hubble, struct particle_data *partdata, struct sph_particle_data *sphdata)
int get_generations(void)
void slots_setup_id(const struct part_manager_type *pman, struct slots_manager_type *sman)
struct slots_manager_type SlotsManager[1]
char * fastpm_strdup_printf(const char *fmt,...)
struct particle_data * Base
double CurrentParticleOffset[3]
unsigned char HeIIIionized
size_t AggregatedIOThreshold
int OutputHeliumFractions
char SnapshotFileBase[100]
int64_t count_sum(int64_t countLocal)
void sumup_large_ints(int n, int *src, int64_t *res)
static enum TransferType ptype