Skip to content

Commit 2170167

Browse files
committed
Claude code review
1 parent 6dfa55e commit 2170167

21 files changed

+141
-111
lines changed

CMakeLists.txt

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ find_package(SimGrid 4.1 REQUIRED)
1515
find_package(FSMod 0.3.1 REQUIRED)
1616
find_package(nlohmann_json REQUIRED)
1717

18-
include_directories(
19-
${CMAKE_SOURCE_DIR}/include
20-
${SimGrid_INCLUDE_DIR}
21-
${FSMod_INCLUDE_DIR}
22-
${CMAKE_BINARY_DIR}/include
23-
)
18+
# Note: Global include_directories removed in favor of target-specific includes below
2419

2520
set(CMAKE_CXX_STANDARD 17)
2621
set(CMAKE_CXX_STANDARD_REQUIRED ON)
27-
set(CMAKE_CXX_FLAGS "-O3 -funroll-loops -fno-strict-aliasing -flto=auto")
22+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -funroll-loops -fno-strict-aliasing -flto=auto -DNDEBUG")
23+
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -Wall -Wextra")
24+
25+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
26+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
27+
endif()
2828

2929
# build the version number
3030
set(DTLMOD_VERSION_MAJOR "0")
@@ -109,7 +109,7 @@ if(enable_python)
109109
${python_files}
110110
${pybind11_options})
111111

