28 {
29
30
33 util::io::print(std::format(
"Initialized MPI. MPI size = {}, MPI rank = {}\n", mpiSize, mpiRank));
35
37
38 if (input.cmdOptionExists("-h") or !input.cmdOptionExists("-i")) {
39
40 std::cout << "Syntax to run PeriDEM: PeriDEM -i <input file> -nThreads <number of threads>" << std::endl;
41 std::cout << "Example: PeriDEM -i input.json -nThreads 4" << std::endl;
42 exit(EXIT_FAILURE);
43 }
44
45 unsigned int nThreads;
46 if (input.cmdOptionExists("-nThreads")) nThreads = std::stoi(input.getCmdOption("-nThreads"));
47 else {
48 nThreads = std::thread::hardware_concurrency();
49 util::io::print(std::format(
"Running test with default number of threads = {}\n", nThreads));
50 }
51
54
55
56 std::cout << "PeriDEM"
57 << " (Version " << MAJOR_VERSION << "." << MINOR_VERSION << "."
58 << UPDATE_VERSION << ")" << std::endl;
59
60
61 auto begin = steady_clock::now();
62
63
64 std::string filename = input.getCmdOption("-i");
65 if (!std::filesystem::exists(filename)) {
66 throw std::runtime_error(std::format("Input file {} does not exist.", filename));
67 }
68 std::ifstream f(filename);
69 auto j = json::parse(f);
70 auto deck = std::make_shared<inp::Input>(j);
71
72
73 if (deck->isPeriDEM()) {
75 dem.run(deck);
76 } else {
77 std::cout << "PeriDEM model not found in input file.\n";
78 }
79
80
81 auto end = steady_clock::now();
82
83 std::cout << "Total simulation time (s) = "
85 << std::endl;
86
88 return 0;
89}
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.