Skip to content
Snippets Groups Projects
Commit b7d9fb5b authored by wenqing's avatar wenqing
Browse files

[PMesh] Let mpmetis be called via system() and changed METIS repository.

parent c1f7f7e1
No related branches found
No related tags found
No related merge requests found
...@@ -24,4 +24,4 @@ ...@@ -24,4 +24,4 @@
url = https://github.com/ufz/vtkGUISupportQt.git url = https://github.com/ufz/vtkGUISupportQt.git
[submodule "ThirdParty/metis"] [submodule "ThirdParty/metis"]
path = ThirdParty/metis path = ThirdParty/metis
url = https://github.com/envinf/metis.git url = https://github.com/scibuilder/metis.git
### ###
add_executable(partmesh PartitionMesh.cpp MeshPartitioning.h MeshPartitioning.cpp) add_executable(partmesh PartitionMesh.cpp MeshPartitioning.h MeshPartitioning.cpp)
set_target_properties(partmesh PROPERTIES FOLDER Utilities) set_target_properties(partmesh PROPERTIES FOLDER Utilities)
target_link_libraries(partmesh FileIO) target_link_libraries(partmesh MeshLib)
if(UTILS_PARTMESH_BUILD_WITH_METIS)
include_directories(${METIS_PATH}/libmetis)
include_directories(${METIS_PATH}/programs)
set(METIS_SOURCES
${METIS_PATH}/programs/mpmetis.c
${METIS_PATH}/programs/cmdline_mpmetis.c
${METIS_PATH}/programs/io.c
${METIS_PATH}/programs/stat.c
metis_main.h
)
ADD_LIBRARY(METIS_Lib STATIC ${METIS_SOURCES} )
target_link_libraries(partmesh METIS_Lib metis)
endif()
ADD_VTK_DEPENDENCY(partmesh) ADD_VTK_DEPENDENCY(partmesh)
...@@ -31,3 +15,25 @@ cpack_add_component(ogs_partmesh ...@@ -31,3 +15,25 @@ cpack_add_component(ogs_partmesh
DESCRIPTION "Mesh partitioning tool." DESCRIPTION "Mesh partitioning tool."
GROUP Utilities GROUP Utilities
) )
## Compile mpmetis
add_definitions(-DSVNINFO="${SVNREV}")
include_directories(${METIS_PATH}/libmetis)
include_directories(${METIS_PATH}/programs)
set(METIS_SOURCES
${METIS_PATH}/programs/mpmetis.c
${METIS_PATH}/programs/cmdline_mpmetis.c
${METIS_PATH}/programs/io.c
${METIS_PATH}/programs/stat.c
)
add_executable(mpmetis ${METIS_SOURCES})
target_link_libraries(mpmetis metis)
install(TARGETS mpmetis RUNTIME DESTINATION bin COMPONENT ogs_metis)
cpack_add_component(ogs_metis
DISPLAY_NAME "mpmetis"
DESCRIPTION "METIS."
GROUP Utilities
)
...@@ -30,7 +30,7 @@ void MeshPartitioning :: write2METIS(const std::string& file_name) ...@@ -30,7 +30,7 @@ void MeshPartitioning :: write2METIS(const std::string& file_name)
os << _elements.size() <<" \n"; os << _elements.size() <<" \n";
for (const auto elem : _elements) for (const auto elem : _elements)
{ {
for (unsigned j=0; j<elem->getNNodes(); j++) for (unsigned j=0; j<elem->getNumberOfNodes(); j++)
{ {
os << elem->getNodeIndex(j) + 1 <<" "; os << elem->getNodeIndex(j) + 1 <<" ";
} }
...@@ -192,7 +192,7 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -192,7 +192,7 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
std::vector<unsigned> nonghost_nodes_local_ids; std::vector<unsigned> nonghost_nodes_local_ids;
unsigned ghost_counter = 0; unsigned ghost_counter = 0;
for (unsigned kk=0; kk<elem->getNNodes(); kk++) for (unsigned kk=0; kk<elem->getNumberOfNodes(); kk++)
{ {
if (nodes_reseved[elem->getNodeIndex(kk)]) if (nodes_reseved[elem->getNodeIndex(kk)])
{ {
...@@ -225,7 +225,7 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -225,7 +225,7 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
// Mark the non-ghost nodes for each ghost element // Mark the non-ghost nodes for each ghost element
for (const auto ghost_elem : partition_ghost_elements) for (const auto ghost_elem : partition_ghost_elements)
{ {
for (unsigned k=0; k<ghost_elem->getNNodes(); k++) for (unsigned k=0; k<ghost_elem->getNumberOfNodes(); k++)
nodes_reseved[ghost_elem->getNodeIndex(k)] = false; nodes_reseved[ghost_elem->getNodeIndex(k)] = false;
// Mark non-ghost nodes // Mark non-ghost nodes
...@@ -236,7 +236,7 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -236,7 +236,7 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
// Add the ghost nodes to the node vector of this partition // Add the ghost nodes to the node vector of this partition
for (const auto ghost_elem : partition_ghost_elements) for (const auto ghost_elem : partition_ghost_elements)
{ {
for (unsigned k=0; k<ghost_elem->getNNodes(); k++) for (unsigned k=0; k<ghost_elem->getNumberOfNodes(); k++)
{ {
const unsigned node_id = ghost_elem->getNodeIndex(k); const unsigned node_id = ghost_elem->getNodeIndex(k);
if (nodes_reseved[node_id]) if (nodes_reseved[node_id])
...@@ -279,13 +279,13 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base, ...@@ -279,13 +279,13 @@ void MeshPartitioning :: partitionByNodeMETIS(const std::string& file_name_base,
PetscInt nmb_element_idxs = 3 * num_non_ghost_elems; PetscInt nmb_element_idxs = 3 * num_non_ghost_elems;
for (PetscInt j=0; j<num_non_ghost_elems; j++) for (PetscInt j=0; j<num_non_ghost_elems; j++)
{ {
nmb_element_idxs += partition_regular_elements[j]->getNNodes(); nmb_element_idxs += partition_regular_elements[j]->getNumberOfNodes();
} }
const PetscInt num_ghost_elems = partition_ghost_elements.size(); const PetscInt num_ghost_elems = partition_ghost_elements.size();
PetscInt nmb_element_idxs_g = 3 * num_ghost_elems; PetscInt nmb_element_idxs_g = 3 * num_ghost_elems;
for (PetscInt j=0; j<num_ghost_elems; j++) for (PetscInt j=0; j<num_ghost_elems; j++)
{ {
nmb_element_idxs_g += partition_ghost_elements[j]->getNNodes(); nmb_element_idxs_g += partition_ghost_elements[j]->getNumberOfNodes();
} }
std::string ipart_str = std::to_string(ipart); std::string ipart_str = std::to_string(ipart);
...@@ -465,7 +465,7 @@ void MeshPartitioning::getElementIntegerVariables(const Element& elem, ...@@ -465,7 +465,7 @@ void MeshPartitioning::getElementIntegerVariables(const Element& elem,
PetscInt& counter) PetscInt& counter)
{ {
unsigned mat_id = 0; // Materical ID to be set from the mesh data unsigned mat_id = 0; // Materical ID to be set from the mesh data
const PetscInt nn = elem.getNNodes();; const PetscInt nn = elem.getNumberOfNodes();;
elem_info[counter++] = mat_id; elem_info[counter++] = mat_id;
elem_info[counter++] = static_cast<unsigned>(getElementType(elem)) + 1; elem_info[counter++] = static_cast<unsigned>(getElementType(elem)) + 1;
elem_info[counter++] = nn; elem_info[counter++] = nn;
...@@ -481,8 +481,8 @@ void MeshPartitioning::writeLocalElementNodeIndicies(std::ostream& os, const Ele ...@@ -481,8 +481,8 @@ void MeshPartitioning::writeLocalElementNodeIndicies(std::ostream& os, const Ele
{ {
unsigned mat_id = 0; // Materical ID to be set from the mesh data unsigned mat_id = 0; // Materical ID to be set from the mesh data
os << mat_id << " " << static_cast<unsigned>(getElementType(elem)) + 1 << " " os << mat_id << " " << static_cast<unsigned>(getElementType(elem)) + 1 << " "
<< elem.getNNodes() <<" "; << elem.getNumberOfNodes() <<" ";
for(unsigned i=0; i<elem.getNNodes(); i++) for(unsigned i=0; i<elem.getNumberOfNodes(); i++)
{ {
os << local_node_ids[elem.getNodeIndex(i)] << " "; os << local_node_ids[elem.getNodeIndex(i)] << " ";
} }
......
MESSAGE( STATUS "The METIS package is copyrighted by the Regents of the University of Minnesota." ) MESSAGE( STATUS "The METIS package is copyrighted by the Regents of the University of Minnesota." )
MESSAGE( STATUS "Please read the license of the METIS package carefully before you use the METIS." ) MESSAGE( STATUS "Please read the license of the METIS package carefully before you use the METIS." )
set(METIS_PATH "${CMAKE_SOURCE_DIR}/ThirdParty/metis")
add_definitions(-DUSE_GKREGEX) add_definitions(-DUSE_GKREGEX)
set(GKLIB_PATH "${METIS_PATH}/GKlib" CACHE PATH "path to GKlib") set(GKLIB_PATH "${METIS_PATH}/GKlib" CACHE PATH "path to GKlib")
......
...@@ -12,13 +12,8 @@ ...@@ -12,13 +12,8 @@
*/ */
#include "tclap/CmdLine.h" #include <sstream>
#include <tclap/CmdLine.h>
#ifdef BUILD_WITH_METIS
extern "C" {
#include "metis_main.h"
}
#endif
#include "Applications/ApplicationsLib/LogogSetup.h" #include "Applications/ApplicationsLib/LogogSetup.h"
#include "BaseLib/FileTools.h" #include "BaseLib/FileTools.h"
...@@ -54,6 +49,8 @@ int main (int argc, char* argv[]) ...@@ -54,6 +49,8 @@ int main (int argc, char* argv[])
TCLAP::SwitchArg ogs2metis_flag("1", "ogs2metis", TCLAP::SwitchArg ogs2metis_flag("1", "ogs2metis",
"Indicator to convert the ogs mesh file to METIS input file", cmd, false); "Indicator to convert the ogs mesh file to METIS input file", cmd, false);
TCLAP::SwitchArg exe_metis_flag("m","exe_metis","Call mpmetis inside the programme via system().", false);
cmd.add(exe_metis_flag);
TCLAP::SwitchArg asci_flag("a","asci","Enable ASCII output.", false); TCLAP::SwitchArg asci_flag("a","asci","Enable ASCII output.", false);
cmd.add(asci_flag); cmd.add(asci_flag);
TCLAP::SwitchArg elem_part_flag("e","element_wise","Enable element wise partitioing.", false); TCLAP::SwitchArg elem_part_flag("e","element_wise","Enable element wise partitioing.", false);
...@@ -70,7 +67,7 @@ int main (int argc, char* argv[]) ...@@ -70,7 +67,7 @@ int main (int argc, char* argv[])
const std::string file_name_base = BaseLib::dropFileExtension(ifile_name); const std::string file_name_base = BaseLib::dropFileExtension(ifile_name);
MeshLib::MeshPartitioning* mesh = static_cast<MeshLib::MeshPartitioning*> MeshLib::MeshPartitioning* mesh = static_cast<MeshLib::MeshPartitioning*>
(MeshLib::IO::readMeshFromFile(file_name_base + ".vtu")); (MeshLib::IO::readMeshFromFile(file_name_base + ".vtu"));
INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); INFO("Mesh read: %d nodes, %d elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements());
if (ogs2metis_flag.getValue()) if (ogs2metis_flag.getValue())
{ {
...@@ -89,23 +86,17 @@ int main (int argc, char* argv[]) ...@@ -89,23 +86,17 @@ int main (int argc, char* argv[])
const int num_partitions = nparts.getValue(); const int num_partitions = nparts.getValue();
std::string str_nparts = std::to_string(num_partitions); std::string str_nparts = std::to_string(num_partitions);
// With the metis source code being compiled // Execute mpmetis via system(...)
if (num_partitions > 1) if (num_partitions > 1 && exe_metis_flag.getValue())
{ {
#ifdef BUILD_WITH_METIS
INFO("METIS is running ..."); INFO("METIS is running ...");
const int argc_m = 4; std::stringstream ss;
char *argv_m[argc_m]; ss << "mpmetis " << " -gtype=nodal "
std::string unsc = "-"; // Avoid compilation warning by argv_m[0] = "-"; << file_name_base + ".mesh "
argv_m[0] = &unsc[0]; << nparts.getValue();
std::string option = "-gtype=nodal";
argv_m[1] = &option[0]; int status = system(ss.str().c_str());
std::string part_mesh_file = file_name_base + ".mesh"; INFO("Return value of system calling %d ", status);
argv_m[2] = &part_mesh_file[0];
argv_m[3] = &str_nparts[0];
metis_main(argc_m, argv_m);
#endif
} }
INFO("Partitioning the mesh in the node wise way ..."); INFO("Partitioning the mesh in the node wise way ...");
...@@ -123,5 +114,7 @@ int main (int argc, char* argv[]) ...@@ -123,5 +114,7 @@ int main (int argc, char* argv[])
INFO( "Total runtime: %g s.\n", run_timer.elapsed() ); INFO( "Total runtime: %g s.\n", run_timer.elapsed() );
INFO( "Total CPU time: %g s.\n", CPU_timer.elapsed() ); INFO( "Total CPU time: %g s.\n", CPU_timer.elapsed() );
return 0; delete mesh;
return EXIT_SUCCESS;
} }
...@@ -150,6 +150,10 @@ if(OGS_BUILD_TESTS) ...@@ -150,6 +150,10 @@ if(OGS_BUILD_TESTS)
set(Data_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/Tests/Data CACHE INTERNAL "") set(Data_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/Tests/Data CACHE INTERNAL "")
endif() endif()
if(OGS_BUILD_UTILS)
include(${CMAKE_SOURCE_DIR}/Applications/Utils/ModelPreparation/PartitionMesh/MetisSetup.cmake)
endif()
###################### ######################
### Subdirectories ### ### Subdirectories ###
###################### ######################
......
Subproject commit 0f44bee3cab5d5453d4fff7cd877c0d4b858f72b
...@@ -12,12 +12,18 @@ set(REQUIRED_SUBMODULES ...@@ -12,12 +12,18 @@ set(REQUIRED_SUBMODULES
ThirdParty/tetgen ThirdParty/tetgen
${OGS_ADDITIONAL_SUBMODULES_TO_CHECKOUT} ${OGS_ADDITIONAL_SUBMODULES_TO_CHECKOUT}
) )
if(OGS_BUILD_TESTS) if(OGS_BUILD_TESTS)
list(APPEND REQUIRED_SUBMODULES Tests/Data) list(APPEND REQUIRED_SUBMODULES Tests/Data)
endif() endif()
if(OGS_BUILD_GUI) if(OGS_BUILD_GUI)
list(APPEND REQUIRED_SUBMODULES ThirdParty/vtkGUISupportQt) list(APPEND REQUIRED_SUBMODULES ThirdParty/vtkGUISupportQt)
endif() endif()
if(OGS_BUILD_UTILS)
list(APPEND REQUIRED_SUBMODULES ThirdParty/metis)
endif()
foreach(SUBMODULE ${REQUIRED_SUBMODULES}) foreach(SUBMODULE ${REQUIRED_SUBMODULES})
execute_process( execute_process(
......
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