/*! * \file main.cpp * \brief Main application file * * \author * Christos Choutouridis AEM:8997 * */ #include #include #include #include #include // Global session data session_t session; Log logger; /*! * 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 | -g [-o ] [-n ] [--dynamic] [-r ] [-t] [-v]\n"; std::cout << " [--make_symmetric] [--triangular_only] [--print_count] [--validate_mtx] [--print_graph ]\n"; std::cout << '\n'; std::cout << "Options:\n\n"; std::cout << " -i | --input \n"; std::cout << " Path to mtx file to load.\n\n"; std::cout << " -g | --generate \n"; std::cout << " Request a random generated graph with size and probability .\n"; std::cout << " This is very slow, use it with care.\n\n"; std::cout << " -o | --output \n"; std::cout << " Select as output file. Default is stdout.\n\n"; std::cout << " -n | --max_trheads \n"; std::cout << " Reduce the thread number for the execution to . must be less or equal to available CPUs.\n\n"; std::cout << " --dynamic\n"; std::cout << " Request of dynamic scheduling for OpenMP and pthreads. Does not affect cilk versions.\n\n"; std::cout << " -r | --repeat \n"; std::cout << " Repeat the vector calculation times.\n\n"; std::cout << " -t | --timing\n"; std::cout << " Request timing measurements output to stdout.\n\n"; std::cout << " -v | --verbose\n"; std::cout << " Request a more verbose output to stdout.\n\n"; std::cout << " --make_symmetric\n"; std::cout << " Explicitly request a symmetric graph generation. This affects only V3 versions where by default a lower\n"; std::cout << " triangular matrix is used.\n\n"; std::cout << " --triangular_only\n"; std::cout << " NOTE: Requires also \"--print_count\".\n"; std::cout << " Explicitly request to use a lower triangular matrix. This affects only V4 versions where a symmetric\n"; std::cout << " matrix is used by default and produce correct answer ONLY for total triangle counting (--print_count).\n\n"; std::cout << " --print_count\n"; std::cout << " NOTE: When used, also implies \"---triangular_only\" for all versions.\n"; std::cout << " Request a total triangle counting output.\n\n"; std::cout << " --validate_mtx\n"; std::cout << " Request an input matrix validation before execution.\n\n"; std::cout << " --print_graph \n"; std::cout << " Prints the first x part of the matrix to stdout.\n\n"; std::cout << " -h | --help \n"; std::cout << " Prints this and exit.\n"; exit(0); } else { // parse error std::cout << "Invokation error. Try -h for details.\n"; status = false; } } // Input checkers if (session.inputMatrix == InputMatrix::UNSPECIFIED) { std::cout << "Error message\n"; status = false; } #if CODE_VERSION == V4 else if (!session.makeSymmetric && !session.print_count) { std::cout << "\"--triangular_only\" requires \"--print_count\"\n"; status = false; } #endif return status; } /*! * get or generate matrix * \param A Reference to matrix for output (move using RVO) * \param timer Reference to timer utility to access time printing functionality */ void prepare_matrix (matrix& A, Timing& timer) { if (session.inputMatrix == InputMatrix::GENERATE) { logger << "Initialize matrix with size: " << session.gen_size << " and probability: " << session.gen_prob << logger.endl; timer.start(); A.size(session.gen_size); init_ER_graph(A, session.gen_prob); timer.stop(); timer.print_dt("generate matrix"); } else { logger << "Read matrix from file" << logger.endl; timer.start(); if (session.validate_mtx && !Mtx::is_triangular (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(); logger << "Matrix size: " << A.size() << " and capacity: " << A.capacity() << logger.endl; timer.print_dt("load matrix"); } if (session.verbose && session.mtx_print) { logger << "\nMatrix:" << logger.endl; print_graph (A); } } /* * main program */ int main(int argc, char* argv[]) try { Timing timer; matrix A; std::vector c; index_t s; #if defined ELEARNING if (!elearn_test()) std::cout << "E-learning test: FAIL\n"; else std::cout << "E-learning test: PASS\n"; exit(0); #endif // try to read command line if (!get_options(argc, argv)) exit(1); prepare_matrix(A, timer); threads_info(); for (size_t i =0 ; i