Skip to content

Commit

Permalink
Merge branch 'metis-upstream' into 'master'
Browse files Browse the repository at this point in the history
[cmake] Use upstream METIS

See merge request ogs/ogs!4773
  • Loading branch information
endJunction committed Oct 26, 2023
2 parents 4b960bc + 47d280a commit a5b428f
Show file tree
Hide file tree
Showing 123 changed files with 162 additions and 64 deletions.
1 change: 1 addition & 0 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ parse:
HTTP_PASSWORD: 1
EXCLUDE_FROM_ALL: 1
OPTIONS: +
PATCH_COMMAND: +
cpmfindpackage:
pargs:
nargs: "*"
Expand Down
1 change: 1 addition & 0 deletions .guix/modules/ogs-package.scm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
hdf5
json-modern-cxx
libxml2
metis
pybind11-2.10.4
python
range-v3
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md, --markdown-linebreak-ext=pandoc]
exclude: "^ThirdParty/.*|^Tests/Data/.*|^web/static|^Documentation/.vale/.*"
exclude: "^ThirdParty/.*|^Tests/Data/.*|^web/static|^Documentation/.vale/.*|.*\\.patch"
- id: check-added-large-files
args: [--maxkb 1024]
- id: check-merge-conflict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ ogs_add_executable(
partmesh PartitionMesh.cpp Metis.cpp NodeWiseMeshPartitioner.cpp
)
target_link_libraries(partmesh GitInfoLib MeshLib MeshToolsLib tclap NumLib)
add_dependencies(partmesh mpmetis)
if(TARGET mpmetis)
add_dependencies(partmesh mpmetis)
endif()
install(TARGETS partmesh RUNTIME DESTINATION bin)
4 changes: 4 additions & 0 deletions Applications/Utils/Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1411,3 +1411,7 @@ if(NOT OGS_USE_PETSC)
NotebookTest(NOTEBOOKFILE ../../web/content/docs/tutorials/mesh_tutorial/notebook-mesh_tutorial.md
RUNTIME 10)
endif()

if(OGS_USE_PETSC)
NotebookTest(NOTEBOOKFILE Utils/partmesh/partmesh_roundtrip.md RUNTIME 10 SKIP_WEB)
endif()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
42 changes: 42 additions & 0 deletions Tests/Data/Utils/partmesh/partmesh_roundtrip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
+++

+++

## `partmesh` round-trip

```python
import os

out_dir = os.environ.get('OGS_TESTRUNNER_OUT_DIR', '_out')
if not os.path.exists(out_dir):
os.makedirs(out_dir)

data_dir = os.environ.get('OGS_DATA_DIR')

input_mesh_basename = "cube_1x1x1_hex_1e3"
input_mesh = f"{data_dir}/EllipticPETSc/{input_mesh_basename}.vtu"
num_partitions = 4
```

```python
! partmesh --ogs2metis -i {input_mesh} -o {out_dir}
```

```python
! partmesh --exe_metis -n {num_partitions} -i {input_mesh} -o {out_dir}
```

```python
! cd {out_dir} && mpirun -np {num_partitions} binaryToPVTU -i {input_mesh_basename} -o {input_mesh_basename}
```

Please note that `binaryToPVTU` has to be run with MPI and is therefore available on OGS PETSc configurations only.
See also https://www.opengeosys.org/docs/tools/meshing/reordermesh/#why-is-the-tool-necessary for an explanation of the following.

```python
! cd {out_dir} && pvtu2vtu -i {input_mesh_basename}.pvtu -o {input_mesh_basename}.vtu
! cd {out_dir} && identifySubdomains -m {input_mesh} -o identify_ -- {input_mesh_basename}.vtu
! ReorderMesh -i {out_dir}/identify_{input_mesh_basename}.vtu -o {out_dir}/{input_mesh_basename}_reordered.vtu
! vtkdiff --mesh_check -- {input_mesh} {out_dir}/{input_mesh_basename}_reordered.vtu
assert _exit_code == 0 # last exit code (from vtkdiff call)
```
2 changes: 1 addition & 1 deletion ThirdParty/collection
Submodule collection updated from c0f039 to 5949ed
2 changes: 2 additions & 0 deletions scripts/ci/jobs/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ build docs:
timeout: 30 minutes
variables:
DOX_WARNINGS_THRESHOLD: 18
# Applying PATCH_COMMAND in Docker volume does not work, therefore using local cache:
CPM_SOURCE_CACHE: $CI_PROJECT_DIR/build/_deps
script:
- mkdir -p build
# cpp-dependencies
Expand Down
50 changes: 42 additions & 8 deletions scripts/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,48 @@ CPMAddPackage(
)

