Skip to content
Snippets Groups Projects
Commit 8cd08950 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Various test with rang and CLI11 packages

parent 953d8c9c
No related branches found
No related tags found
No related merge requests found
...@@ -12,8 +12,10 @@ include(CheckNotInSources) ...@@ -12,8 +12,10 @@ include(CheckNotInSources)
project (Pastis) project (Pastis)
# Rang (colors? Useless thus necessary!)
include_directories(${CMAKE_SOURCE_DIR}/packages/rang/include)
# CLI11 # CLI11
add_subdirectory(${CMAKE_SOURCE_DIR}/packages/CLI11)
include_directories(${CMAKE_SOURCE_DIR}/packages/CLI11/include) include_directories(${CMAKE_SOURCE_DIR}/packages/CLI11/include)
# Kokkos # Kokkos
......
#include <iostream> #include <iostream>
#include <Kokkos_Core.hpp> #include <Kokkos_Core.hpp>
#include <RevisionInfo.hpp> #include <RevisionInfo.hpp>
#include <rang.hpp>
#include <CLI/CLI.hpp> #include <CLI/CLI.hpp>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
std::cout << "It's pastis time!\n"; CLI::App app{"Pastis help"};
long number = 1000;
app.add_option("-n,--number", number, "A big integer");
CLI11_PARSE(app, argc, argv);
std::cout << "--------------------- git info --------------------------\n"; std::cout << "--------------------- git info --------------------------\n";
std::cout << "* version: " << RevisionInfo::version() << '\n'; std::cout << "* version: " << rang::style::bold << RevisionInfo::version() << rang::style::reset << '\n';
std::cout << "* head: " << RevisionInfo::head() << '\n'; std::cout << "* HEAD: " << rang::style::underline << RevisionInfo::head() << rang::style::reset << '\n';
std::cout << "* hash: " << RevisionInfo::hash() << " (" << RevisionInfo::isClean() << ")\n"; std::cout << "* hash: " << RevisionInfo::hash() << " (";
if (RevisionInfo::isClean()) {
std::cout << rang::fgB::green << "clean" << rang::fg::reset;
} else {
std::cout << rang::fgB::red << "dirty" << rang::fg::reset;
}
std::cout << ")\n";
std::cout << "---------------------------------------------------------\n"; std::cout << "---------------------------------------------------------\n";
Kokkos::initialize(argc, argv); Kokkos::initialize(argc, argv);
Kokkos::DefaultExecutionSpace::print_configuration(std::cout); Kokkos::DefaultExecutionSpace::print_configuration(std::cout);
if (argc < 2) { // if (argc < 2) {
fprintf(stderr, "Usage: %s [<kokkos_options>] <size>\n", argv[0]); // fprintf(stderr, "Usage: %s [<kokkos_options>] <size>\n", argv[0]);
Kokkos::finalize(); // Kokkos::finalize();
exit(1); // exit(1);
} // }
const long n = strtol(argv[1], NULL, 10); const long& n = number;
std::cout << "Number of even integers from 0 to " << n - 1 << '\n'; std::cout << "Number of even integers from 0 to " << n - 1 << '\n';
Kokkos::Timer timer; Kokkos::Timer timer;
...@@ -31,12 +43,12 @@ int main(int argc, char *argv[]) ...@@ -31,12 +43,12 @@ int main(int argc, char *argv[])
// Compute the number of even integers from 0 to n-1, in parallel. // Compute the number of even integers from 0 to n-1, in parallel.
long count = 0; long count = 0;
Kokkos::parallel_reduce(n, KOKKOS_LAMBDA (const long i, long& lcount) { Kokkos::parallel_reduce(n, [=] (const long i, long& lcount) {
lcount += (i % 2) == 0; lcount += (i % 2) == 0;
}, count); }, count);
double count_time = timer.seconds(); double count_time = timer.seconds();
std::cout << " Parallel: " << count << " " << count_time << '\n'; std::cout << " Parallel: " << count << " " << rang::style::bold << count_time << rang::style::reset << '\n';
timer.reset(); timer.reset();
...@@ -46,9 +58,8 @@ int main(int argc, char *argv[]) ...@@ -46,9 +58,8 @@ int main(int argc, char *argv[])
seq_count += (i % 2) == 0; seq_count += (i % 2) == 0;
} }
int k =3;
count_time = timer.seconds(); count_time = timer.seconds();
std::cout << "Sequential: " << seq_count << ' ' << count_time << '\n'; std::cout << "Sequential: " << seq_count << ' ' << rang::style::bold << count_time << rang::style::reset << '\n';
Kokkos::finalize(); Kokkos::finalize();
return (count == seq_count) ? 0 : -1; return (count == seq_count) ? 0 : -1;
......
...@@ -4,9 +4,11 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) ...@@ -4,9 +4,11 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/cmake-modules") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/cmake-modules")
include(GetGitRevisionDescription) include(GetGitRevisionDescription)
git_describe(PASTISVERSION "--abbrev=0") git_describe(PASTIS_VERSION "--abbrev=0")
get_git_head_revision(PASTISHEAD PASTISHASH) get_git_head_revision(PASTIS_HEAD PASTIS_HASH)
git_local_changes(PASTISHASLOCALCHANGES) git_local_changes(PASTIS_HAS_LOCAL_CHANGES)
set(PASTIS_IS_CLEAN ${PASTIS_HAS_LOCAL_CHANGES} STREQ "CLEAN")
add_custom_target(git_revision ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/pastis_git_revision.hpp) add_custom_target(git_revision ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/pastis_git_revision.hpp)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/pastis_git_revision.hpp PROPERTIES GENERATED TRUE HEADER_FILE_ONLY TRUE) set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/pastis_git_revision.hpp PROPERTIES GENERATED TRUE HEADER_FILE_ONLY TRUE)
......
...@@ -3,20 +3,24 @@ ...@@ -3,20 +3,24 @@
std::string RevisionInfo::version() std::string RevisionInfo::version()
{ {
return PASTISVERSION; return PASTIS_VERSION;
} }
std::string RevisionInfo::head() std::string RevisionInfo::head()
{ {
return PASTISHEAD; return PASTIS_HEAD;
} }
std::string RevisionInfo::hash() std::string RevisionInfo::hash()
{ {
return PASTISHASH; return PASTIS_HASH;
} }
std::string RevisionInfo::isClean() bool RevisionInfo::isClean()
{ {
return PASTISHASLOCALCHANGES; #if PASTIS_IS_CLEAN
return true;
#else
return false;
#endif
} }
...@@ -8,7 +8,7 @@ struct RevisionInfo ...@@ -8,7 +8,7 @@ struct RevisionInfo
static std::string version(); static std::string version();
static std::string head(); static std::string head();
static std::string hash(); static std::string hash();
static std::string isClean(); static bool isClean();
}; };
#endif // REVISION_INFO_HPP #endif // REVISION_INFO_HPP
#ifndef GIT_REVISION_HPP #ifndef GIT_REVISION_HPP
#define GIT_REVISION_HPP #define GIT_REVISION_HPP
#define PASTISVERSION "@PASTISVERSION@" #define PASTIS_VERSION "@PASTIS_VERSION@"
#define PASTISHEAD "@PASTISHEAD@" #define PASTIS_HEAD "@PASTIS_HEAD@"
#define PASTISHASH "@PASTISHASH@" #define PASTIS_HASH "@PASTIS_HASH@"
#define PASTISHASLOCALCHANGES "@PASTISHASLOCALCHANGES@" #define PASTIS_HAS_LOCAL_CHANGES "@PASTIS_HAS_LOCAL_CHANGES@"
#endif // GIT_REVISION_HPP #endif // GIT_REVISION_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment