|
- /*!
- * \file main.cpp
- * \brief Main application file
- *
- * \author
- * Christos Choutouridis AEM:8997
- * <cchoutou@ece.auth.gr>
- */
-
- #include <iostream>
- #include <string>
- #include <exception>
-
- #include <utils.h>
- #include <config.h>
-
- // Global session data
- session_t session;
-
- /*!
- * A small command line argument parser
- * \return The status of the operation
- */
- bool get_options(int argc, char* argv[]){
- bool status =true;
-
- // iterate over the passed arguments
- for (int i=1 ; i<argc ; ++i) {
- std::string arg(argv[i]); // get current argument
-
- if (arg == "-i" || arg == "--input") {
- session.inputMatrix = InputMatrix::MTX;
- if (i+1 < argc)
- session.mtxFile = std::ifstream(argv[++i]);
- else
- status = false;
- }
- else if (arg == "-g" || arg == "--generate")
- session.inputMatrix = InputMatrix::GENERATE;
- else if (arg == "-s" || arg == "--size")
- session.size = (i+1 < argc) ? std::atoi(argv[++i]) : session.size;
- else if (arg == "-p" || arg == "--probability")
- session.probability = (i+1 < argc) ? std::atof(argv[++i]) : session.probability;
- else if (arg == "--print") {
- session.print = true;
- session.print_size = (i+1 < argc) ? std::atoi(argv[++i]) : session.print_size;
- }
- else if (arg == "--make_symmetric")
- session.makeSymmetric = true;
- else if (arg == "-t" || arg == "--timing")
- session.timing = true;
- else if (arg == "-h" || arg == "--help") {
- std::cout << "Help message\n";
- exit(0);
- }
- else {
- std::cout << "Error message\n";
- status = false;
- }
- }
- return status;
- }
-
-
- int main(int argc, char* argv[]) try {
- Timing timer;
- matrix A;
-
- // try to read command line
- if (!get_options(argc, argv))
- exit(1);
-
- // get or generate matrix
- if (session.inputMatrix == InputMatrix::GENERATE) {
- std::cout << "Initialize matrix with size: " << session.size << " and probability: " << session.probability << '\n';
- timer.start();
- A.size(session.size);
- init_ER_graph(A, session.probability);
- timer.stop();
- if (session.timing) timer.print_dt();
- }
- else {
- std::cout << "Read matrix from file\n";
- timer.start();
- if (session.makeSymmetric && !Mtx::is_triangular<matrix::indexType> (session.mtxFile))
- throw std::runtime_error("Error: Matrix is not strictly upper or lower");
- if (!Mtx::load (A, session.mtxFile)) {
- throw std::runtime_error("Error: fail to load matrix");
- }
- timer.stop();
- std::cout << "Matrix size: " << A.size() << " and capacity: " << A.capacity() <<'\n';
- if (session.timing) timer.print_dt();
- }
-
- if (session.print) {
- std::cout << "Array A:\n";
- print_ER_graph (A);
- }
-
- std::cout << "count triangles\n";
- timer.start();
- std::cout << "There are " << triang_count(A) << " triangles\n";
- timer.stop();
- if (session.timing) timer.print_dt();
-
- return 0;
- }
- catch (std::exception& e) {
- //we probably pollute the user's screen. Comment `cerr << ...` if you don't like it.
- std::cerr << e.what() << '\n';
- exit(1);
- }
|