Skip to content

Commit

Permalink
Fix CI: the app needs to be able to work without MPI support
Browse files Browse the repository at this point in the history
  • Loading branch information
1tnguyen committed Jan 11, 2024
1 parent 7aed295 commit fe58a45
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions runtime/cudaq.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ std::size_t get_random_seed();
int num_available_gpus();

namespace mpi {
/// @brief Return true if CUDA Quantum has MPI plugin support.
bool available();

/// @brief Initialize MPI if available. This function
/// is a no-op if there CUDA Quantum has not been built
/// against MPI.
Expand Down
5 changes: 5 additions & 0 deletions runtime/cudaq/cudaq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ cudaq::MPIPlugin *getMpiPlugin(bool unsafe) {
return g_plugin.get();
};

bool available() {
auto *commPlugin = getMpiPlugin(true);
return commPlugin != nullptr;
}

void initialize() {
auto *commPlugin = getMpiPlugin();
commPlugin->initialize();
Expand Down
7 changes: 5 additions & 2 deletions tools/cudaq-qpud/RestServerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace cudaq {
namespace mpi {
void initialize();
void finalize();
bool available();
} // namespace mpi
} // namespace cudaq

Expand All @@ -28,9 +29,11 @@ static llvm::cl::opt<int>

int main(int argc, char **argv) {
llvm::cl::ParseCommandLineOptions(argc, argv, "CUDA Quantum REST server\n");
cudaq::mpi::initialize();
if (cudaq::mpi::available())
cudaq::mpi::initialize();
auto restServer = cudaq::registry::get<cudaq::RemoteRuntimeServer>("rest");
restServer->init({{"port", std::to_string(port)}});
restServer->start();
cudaq::mpi::finalize();
if (cudaq::mpi::available())
cudaq::mpi::finalize();
}

0 comments on commit fe58a45

Please sign in to comment.