if(OGS_BUILD_UTILS)
CPMAddPackage(
NAME metis
GIT_REPOSITORY https://gitlab.opengeosys.org/ogs/libs/metis.git
GIT_TAG d98094f42d0faf9d0e06eb149c870fb714623ecc
VERSION 5.1.0
DOWNLOAD_ONLY YES
)
include(${PROJECT_SOURCE_DIR}/scripts/cmake/MetisSetup.cmake)
if(NOT GUIX_BUILD)
set(_win_metis_options "MSVC FALSE")
if(WIN32)
set(_win_metis_options "MSVC TRUE")
endif()
CPMFindPackage(
NAME GKlib
GIT_REPOSITORY https://github.com/KarypisLab/GKlib
GIT_TAG 8bd6bad750b2b0d90800c632cf18e8ee93ad72d7
VERSION 5.1.1
OPTIONS "CMAKE_POLICY_DEFAULT_CMP0042 NEW" ${_win_metis_options}
EXCLUDE_FROM_ALL YES
)
CPMFindPackage(
NAME metis
GIT_REPOSITORY https://github.com/KarypisLab/METIS
VERSION 5.2.1
EXCLUDE_FROM_ALL YES
PATCH_COMMAND git apply
${PROJECT_SOURCE_DIR}/scripts/cmake/metis.patch
OPTIONS ${_win_metis_options}
)
if(GKlib_ADDED AND metis_ADDED)
target_include_directories(
metis SYSTEM
PUBLIC ${GKlib_SOURCE_DIR} ${metis_SOURCE_DIR}/include
${metis_SOURCE_DIR}/libmetis
)
target_compile_definitions(
metis PUBLIC IDXTYPEWIDTH=64 REALTYPEWIDTH=32
)
list(APPEND DISABLE_WARNINGS_TARGETS metis GKlib)
endif()
else()
find_library(METIS_LIB metis REQUIRED)
find_path(METIS_INC "metis.h" REQUIRED)
find_program(MPMETIS_TOOL mpmetis REQUIRED)
message(STATUS "Metis: ${METIS_LIB} | ${METIS_INC} | ${MPMETIS_TOOL}")
add_library(metis INTERFACE IMPORTED)
target_include_directories(metis SYSTEM INTERFACE ${METIS_INC})
target_link_libraries(metis INTERFACE ${METIS_LIB})
endif()
endif()

# Disable warnings
Expand Down
51 changes: 0 additions & 51 deletions scripts/cmake/MetisSetup.cmake

This file was deleted.

63 changes: 63 additions & 0 deletions scripts/cmake/metis.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a15d19a..7a505dc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,7 +37,7 @@ include(./conf/gkbuild.cmake)

# Add include directories.
# i.e., the -I equivalent
-include_directories(build/xinclude)
+#include_directories(build/xinclude)
include_directories(${GKLIB_PATH}/include)
include_directories(${CMAKE_INSTALL_PREFIX}/include)

@@ -47,6 +47,6 @@ link_directories(${GKLIB_PATH}/lib)
link_directories(${CMAKE_INSTALL_PREFIX}/lib)

# Recursively look for CMakeLists.txt in subdirs.
-add_subdirectory("build/xinclude")
+#add_subdirectory("build/xinclude")
add_subdirectory("libmetis")
add_subdirectory("programs")
diff --git a/conf/gkbuild.cmake b/conf/gkbuild.cmake
index 0e70a8e..3ce5ae7 100644
--- a/conf/gkbuild.cmake
+++ b/conf/gkbuild.cmake
@@ -126,7 +126,7 @@ if(MSVC)
if("${HAVE_THREADLOCALSTORAGE}" MATCHES "^${HAVE_THREADLOCALSTORAGE}$")
try_compile(HAVE_THREADLOCALSTORAGE
${CMAKE_BINARY_DIR}
- ${CMAKE_SOURCE_DIR}/conf/check_thread_storage.c)
+ ${PROJECT_SOURCE_DIR}/conf/check_thread_storage.c)
if(HAVE_THREADLOCALSTORAGE)
message(STATUS "checking for thread-local storage - found")
else()
diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt
index baf40ad..67e93a2 100644
--- a/programs/CMakeLists.txt
+++ b/programs/CMakeLists.txt
@@ -11,7 +11,10 @@ add_executable(cmpfillin cmpfillin.c io.c smbfactor.c)

# Link with the required libraries
foreach(prog gpmetis ndmetis mpmetis m2gmetis graphchk cmpfillin)
- target_link_libraries(${prog} metis GKlib m)
+ target_link_libraries(${prog} metis GKlib)
+ if(NOT WIN32)
+ target_link_libraries(${prog} m)
+ endif()
endforeach(prog)

if(METIS_INSTALL)
diff --git a/programs/mpmetis.c b/programs/mpmetis.c
index 04a6a1b..af74de9 100644
--- a/programs/mpmetis.c
+++ b/programs/mpmetis.c
@@ -188,7 +188,7 @@ void MPReportResults(params_t *params, mesh_t *mesh, idx_t *epart, idx_t *npart,
printf("\nMemory Information ----------------------------------------------------------\n");
printf(" Max memory used:\t\t %7.3"PRREAL" MB\n", (real_t)(params->maxmemory/(1024.0*1024.0)));

-#ifndef MACOS
+#if !defined(MACOS) && !defined(WIN32) && !defined(__MINGW32__)
{
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
4 changes: 2 additions & 2 deletions web/data/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
}
},
"cpm": {
"package_file_id": 865,
"package_file_sha256": "00db04d08660e131c41fcc20b9cc4046516223c668b0d422e3002775e4d4e967"
"package_file_id": 1028,
"package_file_sha256": "815ef4ca37e05232526afe50e3eafe8a1d6366bce3ae3d509fac1214ab6b5f98"
},
"ext": {
"cache_hash": "4ebd62e0ce484732dbf3cd9932f60b67762e156b"
Expand Down

0 comments on commit a5b428f

Please sign in to comment.