Skip to content

Commit 33f2d65

Browse files
committed
libdistributed version 0.0.3
Bug Fixes: + Prefix names with libdistributed to avoid name conflicts + Fix CMake Export to make it easier to use from other packages. + Fix invalid MPI_Isend call by taking the address of an object rather than passing it itself + Fix multiple send to actually send multiple values
1 parent 121ed8e commit 33f2d65

9 files changed

+71
-42
lines changed

CMakeLists.txt

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.12)
2-
project(libdistributed VERSION "0.0.2" LANGUAGES CXX)
2+
project(libdistributed VERSION "0.0.3" LANGUAGES CXX)
33

44
#correct was to set a default build type
55
# https://blog.kitware.com/cmake-and-the-default-build-type/
@@ -31,8 +31,12 @@ add_library(libdistributed
3131
src/work_queue.cc
3232

3333
#public headers
34-
include/work_queue.h
35-
include/types.h
34+
include/libdistributed_stop_token.h
35+
include/libdistributed_types.h
36+
include/libdistributed_work_queue.h
37+
38+
#private headers
39+
include/libdistributed_work_queue_impl.h
3640
)
3741
target_include_directories(
3842
libdistributed
@@ -50,13 +54,14 @@ if(USE_CLANG_TIDY)
5054
set_target_properties(libdistributed PROPERTIES C_CLANG_TIDY "${CLANG_TIDY}")
5155
endif()
5256

53-
export(TARGETS libdistributed NAMESPACE LibDistributed:: FILE LibDistributed.cmake)
54-
install(TARGETS libdistributed EXPORT LibDistributed
57+
export(TARGETS libdistributed NAMESPACE LibDistributed:: FILE
58+
LibDistributedConfig.cmake)
59+
install(TARGETS libdistributed EXPORT LibDistributedConfig
5560
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
5661
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
5762
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
5863
)
59-
install(EXPORT LibDistributed NAMESPACE LibDistributed:: DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/LibDistributed/cmake)
64+
install(EXPORT LibDistributedConfig NAMESPACE LibDistributed:: DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/LibDistributed/cmake)
6065
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libdistributed)
6166

6267
option(BUILD_DOCS "build the documetation" OFF)

include/stop_token.h include/libdistributed_stop_token.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#pragma once
1+
#ifndef LIBDISTRIBUTED_STOP_TOKEN_H
2+
#define LIBDISTRIBUTED_STOP_TOKEN_H
23

34
/**
45
* \file
@@ -32,3 +33,5 @@ class StopToken {
3233

3334
}
3435
}
36+
37+
#endif

include/types.h include/libdistributed_types.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifndef LIBDISTRIBUTED_TYPES_H
2+
#define LIBDISTRIBUTED_TYPES_H
13
#include <array>
24
#include <vector>
35
#include <algorithm>
@@ -184,3 +186,5 @@ namespace distributed {
184186

185187
}
186188
}
189+
190+
#endif

include/work_queue.h include/libdistributed_work_queue.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#ifndef LIBDISTRIBUTED_WORK_QUEUE_H
2+
#define LIBDISTRIBUTED_WORK_QUEUE_H
13
#include <mpi.h>
24
#include <utility>
3-
#include "types.h"
4-
#include "stop_token.h"
5-
#include "work_queue_impl.h"
5+
#include "libdistributed_types.h"
6+
#include "libdistributed_stop_token.h"
7+
#include "libdistributed_work_queue_impl.h"
68

79
/**
810
* \file
@@ -88,3 +90,4 @@ void work_queue (
8890

8991
}
9092
}
93+
#endif

include/work_queue_impl.h include/libdistributed_work_queue_impl.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <type_traits>
44
#include <mpi.h>
55

6-
#include "stop_token.h"
6+
#include "libdistributed_stop_token.h"
77

88
namespace distributed {
99
namespace queue {
@@ -175,11 +175,12 @@ worker_send(MPI_Comm comm, MPI_Datatype response_dtype, IterableType iterable)
175175
auto value = *begin;
176176
MPI_Request mpi_request;
177177
for (; begin != end; ++begin) {
178+
value = *begin;
178179
MPI_Isend(&value, 1, response_dtype, ROOT, (int)worker_status::more, comm,
179180
&mpi_request);
180181
MPI_Wait(&mpi_request, MPI_STATUS_IGNORE);
181182
}
182-
MPI_Isend(value, 1, response_dtype, ROOT, (int)worker_status::done, comm, &mpi_request);
183+
MPI_Isend(&value, 1, response_dtype, ROOT, (int)worker_status::done, comm, &mpi_request);
183184
MPI_Wait(&mpi_request, MPI_STATUS_IGNORE);
184185
}
185186

test/mpi_test_main.cc

-27
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,6 @@
1-
#include <iostream>
2-
#include <string>
31
#include "mpi.h"
4-
#include <unistd.h>
52
#include "gtest/gtest.h"
63

7-
#include <execinfo.h>
8-
9-
void failing_error_handler(MPI_Comm* comm, int* ec, ...) {
10-
11-
int rank, size;
12-
MPI_Comm_size(*comm, &size);
13-
MPI_Comm_rank(*comm, &rank);
14-
int nptrs;
15-
void* backtrace_buffer[100];
16-
char** backtrace_strings;
17-
nptrs = backtrace(backtrace_buffer, 100);
18-
backtrace_strings = backtrace_symbols(backtrace_buffer, nptrs);
19-
20-
for (int i = 0; i < nptrs; ++i) {
21-
printf("BT %d/%d: [%d] %s\n", rank, size, i, backtrace_strings[i]);
22-
}
23-
free(backtrace_strings);
24-
25-
26-
int length;
27-
std::string s(MPI_MAX_ERROR_STRING, '\0');
28-
MPI_Error_string(*ec, &s[0], &length);
29-
ADD_FAILURE() << s.c_str();
30-
}
314

325
int main(int argc, char *argv[])
336
{

test/simple_queue.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <cmath>
66

77
#include <mpi.h>
8-
#include <work_queue.h>
8+
#include <libdistributed_work_queue.h>
99

1010
using namespace std::literals::chrono_literals;
1111
namespace queue = distributed::queue;

test/test_queue.cc

+41-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <chrono>
77
#include "gtest/gtest.h"
88

9-
#include "work_queue.h"
9+
#include "libdistributed_work_queue.h"
1010

1111
using namespace distributed::queue;
1212
using namespace std::literals::chrono_literals;
@@ -44,6 +44,46 @@ TEST(test_work_queue, single_no_stop) {
4444
}
4545
}
4646

47+
48+
TEST(test_work_queue, multi_no_stop) {
49+
using request = std::tuple<int>;
50+
using response = std::tuple<int, double>;
51+
std::vector<request> tasks;
52+
tasks.reserve(5);
53+
for (int i = 0; i < 5; ++i) {
54+
tasks.emplace_back(i);
55+
}
56+
std::vector<response> results;
57+
58+
work_queue(
59+
MPI_COMM_WORLD,
60+
std::begin(tasks),
61+
std::end(tasks),
62+
[](request req) {
63+
std::vector<response> responses;
64+
responses.reserve(5);
65+
int rank;
66+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
67+
auto req_value = std::get<0>(req);
68+
for (int i = 0; i < 5; ++i) {
69+
responses.emplace_back(req_value, std::pow(req_value, 2));
70+
}
71+
return responses;
72+
},
73+
[&](response res) {
74+
auto [i,d] = res;
75+
results.push_back(res);
76+
}
77+
);
78+
79+
int rank;
80+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
81+
if(rank == 0) {
82+
EXPECT_EQ(results.size(), 25);
83+
} else {
84+
EXPECT_EQ(results.size(), 0);
85+
}
86+
}
4787
namespace std{
4888
inline void PrintTo(const std::chrono::milliseconds& duration, ::std::ostream * os) {
4989
*os << duration.count() << "ms";

test/test_types.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <tuple>
22
#include <vector>
33
#include "gtest/gtest.h"
4-
#include "types.h"
4+
#include "libdistributed_types.h"
55

66
using namespace distributed::types;
77

0 commit comments

Comments
 (0)