Skip to content

Commit 7194dde

Browse files
authored
Merge pull request #73 from LLNL/develop
v0.4 Prep
2 parents 4957ce4 + e307751 commit 7194dde

File tree

5 files changed

+47
-28
lines changed

5 files changed

+47
-28
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ if (NOT cereal_FOUND)
9999
# Populate cereal
100100
FetchContent_Populate(cereal)
101101
# Include cereal root cmake boilerplate
102-
add_subdirectory(${cereal_SOURCE_DIR})
102+
add_subdirectory(${cereal_SOURCE_DIR} ${cereal_BINARY_DIR})
103+
103104
message(STATUS "YGM cloned cereal dependency: " ${cereal_SOURCE_DIR})
104105
endif ()
105106
target_link_libraries(ygm INTERFACE cereal::cereal)

Readme.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,29 @@ perform a user-provided function only on the desired data. These containers are
2727
YGM is a header-only library that is easy to incorporate into a project through CMake. Adding the following to
2828
CMakeLists.txt will install YGM and its dependencies as part of your project:
2929
```
30-
find_package(ygm CONFIG)
31-
if(NOT ygm_FOUND)
30+
set(DESIRED_YGM_VERSION 0.3)
31+
find_package(ygm ${DESIRED_YGM_VERSION} CONFIG)
32+
if (NOT ygm_FOUND)
3233
FetchContent_Declare(
3334
ygm
3435
GIT_REPOSITORY https://github.com/LLNL/ygm
35-
GIT_TAG <commit hash here>
36-
)
37-
set(JUST_INSTALL_YGM ON)
38-
set(YGM_INSTALL ON)
39-
FetchContent_MakeAvailable(ygm)
40-
message(STATUS "Cloned ygm dependency " ${ygm_SOURCE_DIR})
41-
else()
42-
message(STATUS "Found ygm dependency " ${ygm_DIR})
43-
endif()
44-
target_link_libraries(my_cool_project INTERFACE ygm::ygm)
36+
GIT_TAG v${DESIRED_YGM_VERSION}
37+
)
38+
FetchContent_GetProperties(ygm)
39+
if (ygm_POPULATED)
40+
message(STATUS "Found already populated ygm dependency: "
41+
${ygm_SOURCE_DIR}
42+
)
43+
else ()
44+
set(JUST_INSTALL_YGM ON)
45+
set(YGM_INSTALL ON)
46+
FetchContent_Populate(ygm)
47+
add_subdirectory(${ygm_SOURCE_DIR} ${ygm_BINARY_DIR})
48+
message(STATUS "Cloned ygm dependency " ${ygm_SOURCE_DIR})
49+
endif ()
50+
else ()
51+
message(STATUS "Found installed ygm dependency " ${ygm_DIR})
52+
endif ()
4553
```
4654

4755
# Anatomy of a YGM Program

