-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor part mesh tool #2159
Refactor part mesh tool #2159
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -16,6 +16,7 @@ | |||
|
|||
#include <cstdio> // for binary output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since fwrite is replaced with iostream::write, this include can be removed. In additional, I had ever experienced that MPI_file_read could not read the binary by iostream::write. The reason might be that MPI was complied by using old C compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Only minor comments.
} | ||
else if (num_partitions == 1 && exe_metis_flag.getValue()) | ||
const std::string mpmetis_com = | ||
exe_path + "/mpmetis " + " -gtype=nodal " + file_name_base + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem: file_name_base
could contain spaces (especially if the file name is a full/relative path name).
Cf. https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152177
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The execve
solution is very clumsy for this. Would adding "
around the filename suffice?
... + "\"" + file_name_base + "\"" + ...;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the time being that would already be an improvement. Adding single quotes '
might be slightly better. Maybe in the future we should write a small function for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or boost for the rescue (in the future):
https://www.boost.org/doc/libs/1_67_0/doc/html/boost_process/tutorial.html#boost_process.tutorial.starting_a_process
} | ||
} | ||
else if (num_partitions == 1 && exe_metis_flag.getValue()) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we drop that branch entirely since OGS has support for PETSc reading vtu files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wenqing Please comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As suggested by @chleh, that branch can be replaced by OGS_FATAL as
OGS_FATAL("Partitioning the mesh into one domain is unnecessary because OGS reads vtu mesh data directly when np=1 ")
OGS_FATAL("Error while reading file %s.", fname_parts.data()); | ||
} | ||
|
||
npart_in.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary
@@ -79,6 +75,13 @@ class NodeWiseMeshPartitioner | |||
/// \param file_name_base The prefix of the file name. | |||
void writeBinary(const std::string& file_name_base); | |||
|
|||
void resetPartitionIdsForNodes(std::vector<std::size_t> node_partition_ids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the argument be an rvalue ref, too?
Probably the caller never wants to copy that arg.
coords[1], coords[2]); | ||
} | ||
return os.write(reinterpret_cast<const char*>(nodes_buffer.data()), | ||
sizeof(NodeStruct) * nodes_buffer.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is anywhere endianness indicated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in the sky ;)
Applications/Utils/Tests.cmake
Outdated
PATH NodePartitionedMesh/partmesh_2Dmesh_3partitions | ||
EXECUTABLE partmesh | ||
EXECUTABLE_ARGS -a -m -n 3 -i 2Dmesh.vtu -o ${Data_BINARY_DIR}/NodePartitionedMesh/partmesh_2Dmesh_3partitions | ||
REQUIREMENTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no requirements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say no restrictions...
} | ||
return true; | ||
} | ||
|
||
template <typename Function> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this code would be easier to understand if you would provide the function copy_property_vector
right here abov this line and not pass it as a lambda argument.
template <typename Function> | ||
void copyPropertyVectors(std::vector<std::string> const& property_names, | ||
Function copy_property_vector) | ||
void applyPropertyVectors(std::vector<std::string> const& property_names, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, It's an abstraction. But is that really needed? And maybe applyToPropertyVectors
would be a better name.
MeshLib/Location.h
Outdated
@@ -20,6 +20,14 @@ namespace MeshLib | |||
|
|||
enum class MeshItemType { Node, Edge, Face, Cell, IntegrationPoint }; | |||
|
|||
/// Returns a string output for a specific error flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MeshItemType
instead of error flag? Maybe the spelling should be the same as in the enum, i.e., CamelCase.
[&](auto type, std::string const& name) { | ||
return writePropertyVectorBinary<decltype(type)>( | ||
partitioned_properties, name, out_val, out); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, here, some code duplication is reduced.
Ok. Almost there. I had to remove the BL::createBinaryFile() again, because of gcc<5. @bilke Two points for discussion: Can we see what is different on the mac results? Why is it that on the docker-conan node metis' cmake is not finding GKlib (was probably not tested before)? |
This required an access function to the partion ids and the mesh.
The 2Dmesh contains higher order quad8 elements and line3 elements. Scalar and vectorial point and cell data arrays are present. This is copy of a LIE single-fracture benchmark result.
BaseLib/FileTools.cpp
Outdated
{ | ||
OGS_FATAL("Could not open file '%s' for output.", file_name.c_str()); | ||
} | ||
return os; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the problem? Missing copy elision?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The move operator is not implemented as I understood. https://stackoverflow.com/a/28775806
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another one not working on gcc < 5:
struct A { int a; int b = 0; };
void f() { A a = {2, 3}; }
// or
A g() { return {4, 5}; }
because the struct with default initializers cannot be constructed from initializer list; see https://stackoverflow.com/a/37777814
Happened here: https://jenkins.opengeosys.org/blue/organizations/jenkins/ufz%2Fogs/detail/PR-2159/13/pipeline/
I think it's time to move to minimum gcc 5.3 (5.2 had an internal compiler error in the other PR.)...
scripts/cmake/SubmoduleSetup.cmake
Outdated
@@ -12,9 +12,6 @@ set(REQUIRED_SUBMODULES | |||
ThirdParty/tetgen | |||
${OGS_ADDITIONAL_SUBMODULES_TO_CHECKOUT} | |||
) | |||
if(OGS_BUILD_METIS) | |||
list(APPEND REQUIRED_SUBMODULES ThirdParty/metis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@endJunction You need to add the submodule to the list of required submodules
@endJunction To get the diff output you may want to change https://github.com/ufz/ogs/blob/master/scripts/cmake/test/AddTestTester.cmake#L49 to message(FATAL_ERROR "Error exit code: ${EXIT_CODE}\n${OUTPUT}") |
A higher order 2D mesh with mixed quad8/line3 elements, scalar and vectorial, point and cell data is tested.
Extract both the original function from the class and a function for a partition.
It's not accessing any members of the class.
Also extract a code enumerating the partition's local nodes.
Split "config_data" into partition data and offsets.
Extract specific (to node or cell) functions, generalize some of the loops. There are still some code duplications, but more difficult to extract...
This allows to unify the processNodeProperties() and the processCellProperties().
The reinterpret cast seems to more appropriate in context of writing of binary values to a stream.
Remove code duplication and use applyPropertyVector.
CL: "It would be better to use boost::process" https://www.boost.org/doc/libs/1_67_0/doc/html/boost_process/tutorial.html#boost_process.tutorial.starting_a_process
The move ctor is not implemented in gcc < 5.
The dependencies include targets like partmesh and MapGeometryToMeshSurface which are referenced in Tests.cmake.
OpenGeoSys development has been moved to GitLab. |
Major refactoring of the
partmesh
tool as preparation for the boundary mesh partitioning conforming to a partitioned mesh.The refactorings try to separate the write functions from the
NodeWiseMeshPartitioner
class as first step, and remove code duplications in the second.There are still some type and variable names, I'm not happy about but don't know a better name for now.
Other notable changes:
-o
flag for output directory.partmesh
tool is added.Review commit-wise for understanding the changes. The changes include a new file (needed for test) which is 1176 lines, so netto we have +795 -610.