PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
testPeriDEM.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
11#include <PeriDEMConfig.h>
12#include "testPeriDEMLib.h"
13#include "util/io.h"
14#include "util/parallelUtil.h" // MPI-related functions
15#include <fmt/format.h>
16#include <iostream>
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("-i")) {
29 // print help
30 std::cout << argv[0] << " (Version " << MAJOR_VERSION << "."
31 << MINOR_VERSION << "." << UPDATE_VERSION
32 << ") -i <data-filepath> -nThreads <number of threads to be used in taskflow>" << std::endl;
33 exit(EXIT_FAILURE);
34 }
35
36 // read input file
37 std::string filepath = input.getCmdOption("-i");
38
39 unsigned int nThreads;
40 if (input.cmdOptionExists("-nThreads")) nThreads = std::stoi(input.getCmdOption("-nThreads"));
41 else {
42 nThreads = std::thread::hardware_concurrency();
43 util::io::print(fmt::format("Running test with default number of threads = {}\n", nThreads));
44 }
45 // set number of threads
47 util::io::print(fmt::format("Number of threads = {}\n", util::parallel::getNThreads()));
48
49 // run test
50 auto msg = test::testPeriDEM(filepath);
51
52 if (msg == "pass")
53 std::cout << "testPeriDEM: Pass\n";
54 else {
55 std::cerr << "Error: " << msg << "\n";
56 return EXIT_FAILURE;
57 }
58
59 return EXIT_SUCCESS;
60}
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
std::string testPeriDEM(std::string filepath)
Tests PeriDEM model class.
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
Definition io.h:108
unsigned int getNThreads()
Get number of threads to be used by taskflow.
void initNThreads(unsigned int nThreads=std::thread::hardware_concurrency())
Initializes MpiStatus struct.
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()