Skip to content
Snippets Groups Projects
Commit 081cfea0 authored by Tom Fischer's avatar Tom Fischer
Browse files

[MeL/IO/MPI_IO] Refactor readNodePropertiesBinary.

parent 7e5012fc
No related branches found
No related tags found
No related merge requests found
...@@ -198,20 +198,25 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readBinary( ...@@ -198,20 +198,25 @@ MeshLib::NodePartitionedMesh* NodePartitionedMeshReader::readBinary(
MeshLib::Properties NodePartitionedMeshReader::readPropertiesBinary( MeshLib::Properties NodePartitionedMeshReader::readPropertiesBinary(
const std::string& file_name_base) const const std::string& file_name_base) const
{ {
return readNodePropertiesBinary(file_name_base); MeshLib::Properties p;
readNodePropertiesBinary(file_name_base, MeshLib::MeshItemType::Node, p);
return p;
} }
MeshLib::Properties NodePartitionedMeshReader::readNodePropertiesBinary( void NodePartitionedMeshReader::readNodePropertiesBinary(
const std::string& file_name_base) const const std::string& file_name_base, MeshLib::MeshItemType t,
MeshLib::Properties& p) const
{ {
const std::string fname_cfg = file_name_base + std::string const item_type =
"_partitioned_node_properties_cfg" + t == MeshLib::MeshItemType::Node ? "node" : "cell";
const std::string fname_cfg = file_name_base + "_partitioned_" + item_type +
"_properties_cfg" +
std::to_string(_mpi_comm_size) + ".bin"; std::to_string(_mpi_comm_size) + ".bin";
std::ifstream is(fname_cfg.c_str(), std::ios::binary | std::ios::in); std::ifstream is(fname_cfg.c_str(), std::ios::binary | std::ios::in);
if (!is) if (!is)
{ {
WARN("Could not open file '%s' in binary mode.", fname_cfg.c_str()); WARN("Could not open file '%s' in binary mode.", fname_cfg.c_str());
return MeshLib::Properties(); return;
} }
std::size_t number_of_properties = 0; std::size_t number_of_properties = 0;
is.read(reinterpret_cast<char*>(&number_of_properties), sizeof(std::size_t)); is.read(reinterpret_cast<char*>(&number_of_properties), sizeof(std::size_t));
...@@ -257,8 +262,8 @@ MeshLib::Properties NodePartitionedMeshReader::readNodePropertiesBinary( ...@@ -257,8 +262,8 @@ MeshLib::Properties NodePartitionedMeshReader::readNodePropertiesBinary(
DBUG("[%d] %d tuples in partition.", _mpi_rank, pvpmd->number_of_tuples); DBUG("[%d] %d tuples in partition.", _mpi_rank, pvpmd->number_of_tuples);
is.close(); is.close();
const std::string fname_val = file_name_base + const std::string fname_val = file_name_base + "_partitioned_" + item_type +
"_partitioned_node_properties_val" + "_properties_val" +
std::to_string(_mpi_comm_size) + ".bin"; std::to_string(_mpi_comm_size) + ".bin";
is.open(fname_val.c_str(), std::ios::binary | std::ios::in); is.open(fname_val.c_str(), std::ios::binary | std::ios::in);
if (!is) if (!is)
...@@ -266,25 +271,34 @@ MeshLib::Properties NodePartitionedMeshReader::readNodePropertiesBinary( ...@@ -266,25 +271,34 @@ MeshLib::Properties NodePartitionedMeshReader::readNodePropertiesBinary(
ERR("Could not open file '%s' in binary mode.", fname_val.c_str()); ERR("Could not open file '%s' in binary mode.", fname_val.c_str());
} }
MeshLib::Properties p; readDomainSpecificPartOfPropertyVectors(vec_pvmd, *pvpmd, t, is, p);
}
// Read the specific parts of the PropertyVector values for this process. void NodePartitionedMeshReader::readDomainSpecificPartOfPropertyVectors(
std::vector<boost::optional<MeshLib::IO::PropertyVectorMetaData>> const&
vec_pvmd,
MeshLib::IO::PropertyVectorPartitionMetaData const& pvpmd,
MeshLib::MeshItemType t,
std::istream& is,
MeshLib::Properties& p) const
{
unsigned long global_offset = 0; unsigned long global_offset = 0;
std::size_t const number_of_properties = vec_pvmd.size();
for (std::size_t i(0); i < number_of_properties; ++i) for (std::size_t i(0); i < number_of_properties; ++i)
{ {
INFO("[%d] global offset: %d, offset within the PropertyVector: %d.", DBUG("[%d] global offset: %d, offset within the PropertyVector: %d.",
_mpi_rank, global_offset, _mpi_rank, global_offset,
global_offset + global_offset +
pvpmd->offset * vec_pvmd[i]->data_type_size_in_bytes); pvpmd.offset * vec_pvmd[i]->data_type_size_in_bytes);
if (vec_pvmd[i]->is_int_type) if (vec_pvmd[i]->is_int_type)
{ {
if (vec_pvmd[i]->is_data_type_signed) if (vec_pvmd[i]->is_data_type_signed)
{ {
if (vec_pvmd[i]->data_type_size_in_bytes == sizeof(int)) if (vec_pvmd[i]->data_type_size_in_bytes == sizeof(int))
createPropertyVectorPart<int>(is, *vec_pvmd[i], *pvpmd, createPropertyVectorPart<int>(is, *vec_pvmd[i], pvpmd,
global_offset, p); global_offset, p);
if (vec_pvmd[i]->data_type_size_in_bytes == sizeof(long)) if (vec_pvmd[i]->data_type_size_in_bytes == sizeof(long))
createPropertyVectorPart<long>(is, *vec_pvmd[i], *pvpmd, createPropertyVectorPart<long>(is, *vec_pvmd[i], pvpmd,
global_offset, p); global_offset, p);
} }
else else
...@@ -292,32 +306,31 @@ MeshLib::Properties NodePartitionedMeshReader::readNodePropertiesBinary( ...@@ -292,32 +306,31 @@ MeshLib::Properties NodePartitionedMeshReader::readNodePropertiesBinary(
if (vec_pvmd[i]->data_type_size_in_bytes == if (vec_pvmd[i]->data_type_size_in_bytes ==
sizeof(unsigned int)) sizeof(unsigned int))
createPropertyVectorPart<unsigned int>( createPropertyVectorPart<unsigned int>(
is, *vec_pvmd[i], *pvpmd, global_offset, p); is, *vec_pvmd[i], pvpmd, global_offset, p);
if (vec_pvmd[i]->data_type_size_in_bytes == if (vec_pvmd[i]->data_type_size_in_bytes ==
sizeof(unsigned long)) sizeof(unsigned long))
createPropertyVectorPart<unsigned long>( createPropertyVectorPart<unsigned long>(
is, *vec_pvmd[i], *pvpmd, global_offset, p); is, *vec_pvmd[i], pvpmd, global_offset, p);
} }
} }
else else
{ {
if (vec_pvmd[i]->data_type_size_in_bytes == sizeof(float)) if (vec_pvmd[i]->data_type_size_in_bytes == sizeof(float))
createPropertyVectorPart<float>(is, *vec_pvmd[i], *pvpmd, createPropertyVectorPart<float>(is, *vec_pvmd[i], pvpmd,
global_offset, p); global_offset, p);
if (vec_pvmd[i]->data_type_size_in_bytes == sizeof(double)) if (vec_pvmd[i]->data_type_size_in_bytes == sizeof(double))
createPropertyVectorPart<double>(is, *vec_pvmd[i], *pvpmd, createPropertyVectorPart<double>(is, *vec_pvmd[i], pvpmd,
global_offset, p); global_offset, p);
} }
global_offset += vec_pvmd[i]->data_type_size_in_bytes * global_offset += vec_pvmd[i]->data_type_size_in_bytes *
vec_pvmd[i]->number_of_tuples * vec_pvmd[i]->number_of_tuples *
vec_pvmd[i]->number_of_components; vec_pvmd[i]->number_of_components;
} }
return p;
} }
bool NodePartitionedMeshReader::openASCIIFiles(std::string const& file_name_base, bool NodePartitionedMeshReader::openASCIIFiles(
std::ifstream& is_cfg, std::ifstream& is_node, std::ifstream& is_elem) const std::string const& file_name_base, std::ifstream& is_cfg,
std::ifstream& is_node, std::ifstream& is_elem) const
{ {
const std::string fname_header = file_name_base + "_partitioned_"; const std::string fname_header = file_name_base + "_partitioned_";
const std::string fname_num_p_ext = std::to_string(_mpi_comm_size) + ".msh"; const std::string fname_num_p_ext = std::to_string(_mpi_comm_size) + ".msh";
......
...@@ -168,8 +168,17 @@ private: ...@@ -168,8 +168,17 @@ private:
MeshLib::Properties readPropertiesBinary( MeshLib::Properties readPropertiesBinary(
const std::string& file_name_base) const; const std::string& file_name_base) const;
MeshLib::Properties readNodePropertiesBinary( void readNodePropertiesBinary(const std::string& file_name_base,
const std::string& file_name_base) const; MeshLib::MeshItemType t,
MeshLib::Properties& p) const;
void readDomainSpecificPartOfPropertyVectors(
std::vector<boost::optional<MeshLib::IO::PropertyVectorMetaData>> const&
vec_pvmd,
MeshLib::IO::PropertyVectorPartitionMetaData const& pvpmd,
MeshLib::MeshItemType t,
std::istream& is,
MeshLib::Properties& p) const;
template <typename T> template <typename T>
void createPropertyVectorPart( void createPropertyVectorPart(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment