Skip to content
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

Merged
merged 33 commits into from
Jul 12, 2018
Merged

Refactor part mesh tool #2159

merged 33 commits into from
Jul 12, 2018

Conversation

endJunction
Copy link
Member

@endJunction endJunction commented Jul 9, 2018

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:

  • Extract the metis handling in own files.
  • Add -o flag for output directory.
  • A test for ascii and binary output of the 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.

Copy link
Member

@wenqing wenqing left a 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
Copy link
Member

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.

Copy link
Collaborator

@chleh chleh left a 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 +
Copy link
Collaborator

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.

Copy link
Member Author

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 + "\"" + ...;

Copy link
Collaborator

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.

Copy link
Collaborator

@chleh chleh Jul 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
else if (num_partitions == 1 && exe_metis_flag.getValue())
{
Copy link
Collaborator

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wenqing Please comment.

Copy link
Member

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();
Copy link
Collaborator

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)
Copy link
Collaborator

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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is anywhere endianness indicated?

Copy link
Member Author

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 ;)

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no requirements?

Copy link
Member Author

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>
Copy link
Collaborator

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,
Copy link
Collaborator

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.

@@ -20,6 +20,14 @@ namespace MeshLib

enum class MeshItemType { Node, Edge, Face, Cell, IntegrationPoint };

/// Returns a string output for a specific error flag
Copy link
Collaborator

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);
});
Copy link
Collaborator

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.

@endJunction
Copy link
Member Author

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.
{
OGS_FATAL("Could not open file '%s' for output.", file_name.c_str());
}
return os;
Copy link
Collaborator

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?

Copy link
Member Author

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

Copy link
Member Author

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.)...

@@ -12,9 +12,6 @@ set(REQUIRED_SUBMODULES
ThirdParty/tetgen
${OGS_ADDITIONAL_SUBMODULES_TO_CHECKOUT}
)
if(OGS_BUILD_METIS)
list(APPEND REQUIRED_SUBMODULES ThirdParty/metis)
Copy link
Member

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

@bilke
Copy link
Member

bilke commented Jul 12, 2018

@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.
@endJunction endJunction merged commit ae82fdd into ufz:master Jul 12, 2018
@endJunction endJunction deleted the RefactorPartMeshTool branch July 12, 2018 19:05
@ogsbot
Copy link
Member

ogsbot commented Jun 19, 2020

OpenGeoSys development has been moved to GitLab.

See this pull request on GitLab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants