diff --git a/include/HDF_IO.hh b/include/HDF_IO.hh index 1b15b34..a8a50b6 100755 --- a/include/HDF_IO.hh +++ b/include/HDF_IO.hh @@ -886,6 +886,60 @@ inline void HDFWriteDatasetVector( const std::string Filename, const std::string H5Fclose( HDF_FileID ); } +template< typename T > +inline void HDFCreateEmptyDataset( const std::string Filename, const std::string ObjName, const size_t num_particles) +{ + + hid_t + HDF_FileID, + HDF_DatasetID, + HDF_DataspaceID, + HDF_Type; + + hsize_t HDF_Dims; + + HDF_FileID = H5Fopen( Filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT ); + + HDF_Type = GetDataType(); + + HDF_Dims = (hsize_t) (num_particles); + HDF_DataspaceID = H5Screate_simple(1, &HDF_Dims, NULL); + HDF_DatasetID = H5Dcreate( HDF_FileID, ObjName.c_str(), HDF_Type, + HDF_DataspaceID, H5P_DEFAULT ); + H5Dclose( HDF_DatasetID ); + H5Sclose( HDF_DataspaceID ); + + H5Fclose( HDF_FileID ); +} + +template< typename T > +inline void HDFCreateEmptyDatasetVector( const std::string Filename, const std::string ObjName, const size_t num_particles) +{ + + hid_t + HDF_FileID, + HDF_DatasetID, + HDF_DataspaceID, + HDF_Type; + + hsize_t HDF_Dims[2]; + + HDF_FileID = H5Fopen( Filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT ); + + HDF_Type = GetDataType(); + + HDF_Dims[0] = (hsize_t) (num_particles); + HDF_Dims[1] = (hsize_t) 3; + + HDF_DataspaceID = H5Screate_simple(2, HDF_Dims, NULL); + HDF_DatasetID = H5Dcreate( HDF_FileID, ObjName.c_str(), HDF_Type, + HDF_DataspaceID, H5P_DEFAULT ); + H5Dclose( HDF_DatasetID ); + H5Sclose( HDF_DataspaceID ); + H5Fclose( HDF_FileID ); + +} + inline void HDFCreateGroup( const std::string Filename, const std::string GroupName ) { hid_t HDF_FileID, HDF_GroupID; diff --git a/src/plugins/output_swift.cc b/src/plugins/output_swift.cc index ab32d6a..06e85c8 100644 --- a/src/plugins/output_swift.cc +++ b/src/plugins/output_swift.cc @@ -60,7 +60,7 @@ public: // SWIFT uses a single file as IC */ num_files_ = 1; this_rank_ = 0; - num_files_ = 1; + num_ranks_ = 1; real_t astart = 1.0 / (1.0 + cf_.get_value("setup", "zstart")); const double rhoc = 27.7519737; // in h^2 1e10 M_sol / Mpc^3 @@ -251,7 +251,45 @@ public: else mass_[sid] = Omega_species * munit_ / pc.get_global_num_particles(); - HDFCreateGroup(fname_, std::string("PartType") + std::to_string(sid)); + const size_t global_num_particles = pc.get_global_num_particles(); + + // start by creating the full empty datasets in the file + if (this_rank_ == 0) { + + HDFCreateGroup(fname_, std::string("PartType") + std::to_string(sid)); + + if (this->has_64bit_reals()) + { + HDFCreateEmptyDatasetVector(fname_, std::string("PartType") + std::to_string(sid) + std::string("/Coordinates"), global_num_particles); + HDFCreateEmptyDatasetVector(fname_, std::string("PartType") + std::to_string(sid) + std::string("/Velocities"), global_num_particles); + } + else + { + HDFCreateEmptyDatasetVector(fname_, std::string("PartType") + std::to_string(sid) + std::string("/Coordinates"), global_num_particles); + HDFCreateEmptyDatasetVector(fname_, std::string("PartType") + std::to_string(sid) + std::string("/Velocities"), global_num_particles); + } + + if (this->has_64bit_ids()) + HDFCreateEmptyDataset(fname_, std::string("PartType") + std::to_string(sid) + std::string("/ParticleIDs"), global_num_particles); + else + HDFCreateEmptyDataset(fname_, std::string("PartType") + std::to_string(sid) + std::string("/ParticleIDs"), global_num_particles); + + if( pc.bhas_individual_masses_ ){ + if (this->has_64bit_reals()) + HDFCreateEmptyDataset(fname_, std::string("PartType") + std::to_string(sid) + std::string("/Masses"), global_num_particles); + else + HDFCreateEmptyDataset(fname_, std::string("PartType") + std::to_string(sid) + std::string("/Masses"), global_num_particles); + } + + if( bdobaryons_ && s == cosmo_species::baryon) { + + // note: despite this being a constant array we still need to handle it in a distributed way + HDFCreateEmptyDataset(fname_, std::string("PartType") + std::to_string(sid) + std::string("/InternalEnergy"), global_num_particles); + HDFCreateEmptyDataset(fname_, std::string("PartType") + std::to_string(sid) + std::string("/SmoothinLength"), global_num_particles); + } + } + + // Now each node writes its own chunk in a round-robin fashion, appending at the end of the currently existing data //... write positions and velocities..... if (this->has_64bit_reals())