29 {
30
31
34 util::io::print(std::format(
"Initialized MPI. MPI size = {}, MPI rank = {}\n", mpiSize, mpiRank));
36
38
39 if (input.cmdOptionExists("-h") or !input.cmdOptionExists("-i")) {
40
41 std::cout << "Syntax to run PeriDEM: PeriDEM -i <input file> -nThreads <number of threads>" << std::endl;
42 std::cout << "Example: PeriDEM -i input.json -nThreads 4" << std::endl;
43 exit(EXIT_FAILURE);
44 }
45
46 unsigned int nThreads;
47 if (input.cmdOptionExists("-nThreads")) nThreads = std::stoi(input.getCmdOption("-nThreads"));
48 else {
49 nThreads = std::thread::hardware_concurrency();
50 util::io::print(std::format(
"Running test with default number of threads = {}\n", nThreads));
51 }
52
55
56
57 std::cout << "PeriDEM"
58 << " (Version " << MAJOR_VERSION << "." << MINOR_VERSION << "."
59 << UPDATE_VERSION << ")" << std::endl;
60
61
62 auto begin = steady_clock::now();
63
64
65
66 try {
67 std::string filename = input.getCmdOption("-i");
68 if (!std::filesystem::exists(filename)) {
69 throw std::runtime_error(
70 std::format("Input file {} does not exist.", filename));
71 }
72 std::ifstream f(filename);
73 auto j = json::parse(f);
74 auto deck = std::make_shared<inp::Input>(j);
75
76 if (deck->isPeriDEM()) {
78 dem.run(deck);
79 } else {
80 std::cout << "PeriDEM model not found in input file.\n";
81 }
82 } catch (const std::exception &e) {
83 std::cerr << "PeriDEM error: " << e.what() << std::endl;
85 return EXIT_FAILURE;
86 }
87
88
89 auto end = steady_clock::now();
90
91 std::cout << "Total simulation time (s) = "
93 << std::endl;
94
96 return 0;
97}
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
float timeDiff(std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, std::string unit="microseconds")
Returns difference between two times.
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
void finalizeMpi()
Call MPI_Finalize if this process initialized MPI.