112-
target_compile_features(python-bindings PRIVATE cxx_std_14)
112+
target_compile_features(python-bindings PRIVATE cxx_std_17)
113113
target_link_libraries(python-bindings PUBLIC dtlmod)
114114
set_target_properties(python-bindings PROPERTIES
115115
LIBRARY_OUTPUT_NAME dtlmod
@@ -178,10 +178,18 @@ set_target_properties(dtlmod PROPERTIES
178178
LINKER_LANGUAGE CXX
179179
PUBLIC_HEADER "${HEADER_FILES}")
180180

181-
target_include_directories(dtlmod PRIVATE include)
181+
target_include_directories(dtlmod
182+
PUBLIC
183+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
184+
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
185+
$<INSTALL_INTERFACE:include>
186+
PRIVATE
187+
${SimGrid_INCLUDE_DIR}
188+
${FSMod_INCLUDE_DIR}
189+
)
182190
target_link_libraries(dtlmod PUBLIC ${SimGrid_LIBRARY} ${FSMOD_LIBRARY})
183191

184-
foreach (conf "${CONFIG_FILES}")
192+
foreach (conf ${CONFIG_FILES})
185193
add_custom_command(
186194
TARGET ${PROJECT_NAME} POST_BUILD
187195
COMMAND ${CMAKE_COMMAND} -E copy
@@ -210,8 +218,13 @@ if(GTEST_LIBRARY)
210218

211219
add_definitions(-DGTEST_USED)
212220
add_executable(unit_tests EXCLUDE_FROM_ALL ${SOURCE_FILES} ${HEADER_FILES} ${TEST_FILES})
213-
target_include_directories(unit_tests PRIVATE include)
214-
target_link_libraries(unit_tests ${GTEST_LIBRARY} ${SIMGRID_LIBRARY} ${FSMOD_LIBRARY} dtlmod -lpthread -lm)
221+
target_include_directories(unit_tests PRIVATE
222+
${CMAKE_SOURCE_DIR}/include
223+
${CMAKE_BINARY_DIR}/include
224+
${SimGrid_INCLUDE_DIR}
225+
${FSMod_INCLUDE_DIR}
226+
)
227+
target_link_libraries(unit_tests ${GTEST_LIBRARY} ${SimGrid_LIBRARY} ${FSMOD_LIBRARY} dtlmod -lpthread -lm)
215228
set_target_properties(unit_tests PROPERTIES COMPILE_FLAGS "-g -O0 --coverage")
216229
set_target_properties(unit_tests PROPERTIES LINK_FLAGS "--coverage")
217230
#add_custom_command(TARGET unit_tests COMMAND find . -name *.gcda -delete)

include/dtlmod/DTL.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef __DTLMOD_DTL_HPP__
77
#define __DTLMOD_DTL_HPP__
88

9+
#include <optional>
10+
911
#include <xbt/log.h>
1012

1113
#include "dtlmod/Stream.hpp"
@@ -35,15 +37,13 @@ class DTL {
3537
explicit DTL(const std::string& filename);
3638
/// \endcond
3739

38-
/// @brief Create the Data Transport Layer.
39-
static void create();
4040
/// @brief Create the Data Transport Layer.
4141
/// @param filename: a JSON configuration file that provide stream parameters.
42-
static void create(const std::string& filename);
42+
static void create(const std::string& filename = "");
4343

4444
/// @brief Connect an Actor to the Data Transport Layer.
4545
/// @return A handler on the DTL object.
46-
static std::shared_ptr<DTL> connect();
46+
[[nodiscard]] static std::shared_ptr<DTL> connect();
4747
/// @brief Disconnect an Actor from the Data Transport Layer.
4848
static void disconnect();
4949

@@ -54,16 +54,16 @@ class DTL {
5454
/// @brief Add a data stream to the Data Transport Layer.
5555
/// @param name The name of the Stream to add to the DTL.
5656
/// @return A handler on the newly created Stream object.
57-
std::shared_ptr<Stream> add_stream(const std::string& name);
57+
[[nodiscard]] std::shared_ptr<Stream> add_stream(const std::string& name);
5858

5959
/// @brief Retrieve all streams declared in the Data Transport Layer.
6060
/// @return a map of handlers on Stream objects with their names as keys.
6161
const std::unordered_map<std::string, std::shared_ptr<Stream>>& get_all_streams() const { return streams_; }
6262

6363
/// @brief Retrieve a data stream from the Data Transport Layer by its name.
6464
/// @param name The name of the Stream to retrieve.
65-
/// @return A handler on the Stream object or nullptr if it doesn't exist.
66-
std::shared_ptr<Stream> get_stream_by_name_or_null(const std::string& name) const;
65+
/// @return An optional containing the Stream handler if found, std::nullopt otherwise.
66+
[[nodiscard]] std::optional<std::shared_ptr<Stream>> get_stream_by_name(const std::string& name) const;
6767
};
6868

6969
} // namespace dtlmod

include/dtlmod/Engine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Engine {
3434
public:
3535
/// @brief An enum that defines the type of Engine supported by the DTL
3636
enum class Type {
37-
/// @brief The Engine Type has not nee specified yet.
37+
/// @brief The Engine Type has not been specified yet.
3838
Undefined,
3939
/// @brief File Engine. Relies on files written to and read from a file system to transport data from publisher(s)
4040
/// to subscriber(s).

include/dtlmod/Metadata.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ class Metadata {
3232
protected:
3333
const std::map<std::pair<std::vector<size_t>, std::vector<size_t>>, std::pair<std::string, sg4::ActorPtr>,
3434
std::less<>>&
35-
get_blocks_for_transaction(int id)
35+
get_blocks_for_transaction(unsigned int id)
3636
{
3737
return transaction_infos_[id];
3838
}
39-
void add_transaction(int id, const std::pair<std::vector<size_t>, std::vector<size_t>>& start_and_count,
39+
void add_transaction(unsigned int id, const std::pair<std::vector<size_t>, std::vector<size_t>>& start_and_count,
4040
const std::string& filename, sg4::ActorPtr publisher);
4141

4242
public:
4343
explicit Metadata(Variable* variable) : variable_(variable) {}
44-
int get_current_transaction() const { return transaction_infos_.empty() ? -1 : (transaction_infos_.rbegin())->first; }
44+
unsigned int get_current_transaction() const
45+
{
46+
return transaction_infos_.empty() ? 0 : (transaction_infos_.rbegin())->first;
47+
}
4548
void export_to_file(std::ofstream& ostream) const;
4649
};
4750
/// \endcond

include/dtlmod/StagingEngine.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef __DTLMOD_ENGINE_STAGING_HPP__
77
#define __DTLMOD_ENGINE_STAGING_HPP__
88

9+
#include <atomic>
10+
911
#include "dtlmod/Engine.hpp"
1012

1113
XBT_LOG_EXTERNAL_CATEGORY(dtlmod);
@@ -16,7 +18,7 @@ namespace dtlmod {
1618
class StagingEngine : public Engine {
1719
sg4::ConditionVariablePtr first_pub_transaction_started_ = sg4::ConditionVariable::create();
1820
sg4::ConditionVariablePtr sub_transaction_started_ = sg4::ConditionVariable::create();
19-
int num_subscribers_starting_ = 0;
21+
std::atomic<unsigned int> num_subscribers_starting_{0};
2022
bool pub_closing_ = false;
2123
bool sub_closing_ = false;
2224

include/dtlmod/Stream.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Stream : public std::enable_shared_from_this<Stream> {
4646
Transport::Method transport_method_ = Transport::Method::Undefined;
4747
bool metadata_export_ = false;
4848
sg4::MutexPtr mutex_ = sg4::Mutex::create();
49+
sg4::ConditionVariablePtr engine_created_ = sg4::ConditionVariable::create();
4950
Mode access_mode_;
5051

5152
std::unordered_map<std::string, std::shared_ptr<Variable>> variables_;
@@ -59,7 +60,7 @@ class Stream : public std::enable_shared_from_this<Stream> {
5960
}
6061
[[nodiscard]] const char* mode_to_str(Mode mode) const
6162
{
62-
return (mode == Mode::Publish) ? "Mode::Publish" : "Mode::Suscribe";
63+
return (mode == Mode::Publish) ? "Mode::Publish" : "Mode::Subscribe";
6364
}
6465
void close() { engine_ = nullptr; }
6566
/// \endcond
@@ -115,7 +116,7 @@ class Stream : public std::enable_shared_from_this<Stream> {
115116
/// @param name name of the Engine created when opening the Stream.
116117
/// @param mode either Stream::Mode::Publish or Stream::Mode::Subscribe.
117118
/// @return A shared pointer on the corresponding Engine.
118-
std::shared_ptr<Engine> open(const std::string& name, Mode mode);
119+
[[nodiscard]] std::shared_ptr<Engine> open(const std::string& name, Mode mode);
119120

120121
/// @brief Helper function to obtain the number of actors connected to Stream in Mode::Publish.
121122
/// @return The number of publishers for that Stream.
@@ -130,7 +131,7 @@ class Stream : public std::enable_shared_from_this<Stream> {
130131
/// @param name The name of the new Variable.
131132
/// @param element_size The size of the elements in the Variable.
132133
/// @return A shared pointer on the newly created Variable.
133-
std::shared_ptr<Variable> define_variable(const std::string& name, size_t element_size);
134+
[[nodiscard]] std::shared_ptr<Variable> define_variable(const std::string& name, size_t element_size);
134135

135136
/// @brief Define a Variable for this Stream.
136137
/// @param name The name of the new variable.
@@ -139,18 +140,18 @@ class Stream : public std::enable_shared_from_this<Stream> {
139140
/// @param count A vector that specifies how many elements the calling Actor owns in each dimension.
140141
/// @param element_size The size of the elements in the Variable.
141142
/// @return A shared pointer on the newly created Variable
142-
std::shared_ptr<Variable> define_variable(const std::string& name, const std::vector<size_t>& shape,
143-
const std::vector<size_t>& start, const std::vector<size_t>& count,
144-
size_t element_size);
143+
[[nodiscard]] std::shared_ptr<Variable> define_variable(const std::string& name, const std::vector<size_t>& shape,
144+
const std::vector<size_t>& start,
145+
const std::vector<size_t>& count, size_t element_size);
145146

146147
/// @brief Retrieve the list of Variables defined on this stream
147148
/// @return the list of Variable names
148-
std::vector<std::string> get_all_variables() const;
149+
[[nodiscard]] std::vector<std::string> get_all_variables() const;
149150

150151
/// @brief Retrieve a Variable information by name.
151152
/// @param name The name of desired Variable.
152153
/// @return Either a shared pointer on the Variable object if known, nullptr otherwise.
153-
std::shared_ptr<Variable> inquire_variable(const std::string& name) const;
154+
[[nodiscard]] std::shared_ptr<Variable> inquire_variable(const std::string& name) const;
154155

155156
/// @brief Remove a Variable of the list of variables known by the Stream.
156157
/// @param name The name of the variable to remove.

include/dtlmod/Variable.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Variable {
2828
size_t element_size_;
2929
std::vector<size_t> shape_;
3030
std::unordered_map<sg4::ActorPtr, std::pair<std::vector<size_t>, std::vector<size_t>>> local_start_and_count_;
31-
int transaction_start_ = -1;
31+
unsigned int transaction_start_ = 0;
3232
unsigned int transaction_count_ = 0;
3333

3434
std::weak_ptr<const Stream> defined_in_stream_;
@@ -41,19 +41,19 @@ class Variable {
4141
protected:
4242
/// \cond EXCLUDE_FROM_DOCUMENTATION
4343
void set_metadata(std::shared_ptr<Metadata> metadata) { metadata_ = metadata; }
44-
void set_transaction_start(int start) { transaction_start_ = start; }
45-
[[nodiscard]] int get_transaction_start() const { return transaction_start_; }
46-
void set_transaction_count(int count) { transaction_count_ = count; }
44+
void set_transaction_start(unsigned int start) { transaction_start_ = start; }
45+
[[nodiscard]] unsigned int get_transaction_start() const { return transaction_start_; }
46+
void set_transaction_count(unsigned int count) { transaction_count_ = count; }
4747
[[nodiscard]] unsigned int get_transaction_count() const { return transaction_count_; }
4848

4949
void set_local_start_and_count(sg4::ActorPtr actor,
5050
const std::pair<std::vector<size_t>, std::vector<size_t>>& local_start_and_count)
5151
{
5252
local_start_and_count_[actor] = local_start_and_count;
5353
}
54-
const std::pair<std::vector<size_t>, std::vector<size_t>>& get_local_start_and_count(sg4::ActorPtr actor)
54+
const std::pair<std::vector<size_t>, std::vector<size_t>>& get_local_start_and_count(sg4::ActorPtr actor) const
5555
{
56-
return local_start_and_count_[actor];
56+
return local_start_and_count_.at(actor);
5757
}
5858

5959
void add_transaction_metadata(unsigned int transaction_id, sg4::ActorPtr publisher, const std::string& location);

src/DTL.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ namespace sg4 = simgrid::s4u;
1818
namespace dtlmod {
1919

2020
/// \cond EXCLUDE_FROM_DOCUMENTATION
21-
DTL::DTL(const std::string& filename)
21+
DTL::DTL(const std::string& filename) : mutex_(sg4::Mutex::create())
2222
{
23-
mutex_ = sg4::Mutex::create();
2423
// No configuration file has been provided. Nothing else to do
2524
if (filename.empty())
2625
return;
@@ -96,8 +95,9 @@ __attribute__((noreturn)) void DTL::connection_manager_init(std::shared_ptr<DTL>
9695
bool* connect = nullptr;
9796
auto mess = connect_mq->get_async(&connect);
9897
mess->wait();
98+
std::unique_ptr<bool> connect_guard(connect); // RAII: automatic cleanup
9999
auto* sender = mess->get_sender();
100-
if (*connect) { // Connection
100+
if (*connect_guard) { // Connection
101101
dtl->connection_manager_connect(sender);
102102
// Return a handler on the DTL to the newly connected actor
103103
handler_mq->put_init(&dtl)->detach();
@@ -107,7 +107,7 @@ __attribute__((noreturn)) void DTL::connection_manager_init(std::shared_ptr<DTL>
107107
if (!dtl->has_active_connections())
108108
XBT_WARN("The DTL has no active connection");
109109
}
110-
delete connect;
110+
// connect_guard automatically deletes connect at end of scope
111111
} while (true);
112112
}
113113
///\endcond
@@ -124,11 +124,6 @@ void DTL::create(const std::string& filename)
124124
->daemonize();
125125
}
126126

127-
void DTL::create()
128-
{
129-
create("");
130-
}
131-
132127
std::shared_ptr<DTL> DTL::connect()
133128
{
134129
sg4::MessageQueue::by_name("dtlmod::connection_manager_connect")->put(new bool(true));
@@ -152,11 +147,11 @@ std::shared_ptr<Stream> DTL::add_stream(const std::string& name)
152147
return streams_[name];
153148
}
154149

155-
std::shared_ptr<Stream> DTL::get_stream_by_name_or_null(const std::string& name) const
150+
std::optional<std::shared_ptr<Stream>> DTL::get_stream_by_name(const std::string& name) const
156151
{
157152
auto it = streams_.find(name);
158153
if (it == streams_.end())
159-
return nullptr;
154+
return std::nullopt;
160155
return it->second;
161156
}
162157
} // namespace dtlmod

src/FileEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ FileEngine::FileEngine(const std::string& fullpath, const std::shared_ptr<Stream
6565
}
6666
}
6767

68-
void FileEngine::create_transport(const Transport::Method& transport_method)
68+
void FileEngine::create_transport(const Transport::Method& /*transport_method*/)
6969
{
7070
// This function is called in a critical section. Transport can only be created once.
7171
set_transport(std::make_shared<FileTransport>(this));

src/Metadata.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(dtlmod_metadata, dtlmod, "DTL logging about Meta
1111

1212
namespace dtlmod {
1313
/// \cond EXCLUDE_FROM_DOCUMENTATION
14-
void Metadata::add_transaction(int id, const std::pair<std::vector<size_t>, std::vector<size_t>>& start_and_count,
14+
void Metadata::add_transaction(unsigned int id,
15+
const std::pair<std::vector<size_t>, std::vector<size_t>>& start_and_count,
1516
const std::string& location, sg4::ActorPtr publisher)
1617
{
1718
transaction_infos_[id][start_and_count] = std::make_pair(location, publisher);

0 commit comments

Comments
 (0)