GADGET-4
io.h
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#ifndef IO_H
13#define IO_H
14
15#include <hdf5.h>
16
17#ifdef LIGHTCONE_PARTICLES
18#include <chealpix.h>
19#endif
20
21#include "../data/simparticles.h"
22#include "../fof/fof.h"
23#include "../io/io_streamcount.h"
24#include "../mpi_utils/setcomm.h"
25
26#define LABEL_LEN 4
27#define DATASETNAME_LEN 256
28
30{
49};
50
52{
62};
63
65{
75};
76
78{
88};
89
90#ifdef FOF_ALLOW_HUGE_GROUPLENGTH
93#else
96#endif
97
99{
103 ALL_TYPES = ((1 << NTYPES) - 1),
107 GROUPS = -4,
114 TREELINK = -11,
115 MASSMAPS = -12,
118 GALSNAPS = -16,
120};
121
123{
127
128class IO_Def : public io_streamcount, public setcomm
129{
130 public:
131 IO_Def(MPI_Comm comm, int format) : setcomm(comm)
132 {
134 file_format = format;
135 }
136
137 virtual ~IO_Def();
138
140 int N_IO_Fields = 0;
142
143 /* functions that need to be provided by the specific module */
144
145 virtual void fill_file_header(int writeTask, int lastTask, long long *nloc_part, long long *npart) = 0;
146 virtual void read_file_header(const char *fname, int filenr, int readTask, int lastTask, long long *nloc_part, long long *npart,
147 int *nstart) = 0;
148 virtual void get_datagroup_name(int grnr, char *gname) = 0;
149 virtual void write_header_fields(hid_t) = 0;
150 virtual void read_header_fields(const char *fname) = 0;
151 virtual void read_increase_numbers(int type, int n_for_this_task) = 0;
152 virtual int get_filenr_from_header(void) = 0;
153 virtual void set_filenr_in_header(int) = 0;
154 virtual void *get_base_address_of_structure(enum arrays array, int index) = 0;
155 virtual int get_type_of_element(int index) = 0;
156 virtual void set_type_of_element(int index, int type) = 0;
157
158 void init_field(const char *label, const char *datasetname, enum types_in_memory type_in_memory,
159 enum types_in_file type_in_file_output, enum read_flags read_flag, int values_per_block, enum arrays array,
160 void *pointer_to_field, void (*io_func)(IO_Def *, int, int, void *, int), int typelist_bitmask, int hasunits,
161 double a, double h, double L, double M, double V, double c, bool compression_on = false);
162
163 int find_files(const char *fname, const char *fname_multiple);
164 void read_files_driver(const char *fname, int rep, int numfiles);
165 void write_multiple_files(char *fname, int numfilesperdump, int append_flag = 0, int chunk_size = 0);
167 void read_segment(const char *fname, int type, long long offset, long long count, int numfiles);
168 void read_single_file_segment(const char *fname, int filenr, int type, long long offset, unsigned long long count,
169 long long storage_offset, int numfiles);
170
171 void alloc_and_read_ntype_in_files(const char *fname, int num_files);
172
175
176 long long *ntype_in_files;
177 char info[100];
178
179#if defined(MERGERTREE)
180 typedef fof<simparticles>::treehalo_t treehalo_type;
181#endif
182
183 /*
184 * variables for new input/output functionality
185 */
186
188
189 private:
190 struct IO_Field
191 {
192 enum types_in_memory type_in_memory;
193 enum types_in_file type_in_file_output;
194 enum read_flags read_flag;
195 int values_per_block;
196 int write_block;
197 int read_block;
198 char label[LABEL_LEN + 1];
199 char datasetname[DATASETNAME_LEN + 1];
200 void (*io_func)(IO_Def *, int, int, void *, int);
201 int typelist;
202 bool compression_on;
203 enum arrays array;
204 size_t offset;
205
206 char hasunit;
207 double a;
208 double h;
209 double L;
210 double M;
211 double V;
212 double c;
213 };
214 IO_Field *IO_Fields;
215
216 void write_file(char *fname, int writeTask, int lastTask, void *CommBuffer, int numfilesperdump, int chunksize);
217 void read_file(const char *fname, int filenr, int readTask, int lastTask, void *CommBuffer);
218 void append_file(char *fname, int writeTask, int lastTask, void *CommBuffer, int numfilesperdump, int chunksize);
219
220 int get_values_per_blockelement(int blocknr);
221 void get_dataset_name(int blocknr, char *buf);
222 long long get_particles_in_block(int blocknr, long long *npartinfile, int *typelist);
223 int get_bytes_per_memory_blockelement(int blocknr, int mode);
224 hid_t get_hdf5_outputtype_of_block(int blocknr);
225 hid_t get_hdf5_memorytype_of_block(int blocknr);
226 void get_Tab_IO_Label(int blocknr, char *label);
227 void type_cast_data(char *src, int src_bytes_per_element, char *target, int target_bytes_per_element, int len, int blocknr);
228 void distribute_file(int nfiles, int *filenr, int *master, int *last);
229 void share_particle_number_in_file(const char *fname, int filenr, int readTask, int lastTask);
230 void find_block(char *label, FILE *fd);
231 void fill_write_buffer(int blocknr, int *startindex, int pc, int type, void *CommBuffer);
232 void empty_read_buffer(int blocknr, int offset, int pc, int type, long long nprevious, void *CommBuffer);
233
234 void write_dataset_attributes(hid_t hdf5_dataset, int blocknr);
235 void write_parameters_attributes_in_hdf5(hid_t handle);
236 void rename_file_to_bak_if_it_exists(char *fname);
237
238 void polling(int numfilesperdump);
239
240 int files_started;
241 int files_completed;
242 int file_format;
243
244 struct seq_data
245 {
246 int thistask;
247 int rankinnode;
248 int thisnode;
249 bool operator<(const seq_data &b) const
250 {
251 if(rankinnode < b.rankinnode)
252 return true;
253 if(rankinnode > b.rankinnode)
254 return false;
255 if(thisnode < b.thisnode)
256 return true;
257 if(thisnode > b.thisnode)
258 return false;
259 return thistask < b.thistask;
260 }
261 };
262 seq_data *seq;
263};
264
265#ifdef GADGET2_HEADER
266#define NTYPES_HEADER 6
267#else
268#define NTYPES_HEADER NTYPES
269#endif
270
271#define FLAG_ZELDOVICH_ICS 1
272#define FLAG_SECOND_ORDER_ICS 2
273
274#endif
Definition: io.h:129
virtual int get_filenr_from_header(void)=0
int N_DataGroups
Definition: io.h:139
void alloc_and_read_ntype_in_files(const char *fname, int num_files)
Definition: io.cc:2439
void write_multiple_files(char *fname, int numfilesperdump, int append_flag=0, int chunk_size=0)
Definition: io.cc:700
long long * ntype_in_files
Definition: io.h:176
int Max_IO_Fields
Definition: io.h:141
virtual ~IO_Def()
Definition: io.cc:47
void * header_buf
Definition: io.h:174
virtual void * get_base_address_of_structure(enum arrays array, int index)=0
void read_segment(const char *fname, int type, long long offset, long long count, int numfiles)
Definition: io.cc:2166
virtual void set_type_of_element(int index, int type)=0
virtual void read_increase_numbers(int type, int n_for_this_task)=0
virtual void fill_file_header(int writeTask, int lastTask, long long *nloc_part, long long *npart)=0
size_t header_size
Definition: io.h:173
void init_field(const char *label, const char *datasetname, enum types_in_memory type_in_memory, enum types_in_file type_in_file_output, enum read_flags read_flag, int values_per_block, enum arrays array, void *pointer_to_field, void(*io_func)(IO_Def *, int, int, void *, int), int typelist_bitmask, int hasunits, double a, double h, double L, double M, double V, double c, bool compression_on=false)
Definition: io.cc:66
int N_IO_Fields
Definition: io.h:140
virtual void read_header_fields(const char *fname)=0
virtual void read_file_header(const char *fname, int filenr, int readTask, int lastTask, long long *nloc_part, long long *npart, int *nstart)=0
char info[100]
Definition: io.h:177
virtual void set_filenr_in_header(int)=0
enum file_contents type_of_file
Definition: io.h:187
virtual void write_header_fields(hid_t)=0
IO_Def(MPI_Comm comm, int format)
Definition: io.h:131
void read_files_driver(const char *fname, int rep, int numfiles)
Definition: io.cc:227
virtual void get_datagroup_name(int grnr, char *gname)=0
void read_single_file_segment(const char *fname, int filenr, int type, long long offset, unsigned long long count, long long storage_offset, int numfiles)
Definition: io.cc:2207
virtual int get_type_of_element(int index)=0
int find_files(const char *fname, const char *fname_multiple)
This function determines on how many files a given snapshot or group/desc catalogue is distributed.
Definition: io.cc:132
void write_compile_time_options_in_hdf5(hid_t handle)
void determine_compute_nodes(void)
Definition: setcomm.h:98
#define NTYPES
Definition: constants.h:308
bool operator<(const location &left, const location &right)
Definition: dtypes.h:172
const types_in_memory mem_len_type
Definition: io.h:94
read_flags
Definition: io.h:123
@ READ_IF_PRESENT
Definition: io.h:124
@ SKIP_ON_READ
Definition: io.h:125
e_typelist
Definition: io.h:99
@ GALSNAPS
Definition: io.h:118
@ ALL_TYPES
Definition: io.h:103
@ MASSMAPS
Definition: io.h:115
@ TREELENGTH
Definition: io.h:112
@ PREVSUBS
Definition: io.h:110
@ AGE_BLOCK
Definition: io.h:105
@ TREETIMES
Definition: io.h:117
@ TREELINK
Definition: io.h:114
@ Z_BLOCK
Definition: io.h:106
@ GAS_AND_STARS
Definition: io.h:102
@ GROUPS
Definition: io.h:107
@ MASS_BLOCK
Definition: io.h:104
@ STARS_ONLY
Definition: io.h:101
@ GAS_ONLY
Definition: io.h:100
@ CURRSUBS
Definition: io.h:111
@ SUBGROUPS
Definition: io.h:108
@ ID_BLOCK
Definition: io.h:109
@ TREEHALOS
Definition: io.h:113
@ TREETABLE
Definition: io.h:116
@ HEALPIXTAB
Definition: io.h:119
arrays
Definition: io.h:30
@ A_PROG
Definition: io.h:39
@ A_DESC
Definition: io.h:38
@ A_MTRP
Definition: io.h:40
@ A_IDS
Definition: io.h:47
@ A_ID
Definition: io.h:37
@ A_NONE
Definition: io.h:31
@ A_TL
Definition: io.h:44
@ A_MM
Definition: io.h:46
@ A_SPHP
Definition: io.h:32
@ A_P
Definition: io.h:33
@ A_H
Definition: io.h:41
@ A_TT
Definition: io.h:42
@ A_G
Definition: io.h:35
@ A_PS
Definition: io.h:34
@ A_LC
Definition: io.h:45
@ A_S
Definition: io.h:36
@ A_CT
Definition: io.h:43
@ A_TID
Definition: io.h:48
types_in_file
Definition: io.h:65
@ FILE_FLOAT
Definition: io.h:74
@ FILE_MY_INTPOS_TYPE
Definition: io.h:72
@ FILE_DOUBLE
Definition: io.h:73
@ FILE_HALF
Definition: io.h:70
@ FILE_NONE
Definition: io.h:66
@ FILE_MY_IO_FLOAT
Definition: io.h:69
@ FILE_INT64
Definition: io.h:68
@ FILE_MY_ID_TYPE
Definition: io.h:71
@ FILE_INT
Definition: io.h:67
#define LABEL_LEN
Definition: io.h:26
const types_in_file file_len_type
Definition: io.h:95
#define DATASETNAME_LEN
Definition: io.h:27
types_in_memory
Definition: io.h:78
@ MEM_INT
Definition: io.h:79
@ MEM_DOUBLE
Definition: io.h:84
@ MEM_MY_FLOAT
Definition: io.h:85
@ MEM_MY_FILEOFFSET
Definition: io.h:87
@ MEM_MY_ID_TYPE
Definition: io.h:81
@ MEM_MY_INTPOS_TYPE
Definition: io.h:82
@ MEM_FLOAT
Definition: io.h:83
@ MEM_MY_DOUBLE
Definition: io.h:86
@ MEM_INT64
Definition: io.h:80
file_contents
Definition: io.h:52
@ FILE_IS_DESCCAT
Definition: io.h:55
@ FILE_IS_TREELINK
Definition: io.h:58
@ FILE_IS_GALSNAP
Definition: io.h:61
@ FILE_IS_GROUPCAT
Definition: io.h:54
@ FILE_IS_SNAPSHOT
Definition: io.h:53
@ FILE_IS_PROGCAT
Definition: io.h:56
@ FILE_IS_TREECAT
Definition: io.h:57
@ FILE_IS_LIGHTCONE
Definition: io.h:59
@ FILE_IS_MASSMAP
Definition: io.h:60