Skip to content

Commit

Permalink
Adding a couple utility api functions
Browse files Browse the repository at this point in the history
Signed-off-by: Alex McCaskey <mccaskeyaj@ornl.gov>
  • Loading branch information
Alex McCaskey committed Jan 22, 2018
1 parent 2ecb4a1 commit 429fd55
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
53 changes: 30 additions & 23 deletions xacc/XACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,44 @@ void Initialize() {
Initialize(std::vector<std::string>{});
}

bool isInitialized() {
return xaccFrameworkInitialized;
}

void Initialize(int arc, char** arv) {

argc = arc;
argv = arv;
if (!xaccFrameworkInitialized) {
argc = arc;
argv = arv;

// Create the iniitial xacc-console
std::shared_ptr<spdlog::logger> tmpInitConsole;
if (!spdlog::get("xacc-console")) {
tmpInitConsole = spdlog::stdout_logger_mt("xacc-console");
} else {
tmpInitConsole = spdlog::get("xacc-console");
}
// Create the iniitial xacc-console
std::shared_ptr<spdlog::logger> tmpInitConsole;
if (!spdlog::get("xacc-console")) {
tmpInitConsole = spdlog::stdout_logger_mt("xacc-console");
} else {
tmpInitConsole = spdlog::get("xacc-console");
}

XACCInfo("[xacc] Initializing XACC Framework.");

XACCInfo("[xacc] Initializing XACC Framework.");
// Get reference to the service registry
auto serviceRegistry = xacc::ServiceRegistry::instance();

// Get reference to the service registry
auto serviceRegistry = xacc::ServiceRegistry::instance();
// Parse any user-supplied command line options
xaccCLParser->parse(argc, argv);

// Parse any user-supplied command line options
xaccCLParser->parse(argc, argv);
// Check that we have some
auto s = serviceRegistry->getServices<Compiler>().size();
auto a = serviceRegistry->getServices<Accelerator>().size();

// Check that we have some
auto s = serviceRegistry->getServices<Compiler>().size();
auto a = serviceRegistry->getServices<Accelerator>().size();
XACCInfo(
"[xacc::plugins] XACC has " + std::to_string(s) + " Compiler"
+ ((s == 1 || s == 0) ? "" : "s") + " available.");
XACCInfo(
"[xacc::plugins] XACC has " + std::to_string(a) + " Accelerator"
+ ((s == 0 || s == 1) ? "" : "s") + " available.");

XACCInfo(
"[xacc::plugins] XACC has " + std::to_string(s) + " Compiler"
+ ((s == 1 || s == 0) ? "" : "s") + " available.");
XACCInfo(
"[xacc::plugins] XACC has " + std::to_string(a) + " Accelerator"
+ ((s == 0 || s == 1) ? "" : "s") + " available.");
}

// We're good if we make it here, so indicate that we've been
// initialized
Expand Down
2 changes: 2 additions & 0 deletions xacc/XACC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void Initialize(std::vector<std::string> argv);

void Initialize();

bool isInitialized();

/**
* Add a valid command line option
*/
Expand Down
5 changes: 4 additions & 1 deletion xacc/utils/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ class XACCException: public std::exception {

XACCException(std::string error) :
errorMessage(error) {
spdlog::get("xacc-console")->error("\033[1;31m" + errorMessage + "\033[0m"); \
auto c = spdlog::get("xacc-console");
if (c) {
c->error("\033[1;31m" + errorMessage + "\033[0m");
}
}

virtual const char * what() const throw () {
Expand Down

0 comments on commit 429fd55

Please sign in to comment.