From be7190d9973b32f36652800f8eaa4581340f6464 Mon Sep 17 00:00:00 2001 From: Ethan Coon Date: Mon, 4 Jan 2021 23:19:23 -0500 Subject: [PATCH 1/3] adds option to partition from an existing binary coloring file --- CMakeLists.txt | 2 +- cmake/modules/FindExodusII.cmake | 1 + include/MSTK_private.h | 1 + src/par/MESH_Get_Partitioning.c | 8 +++++ src/par/MESH_PartitionWithColoringFile.c | 44 ++++++++++++++++++++++++ utils/meshconvert/src/meshconvert.c | 3 +- 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/par/MESH_PartitionWithColoringFile.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 726e3834..e8de2973 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,7 @@ endif (NOT INSTALL_DIR) set (MSTKLIB mstk) -# shared libraries tweaks; enforcing absolute path +# shared libraries tweaks: enforcing absolute path if (BUILD_SHARED_LIBS) set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_SKIP_INSTALL_RPATH FALSE) diff --git a/cmake/modules/FindExodusII.cmake b/cmake/modules/FindExodusII.cmake index 2d5bdb80..9aff764f 100644 --- a/cmake/modules/FindExodusII.cmake +++ b/cmake/modules/FindExodusII.cmake @@ -130,6 +130,7 @@ if (ExodusII_FOUND AND NOT TARGET ExodusII::ExodusII) # Add netCDF as a dependency of ExodusII target_link_libraries(${ExodusII_LIBRARIES} INTERFACE ${netCDF_LIBRARIES}) + message(DEBUG "Including netcdf: ${netCDF_LIBRARIES}") endif() diff --git a/include/MSTK_private.h b/include/MSTK_private.h index 4cc3b9cd..dc4316a2 100644 --- a/include/MSTK_private.h +++ b/include/MSTK_private.h @@ -332,6 +332,7 @@ typedef enum MDelType {MDELREGION=-40, MDELFACE=-30, MDELEDGE=-20, MDELVERTEX=-1 int MESH_PartitionWithZoltan(Mesh_ptr mesh, int nparts, int **part, int noptions, char **options, MSTK_Comm comm); + int MESH_PartitionWithColoringFile(Mesh_ptr mesh, int nparts, int **part); int FixColumnPartitions(Mesh_ptr mesh, int *part, MSTK_Comm comm); int FixColumnPartitions_IsSide(Mesh_ptr mesh, MRegion_ptr mr, MFace_ptr rf); int FixColumnPartitions_UpDown(Mesh_ptr mesh, MRegion_ptr mr, MFace_ptr* up, MFace_ptr* dn); diff --git a/src/par/MESH_Get_Partitioning.c b/src/par/MESH_Get_Partitioning.c index 446c904e..68b9a2fc 100644 --- a/src/par/MESH_Get_Partitioning.c +++ b/src/par/MESH_Get_Partitioning.c @@ -112,6 +112,14 @@ int MESH_Get_Partitioning(Mesh_ptr mesh, int method, int **part, MSTK_Comm comm) break; } + case 3: { + /* This reads a coloring file */ + if (rank == 0) { + ok = MESH_PartitionWithColoringFile(mesh, num, part); + } + + break; + } default: MSTK_Report("MESH_Get_Partition","Unknown partitioning method",MSTK_FATAL); } diff --git a/src/par/MESH_PartitionWithColoringFile.c b/src/par/MESH_PartitionWithColoringFile.c new file mode 100644 index 00000000..c93d7456 --- /dev/null +++ b/src/par/MESH_PartitionWithColoringFile.c @@ -0,0 +1,44 @@ +/* +Copyright 2019 Triad National Security, LLC. All rights reserved. + +This file is part of the MSTK project. Please see the license file at +the root of this repository or at +https://github.com/MeshToolkit/MSTK/blob/master/LICENSE +*/ + +#include +#include + +#include "MSTK.h" + +/* Get the partitioning of mesh by reading a coloring file - + Doesn't actually do anything to the mesh */ + +#ifdef __cplusplus +extern "C" { +#endif + + +int MESH_PartitionWithColoringFile(Mesh_ptr mesh, int nparts, int **part) { + int ncells; + FILE* fid; + size_t count; + + ncells = MESH_Num_Regions(mesh); + *part = (int *) malloc(ncells*sizeof(int)); + + fid = fopen("coloring.bin", "rb"); + if (fid == NULL) { + fprintf(stderr,"Nonexistent coloring file \"coloring.bin\"\n"); + exit(-1); + } + + count = fread(*part, sizeof(int), (size_t) ncells, fid); + fprintf(stderr,"read %zu of %i region colors from coloring.bin\n", count, ncells); + if (count != (size_t) ncells) { + fprintf(stderr,"Error reading coloring file \"coloring.bin\"\n"); + exit(-1); + } + fclose(fid); + return 1; +} diff --git a/utils/meshconvert/src/meshconvert.c b/utils/meshconvert/src/meshconvert.c index acf78c52..bd639a62 100644 --- a/utils/meshconvert/src/meshconvert.c +++ b/utils/meshconvert/src/meshconvert.c @@ -57,10 +57,11 @@ int main(int argc, char *argv[]) { if (argc < 3) { fprintf(stderr,"\n"); - fprintf(stderr,"usage: meshconvert <--classify=0|n|1|y|2> <--partition=y|1|n|0> <--partition-method=0|1|2> <--parallel-check=y|1|n|0> <--weave=y|1|n|0> <--num-ghost-layers=?> <--check-topo=y|1|n|0> infilename outfilename\n\n"); + fprintf(stderr,"usage: meshconvert <--classify=0|n|1|y|2> <--partition=y|1|n|0> <--partition-method=0|1|2|3> <--parallel-check=y|1|n|0> <--weave=y|1|n|0> <--num-ghost-layers=?> <--check-topo=y|1|n|0> infilename outfilename\n\n"); fprintf(stderr,"partition-method = 0, METIS\n"); fprintf(stderr," = 1, ZOLTAN with GRAPH partioning\n"); fprintf(stderr," = 2, ZOLTAN with RCB partitioning\n"); + fprintf(stderr," = 3, read partitioning from coloring.txt file\n"); fprintf(stderr,"Choose 2 if you want to avoid partitioning models\n"); fprintf(stderr,"with high aspect ratio along the short directions\n"); fprintf(stderr,"\n"); From 8574acb16cb2b56a755c2ca87a43a72c16291c02 Mon Sep 17 00:00:00 2001 From: Ethan Coon Date: Mon, 4 Jan 2021 23:31:54 -0500 Subject: [PATCH 2/3] cleans up debugging netcdf cruft and adds missing cplusplus protection --- CMakeLists.txt | 2 +- cmake/modules/FindExodusII.cmake | 1 - src/par/MESH_PartitionWithColoringFile.c | 4 ++++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8de2973..726e3834 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,7 @@ endif (NOT INSTALL_DIR) set (MSTKLIB mstk) -# shared libraries tweaks: enforcing absolute path +# shared libraries tweaks; enforcing absolute path if (BUILD_SHARED_LIBS) set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_SKIP_INSTALL_RPATH FALSE) diff --git a/cmake/modules/FindExodusII.cmake b/cmake/modules/FindExodusII.cmake index 9aff764f..2d5bdb80 100644 --- a/cmake/modules/FindExodusII.cmake +++ b/cmake/modules/FindExodusII.cmake @@ -130,7 +130,6 @@ if (ExodusII_FOUND AND NOT TARGET ExodusII::ExodusII) # Add netCDF as a dependency of ExodusII target_link_libraries(${ExodusII_LIBRARIES} INTERFACE ${netCDF_LIBRARIES}) - message(DEBUG "Including netcdf: ${netCDF_LIBRARIES}") endif() diff --git a/src/par/MESH_PartitionWithColoringFile.c b/src/par/MESH_PartitionWithColoringFile.c index c93d7456..7bd95743 100644 --- a/src/par/MESH_PartitionWithColoringFile.c +++ b/src/par/MESH_PartitionWithColoringFile.c @@ -42,3 +42,7 @@ int MESH_PartitionWithColoringFile(Mesh_ptr mesh, int nparts, int **part) { fclose(fid); return 1; } + +#ifdef __cplusplus + } +#endif From 20dd3f9e1387b948b886bdccc230bc5eb0e162ee Mon Sep 17 00:00:00 2001 From: Ethan Coon Date: Mon, 4 Jan 2021 23:32:55 -0500 Subject: [PATCH 3/3] typo -- using bin extension for binary file --- utils/meshconvert/src/meshconvert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/meshconvert/src/meshconvert.c b/utils/meshconvert/src/meshconvert.c index bd639a62..91ad4565 100644 --- a/utils/meshconvert/src/meshconvert.c +++ b/utils/meshconvert/src/meshconvert.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) { fprintf(stderr,"partition-method = 0, METIS\n"); fprintf(stderr," = 1, ZOLTAN with GRAPH partioning\n"); fprintf(stderr," = 2, ZOLTAN with RCB partitioning\n"); - fprintf(stderr," = 3, read partitioning from coloring.txt file\n"); + fprintf(stderr," = 3, read partitioning from coloring.bin file\n"); fprintf(stderr,"Choose 2 if you want to avoid partitioning models\n"); fprintf(stderr,"with high aspect ratio along the short directions\n"); fprintf(stderr,"\n");