Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: C++ and python api #1

Merged
merged 10 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
-DENABLE_EXAMPLES=ON \
-DENABLE_BEDROCK=ON \
-DENABLE_MPI=ON \
-DENABLE_PYTHON=ON \
-DCMAKE_BUILD_TYPE=Debug
make
make test
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
-DENABLE_EXAMPLES=ON \
-DENABLE_BEDROCK=ON \
-DENABLE_MPI=ON \
-DENABLE_PYTHON=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo
make
make test
Expand Down
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# See COPYRIGHT in top-level directory.
cmake_minimum_required (VERSION 3.8)
project (flock C CXX)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
enable_testing ()

add_definitions (-Wextra -Wall -Wpedantic)
Expand All @@ -13,6 +15,7 @@ option (ENABLE_EXAMPLES "Build examples" OFF)
option (ENABLE_BEDROCK "Build bedrock module" OFF)
option (ENABLE_COVERAGE "Build with coverage" OFF)
option (ENABLE_MPI "Build with MPI support" OFF)
option (ENABLE_PYTHON "Build with Python support" OFF)

# library version set here (e.g. for shared libs).
set (FLOCK_VERSION_MAJOR 0)
Expand Down Expand Up @@ -62,11 +65,21 @@ endif ()
pkg_check_modules (margo REQUIRED IMPORTED_TARGET margo)
# search for json-c
pkg_check_modules (json-c REQUIRED IMPORTED_TARGET json-c)
# search for thallium
find_package (thallium REQUIRED)

if (ENABLE_MPI)
find_package (MPI REQUIRED)
endif ()

# search for Python
if (ENABLE_PYTHON)
set (Python3_FIND_STRATEGY LOCATION)
find_package (Python3 COMPONENTS Interpreter Development REQUIRED)
find_package (pybind11 REQUIRED)
add_subdirectory (python)
endif ()

add_subdirectory (src)
if (${ENABLE_TESTS})
enable_testing ()
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
SCRIPT_DIR=$(dirname "$0")
cmake .. -DENABLE_TESTS=ON -DENABLE_BEDROCK=ON -DENABLE_EXAMPLES=ON -DENABLE_MPI=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake .. -DENABLE_TESTS=ON -DENABLE_BEDROCK=ON -DENABLE_EXAMPLES=ON -DENABLE_MPI=ON -DENABLE_PYTHON=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
make
91 changes: 91 additions & 0 deletions include/flock/cxx/client.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __FLOCK_CLIENT_HPP
#define __FLOCK_CLIENT_HPP

#include <thallium.hpp>
#include <flock/flock-client.h>
#include <flock/flock-group.h>
#include <flock/cxx/exception.hpp>
#include <flock/cxx/group.hpp>

namespace flock {

class Client {

public:

Client() = default;

Client(margo_instance_id mid, ABT_pool pool = ABT_POOL_NULL)
: m_engine{mid} {
auto err = flock_client_init(mid, pool, &m_client);
FLOCK_CONVERT_AND_THROW(err);
}

Client(const thallium::engine& engine, thallium::pool pool = thallium::pool())
: m_engine{engine} {
auto err = flock_client_init(engine.get_margo_instance(), pool.native_handle(), &m_client);
FLOCK_CONVERT_AND_THROW(err);
}

~Client() {
if(m_client != FLOCK_CLIENT_NULL) {
flock_client_finalize(m_client);
}
}

Client(Client&& other)
: m_client(other.m_client) {
other.m_client = FLOCK_CLIENT_NULL;
}

Client(const Client&) = delete;

Client& operator=(const Client&) = delete;

Client& operator=(Client&& other) {
if(this == &other) return *this;
if(m_client != FLOCK_CLIENT_NULL) {
flock_client_finalize(m_client);
}
m_client = other.m_client;
other.m_client = FLOCK_CLIENT_NULL;
return *this;
}

GroupHandle makeGroupHandle(
hg_addr_t addr,
uint16_t provider_id,
uint32_t mode = 0) const {
flock_group_handle_t gh;
auto err = flock_group_handle_create(
m_client, addr, provider_id, mode, &gh);
FLOCK_CONVERT_AND_THROW(err);
return GroupHandle(gh, false);
}

auto handle() const {
return m_client;
}

operator flock_client_t() const {
return m_client;

Check warning on line 76 in include/flock/cxx/client.hpp

View check run for this annotation

Codecov / codecov/patch

include/flock/cxx/client.hpp#L75-L76

Added lines #L75 - L76 were not covered by tests
}

auto engine() const {
return m_engine;
}

private:

thallium::engine m_engine;
flock_client_t m_client = FLOCK_CLIENT_NULL;
};

}

#endif
46 changes: 46 additions & 0 deletions include/flock/cxx/exception.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __FLOCK_EXCEPTION_HPP
#define __FLOCK_EXCEPTION_HPP

#include <flock/flock-common.h>
#include <exception>

namespace flock {

class Exception : public std::exception {

public:

Exception(flock_return_t code)
: m_code(code) {}

Check warning on line 19 in include/flock/cxx/exception.hpp

View check run for this annotation

Codecov / codecov/patch

include/flock/cxx/exception.hpp#L18-L19

Added lines #L18 - L19 were not covered by tests

const char* what() const noexcept override {

Check warning on line 21 in include/flock/cxx/exception.hpp

View check run for this annotation

Codecov / codecov/patch

include/flock/cxx/exception.hpp#L21

Added line #L21 was not covered by tests
#define X(__err__, __msg__) case __err__: return __msg__;
switch(m_code) {
FLOCK_RETURN_VALUES

Check warning on line 24 in include/flock/cxx/exception.hpp

View check run for this annotation

Codecov / codecov/patch

include/flock/cxx/exception.hpp#L23-L24

Added lines #L23 - L24 were not covered by tests
}
#undef X
return "Unknown error";

Check warning on line 27 in include/flock/cxx/exception.hpp

View check run for this annotation

Codecov / codecov/patch

include/flock/cxx/exception.hpp#L27

Added line #L27 was not covered by tests
}

auto code() const {
return m_code;
}

private:

flock_return_t m_code;
};

#define FLOCK_CONVERT_AND_THROW(__err__) do { \
if((__err__) != FLOCK_SUCCESS) { \
throw ::flock::Exception((__err__)); \
} \
} while(0)

}
#endif
Loading
Loading