PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
testMeshPartitioning.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2024 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
12#include <PeriDEMConfig.h>
13#include <iostream>
14#include "util/io.h" // InputParser class
15#include "util/parallelUtil.h" // MPI-related functions
16#include <fmt/format.h>
17
18int main(int argc, char *argv[]) {
19
20 // init parallel
21 util::parallel::initMpi(argc, argv);
22 int mpiSize = util::parallel::mpiSize(), mpiRank = util::parallel::mpiRank();
23 util::io::print(fmt::format("Initialized MPI. MPI size = {}, MPI rank = {}\n", mpiSize, mpiRank));
25
26 util::io::InputParser input(argc, argv);
27
28 if (input.cmdOptionExists("-h") or !input.cmdOptionExists("-o")) {
29 // print help
30 std::cout << argv[0] << " (Version " << MAJOR_VERSION << "."
31 << MINOR_VERSION << "." << UPDATE_VERSION
32 << ") -o <0 to perform basic test, 1 on uniform mesh and 2 to test on user mesh> -n <grid-size> -p <number-partitions> -m <horizon-integer-factor> -f <mesh-filename>" << std::endl;
33 std::cout << "To perform basic test" << std::endl;
34 std::cout << argv[0] << " -o 0" << std::endl;
35 std::cout << "To test on uniform mesh" << std::endl;
36 std::cout << argv[0] << " -o 1 -p 4 -m 4 -n 10 " << std::endl;
37 std::cout << "To test on user-provided mesh (filename = filepath/meshfile.vtu)" << std::endl;
38 std::cout << argv[0] << " -o 2 -p 4 -m 4 -f filepath/meshfile.vtu" << std::endl;
39 exit(EXIT_FAILURE);
40 }
41
42 // read input
43 size_t testOption, nGrid(0), nPart, mHorizon;
44 std::string meshFilename("");
45
46 if (input.cmdOptionExists("-o")) testOption = size_t(std::stoi(input.getCmdOption("-o")));
47 else {
48 std::cerr << "Test requires following arguments -o <option integer> -n <grid-size> -p <number-partition> -m <horizon-integer-factor> -f <mesh-filename>\n";
49 exit(1);
50 }
51
52 if (testOption == 0) {
53 std::cout << "testMeshPartitioning: Simple test of metis graph partitioning\n\n";
55 } else if (testOption == 1 or testOption == 2) {
56
57 if (input.cmdOptionExists("-n"))
58 nGrid = size_t(std::stoi(input.getCmdOption("-n")));
59 else {
60 // set only if we are running test using in-built mesh
61 if (testOption == 1) {
62 nGrid = 50;
63 std::cout << "Running test with default grid size = "
64 << nGrid << std::endl;
65 }
66 }
67
68 if (input.cmdOptionExists("-p"))
69 nPart = size_t(std::stoi(input.getCmdOption("-p")));
70 else {
71 nPart = 4;
72 std::cout << "Running test with default number of partitions = "
73 << nPart << std::endl;
74
75 }
76
77 if (input.cmdOptionExists("-m"))
78 mHorizon = size_t(std::stoi(input.getCmdOption("-m")));
79 else {
80 mHorizon = 4;
81 std::cout << "Running test with default integer factor for horizon = "
82 << mHorizon << std::endl;
83 }
84
85 if (input.cmdOptionExists("-f")) meshFilename = input.getCmdOption("-f");
86
87 // check if nGrid and meshFilename are compatible
88 if ((nGrid > 0 and testOption == 2) or
89 (!meshFilename.empty() and testOption == 1)) {
90 std::cerr
91 << "Please specify either using uniform mesh (in-built) or user-defined mesh "
92 "to perform the partitioning test. "
93 "That is, either specify '-o 1 -n <grid-size>' "
94 "or '-o 2 -f <mesh-filename>'.\n";
95 exit(1);
96 }
97
98 // test partitioning
99 std::cout
100 << "\n\ntestMeshPartitioning: Test of metis graph partitioning on 2-D mesh with nonlocal interaction\n\n";
101 test::testGraphPartitioning(nPart, nGrid, mHorizon, testOption,
102 meshFilename);
103 } else {
104 std::cout << "Invalid option -o argument.\n";
105 }
106
107 return EXIT_SUCCESS;
108}
size_t const MINOR_VERSION
size_t const UPDATE_VERSION
size_t const MAJOR_VERSION
Input command line argument parser.
Definition io.h:355
bool cmdOptionExists(const std::string &option) const
Check if argument exists.
Definition io.h:387
const std::string & getCmdOption(const std::string &option) const
Get value of argument specified by key.
Definition io.h:372
void testGraphPartitioningSimple()
Tests metis partitioning of graph.
void testGraphPartitioning(size_t nPart=4, size_t nGrid=10, size_t mHorizon=3, size_t testOption=0, std::string meshFilename="")
Tests metis partitioning of graph from a 2-D mesh with nonlocal interaction.
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
Definition io.h:108
const MpiStatus * getMpiStatus()
Returns pointer to MpiStatus struct.
void initMpi(int argc=0, char *argv[]=nullptr)
Initializes MPI and also creates MpiStatus struct.
int mpiSize()
Get size (number) of processors.
int mpiRank()
get rank (id) of this processor
int main()