include/ygm/comm.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@
1414
namespace ygm {
1515

1616
class comm {
17+
private:
18+
class impl;
19+
1720
public:
1821
comm(int *argc, char ***argv, int buffer_capacity);
1922

2023
// TODO: Add way to detect if this MPI_Comm is already open. E.g., static
2124
// map<MPI_Comm, impl*>
2225
comm(MPI_Comm comm, int buffer_capacity);
2326

27+
// Constructor to allow comm::impl to build temporary comm using itself as the
28+
// impl
29+
comm(std::shared_ptr<impl> impl_ptr);
30+
2431
~comm();
2532

2633
//
@@ -150,7 +157,6 @@ class comm {
150157
private:
151158
comm() = delete;
152159

153-
class impl;
154160
std::shared_ptr<impl> pimpl;
155161
std::shared_ptr<detail::mpi_init_finalize> pimpl_if;
156162
};

include/ygm/detail/comm_impl.hpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace ygm {
2121

22-
class comm::impl {
22+
class comm::impl : public std::enable_shared_from_this<comm::impl> {
2323
public:
2424
impl(MPI_Comm c, int buffer_capacity) {
2525
ASSERT_MPI(MPI_Comm_dup(c, &m_comm_async));
@@ -35,7 +35,6 @@ class comm::impl {
3535
}
3636

3737
~impl() {
38-
barrier();
3938
// send kill signal to self (listener thread)
4039
ASSERT_RELEASE(MPI_Send(NULL, 0, MPI_BYTE, m_comm_rank, 0, m_comm_async) ==
4140
MPI_SUCCESS);
@@ -399,12 +398,12 @@ class comm::impl {
399398
std::forward<const PackArgs>(args)...);
400399
ASSERT_DEBUG(sizeof(Lambda) == 1);
401400

402-
void (*fun_ptr)(impl *, cereal::YGMInputArchive &) =
403-
[](impl *t, cereal::YGMInputArchive &bia) {
401+
void (*fun_ptr)(comm *, cereal::YGMInputArchive &) =
402+
[](comm *c, cereal::YGMInputArchive &bia) {
404403
std::tuple<PackArgs...> ta;
405404
bia(ta);
406405
Lambda *pl = nullptr;
407-
auto t1 = std::make_tuple((impl *)t);
406+
auto t1 = std::make_tuple((comm *)c);
408407

409408
// \pp was: std::apply(*pl, std::tuple_cat(t1, ta));
410409
ygm::meta::apply_optional(*pl, std::move(t1), std::move(ta));
@@ -430,6 +429,7 @@ class comm::impl {
430429
*/
431430
bool process_receive_queue() {
432431
bool received = false;
432+
comm tmp_comm(shared_from_this());
433433
while (true) {
434434
auto buffer = receive_queue_try_pop();
435435
if (buffer.second == 0) break;
@@ -439,9 +439,9 @@ class comm::impl {
439439
int64_t iptr;
440440
iarchive(iptr);
441441
iptr += (int64_t)&reference;
442-
void (*fun_ptr)(impl *, cereal::YGMInputArchive &);
442+
void (*fun_ptr)(comm *, cereal::YGMInputArchive &);
443443
memcpy(&fun_ptr, &iptr, sizeof(uint64_t));
444-
fun_ptr(this, iarchive);
444+
fun_ptr(&tmp_comm, iarchive);
445445
m_recv_count++;
446446
m_local_rpc_calls++;
447447
}
@@ -496,10 +496,13 @@ inline comm::comm(MPI_Comm mcomm, int buffer_capacity = 16 * 1024 * 1024) {
496496
pimpl = std::make_shared<comm::impl>(mcomm, buffer_capacity);
497497
}
498498

499+
inline comm::comm(std::shared_ptr<impl> impl_ptr) : pimpl(impl_ptr) {}
500+
499501
inline comm::~comm() {
500-
ASSERT_RELEASE(MPI_Barrier(MPI_COMM_WORLD) == MPI_SUCCESS);
502+
if (pimpl.use_count() == 1) {
503+
barrier();
504+
}
501505
pimpl.reset();
502-
ASSERT_RELEASE(MPI_Barrier(MPI_COMM_WORLD) == MPI_SUCCESS);
503506
pimpl_if.reset();
504507
}
505508

include/ygm/io/csv_parser.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ class csv_parser {
2828
void for_all(Function fn) {
2929
using namespace ygm::io::detail;
3030
m_lp.for_all([fn](const std::string& line) {
31-
auto vfields = parse_csv_line(line);
32-
//auto stypes = convert_type_string(vfields);
33-
//todo, detect if types are inconsistent between records
34-
fn(vfields);
31+
auto vfields = parse_csv_line(line);
32+
// auto stypes = convert_type_string(vfields);
33+
// todo, detect if types are inconsistent between records
34+
if (vfields.size() > 0) {
35+
fn(vfields);
36+
}
3537
});
3638
}
3739

3840
private:
3941
line_parser m_lp;
4042
};
41-
4243
} // namespace ygm::io

0 commit comments

Comments
 (0)