12#include "gadgetconfig.h"
16#include <gsl/gsl_rng.h>
27#include "../data/allvars.h"
28#include "../data/dtypes.h"
29#include "../data/mymalloc.h"
30#include "../fof/fof.h"
31#include "../io/hdf5_util.h"
33#include "../logs/timer.h"
34#include "../main/simulation.h"
35#include "../mergertree/io_treelinks.h"
36#include "../mergertree/mergertree.h"
37#include "../mpi_utils/mpi_utils.h"
38#include "../sort/parallel_sort.h"
39#include "../subfind/subfind.h"
40#include "../system/system.h"
42treelinks_io::treelinks_io(mergertree *MergerTree_ptr, MPI_Comm comm,
int format) :
IO_Def(comm, format)
44 MergerTree = MergerTree_ptr;
46 this->N_IO_Fields = 0;
47 this->N_DataGroups = 1;
48 this->header_size =
sizeof(header);
49 this->header_buf = &header;
51 sprintf(this->info,
"TREELINK: writing treelink information");
53 init_field(
"TRNR",
"TreeID",
MEM_INT64,
FILE_INT64,
READ_IF_PRESENT, 1,
A_TL, &MergerTree->TreeLink[0].TreeID, NULL,
TREELINK, 0, 0,
56 init_field(
"TRIX",
"TreeIndex",
MEM_INT,
FILE_INT,
READ_IF_PRESENT, 1,
A_TL, &MergerTree->TreeLink[0].TreeIndex, NULL,
TREELINK, 0,
57 0, 0, 0, 0, 0, 0,
true);
60void treelinks_io::treelinks_save(
int num)
72 MPI_Barrier(Communicator);
76 sprintf(buf,
"%s/groups_%03d/%s_%03d",
All.
OutputDir, num,
"subhalo_treelink", num);
78 sprintf(buf,
"%s%s_%03d",
All.
OutputDir,
"subhalo_treelink", num);
83void treelinks_io::fill_file_header(
int writeTask,
int lastTask,
long long *n_type,
long long *ntot_type)
87 n_type[0] = Nsubhalos;
89 if(ThisTask == writeTask)
91 for(
int n = 0; n < 1; n++)
92 ntot_type[n] = n_type[n];
94 for(
int task = writeTask + 1; task <= lastTask; task++)
97 MPI_Recv(&nn[0], 1, MPI_LONG_LONG, task,
TAG_LOCALN, Communicator, MPI_STATUS_IGNORE);
98 for(
int n = 0; n < 1; n++)
99 ntot_type[n] += nn[n];
102 for(
int task = writeTask + 1; task <= lastTask; task++)
103 MPI_Send(&ntot_type[0], 1, MPI_LONG_LONG, task,
TAG_N, Communicator);
107 MPI_Send(&n_type[0], 1, MPI_LONG_LONG, writeTask,
TAG_LOCALN, Communicator);
108 MPI_Recv(&ntot_type[0], 1, MPI_LONG_LONG, writeTask,
TAG_N, Communicator, MPI_STATUS_IGNORE);
113 header.Nsubhalos = ntot_type[0];
114 header.TotNsubhalos = TotNsubhalos;
118void treelinks_io::read_file_header(
const char *fname,
int filenr,
int readTask,
int lastTask,
long long *n_type,
long long *ntot_type,
124void treelinks_io::write_header_fields(hid_t handle)
133void treelinks_io::read_header_fields(
const char *fname)
137int treelinks_io::get_filenr_from_header(
void) {
return header.num_files; }
139void treelinks_io::set_filenr_in_header(
int numfiles) { header.num_files = numfiles; }
141void treelinks_io::read_increase_numbers(
int type,
int n_for_this_task)
145void treelinks_io::get_datagroup_name(
int type,
char *buf)
150 sprintf(buf,
"/Subhalo");
158int treelinks_io::get_type_of_element(
int index)
164void treelinks_io::set_type_of_element(
int index,
int type)
168void *treelinks_io::get_base_address_of_structure(
enum arrays array,
int index)
173 return (
void *)(MergerTree->TreeLink + index);
175 Terminate(
"strange, we don't expect to get here");
global_data_all_processes All
#define MAXLEN_PATH_EXTRA
void write_scalar_attribute(hid_t handle, const char *attr_name, const void *buf, hid_t mem_type_id)
char OutputDir[MAXLEN_PATH]