Skip to content

Commit 9afea2e

Browse files
committed
#1: LB: make progress on LB algorithm
1 parent f4c93bc commit 9afea2e

File tree

15 files changed

+297
-64
lines changed

15 files changed

+297
-64
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ find_package(MPI REQUIRED)
1313
find_package(vt)
1414

1515
# vt includes magistrate
16-
if(NOT vt_FOUND)
16+
#if(NOT vt_FOUND)
1717
find_package(magistrate REQUIRED)
18-
endif()
18+
#endif()
1919

2020
file(
2121
GLOB
@@ -34,6 +34,7 @@ set(
3434
# Specify the C++ standard
3535
set(CMAKE_CXX_STANDARD_REQUIRED True)
3636
set(CMAKE_CXX_EXTENSIONS OFF)
37+
set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")
3738

3839
if(NOT CMAKE_CXX_STANDARD)
3940
set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")

examples/test_example.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <vt-lb/comm/comm_mpi.h>
22
#include <vt-lb/comm/comm_vt.h>
3+
#include <vt-lb/algo/driver/driver.h>
34

45
struct MyClass {
56
void myHandler(int a, double b) {
@@ -13,7 +14,7 @@ struct MyClass {
1314
};
1415

1516
int main(int argc, char** argv) {
16-
auto comm = vt_lb::comm::CommVT();
17+
auto comm = vt_lb::comm::CommMPI();
1718
comm.init(argc, argv);
1819

1920
auto cls = std::make_unique<MyClass>();
@@ -38,6 +39,13 @@ int main(int argc, char** argv) {
3839

3940
printf("out of poll\n");
4041

42+
vt_lb::runLB(
43+
vt_lb::DriverAlgoEnum::TemperedLB,
44+
comm,
45+
vt_lb::algo::temperedlb::Configuration{},
46+
nullptr
47+
);
48+
4149
comm.finalize();
4250
return 0;
4351
}

src/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
set(
22
TOP_LEVEL_SUBDIRS
3-
algo algo/baselb algo/temperedlb
3+
algo algo/baselb algo/temperedlb algo/driver
44
comm
55
input
6+
model
67
)
78

89
set(VT_LB_INSTALL_DESTINATION "include/vt-lb")
@@ -65,6 +66,8 @@ foreach(SUB_DIR ${TOP_LEVEL_SUBDIRS})
6566
)
6667
endforeach()
6768

69+
message(STATUS "VT_LB_HEADER_FILES: ${HEADER_FILES}")
70+
6871
add_library(
6972
${VT_LB_LIBRARY}
7073
STATIC

src/vt-lb/algo/baselb/baselb.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,19 @@
4444
#if !defined INCLUDED_VT_LB_ALGO_BASELB_BASELB_H
4545
#define INCLUDED_VT_LB_ALGO_BASELB_BASELB_H
4646

47+
#include <memory>
48+
#include <vt-lb/model/PhaseData.h>
49+
4750
namespace vt_lb::algo::baselb {
4851

49-
template <typename T>
5052
struct BaseLB {
53+
void inputData(std::unique_ptr<model::PhaseData> phase_data) {
54+
phase_data_ = std::move(phase_data);
55+
}
56+
57+
protected:
58+
/// @brief Phase data for load balancing
59+
std::unique_ptr<model::PhaseData> phase_data_;
5160
};
5261

5362
} /* end namespace vt_lb::algo::baselb */

src/vt-lb/algo/driver/driver.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
//@HEADER
3+
// *****************************************************************************
4+
//
5+
// driver.h
6+
// DARMA/vt-lb => Virtual Transport/Load Balancers
7+
//
8+
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
9+
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
10+
// Government retains certain rights in this software.
11+
//
12+
// Redistribution and use in source and binary forms, with or without
13+
// modification, are permitted provided that the following conditions are met:
14+
//
15+
// * Redistributions of source code must retain the above copyright notice,
16+
// this list of conditions and the following disclaimer.
17+
//
18+
// * Redistributions in binary form must reproduce the above copyright notice,
19+
// this list of conditions and the following disclaimer in the documentation
20+
// and/or other materials provided with the distribution.
21+
//
22+
// * Neither the name of the copyright holder nor the names of its
23+
// contributors may be used to endorse or promote products derived from this
24+
// software without specific prior written permission.
25+
//
26+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36+
// POSSIBILITY OF SUCH DAMAGE.
37+
//
38+
// Questions? Contact [email protected]
39+
//
40+
// *****************************************************************************
41+
//@HEADER
42+
*/
43+
44+
#if !defined INCLUDED_VT_LB_ALGO_DRIVER_DRIVER_H
45+
#define INCLUDED_VT_LB_ALGO_DRIVER_DRIVER_H
46+
47+
#include "vt-lb/model/PhaseData.h"
48+
49+
#include <memory>
50+
51+
namespace vt_lb {
52+
53+
enum class DriverAlgoEnum {
54+
None,
55+
TemperedLB,
56+
};
57+
58+
template <typename CommT, typename ConfigT>
59+
void runLB(DriverAlgoEnum algo, CommT& comm, ConfigT config, std::unique_ptr<model::PhaseData> phase_data);
60+
61+
} /* end namespace vt_lb */
62+
63+
#include "vt-lb/algo/driver/driver.impl.h"
64+
65+
#endif /*INCLUDED_VT_LB_ALGO_DRIVER_DRIVER_H*/
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
//@HEADER
3+
// *****************************************************************************
4+
//
5+
// driver.cc
6+
// DARMA/vt-lb => Virtual Transport/Load Balancers
7+
//
8+
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
9+
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
10+
// Government retains certain rights in this software.
11+
//
12+
// Redistribution and use in source and binary forms, with or without
13+
// modification, are permitted provided that the following conditions are met:
14+
//
15+
// * Redistributions of source code must retain the above copyright notice,
16+
// this list of conditions and the following disclaimer.
17+
//
18+
// * Redistributions in binary form must reproduce the above copyright notice,
19+
// this list of conditions and the following disclaimer in the documentation
20+
// and/or other materials provided with the distribution.
21+
//
22+
// * Neither the name of the copyright holder nor the names of its
23+
// contributors may be used to endorse or promote products derived from this
24+
// software without specific prior written permission.
25+
//
26+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36+
// POSSIBILITY OF SUCH DAMAGE.
37+
//
38+
// Questions? Contact [email protected]
39+
//
40+
// *****************************************************************************
41+
//@HEADER
42+
*/
43+
44+
#if !defined INCLUDED_VT_LB_ALGO_DRIVER_DRIVER_IMPL_H
45+
#define INCLUDED_VT_LB_ALGO_DRIVER_DRIVER_IMPL_H
46+
47+
#include <vt-lb/algo/temperedlb/temperedlb.h>
48+
#include "vt-lb/algo/driver/driver.h"
49+
50+
namespace vt_lb {
51+
52+
template <typename CommT, typename ConfigT>
53+
void runLB(DriverAlgoEnum algo, CommT& comm, ConfigT config, std::unique_ptr<model::PhaseData> phase_data) {
54+
switch (algo) {
55+
case DriverAlgoEnum::None:
56+
// No load balancing
57+
break;
58+
case DriverAlgoEnum::TemperedLB:
59+
{
60+
// Run TemperedLB algorithm
61+
auto lb = std::make_unique<algo::temperedlb::TemperedLB<CommT>>(comm, config);
62+
lb->makeHandle();
63+
lb->inputData(std::move(phase_data));
64+
lb->run();
65+
}
66+
break;
67+
default:
68+
throw std::runtime_error("Invalid load balancer algorithm");
69+
}
70+
}
71+
72+
} /* end namespace vt_lb */
73+
74+
#endif /*INCLUDED_VT_LB_ALGO_DRIVER_DRIVER_IMPL_H*/

src/vt-lb/algo/temperedlb/temperedlb.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ struct Configuration {
7474

7575
/// @brief Work model parameters (rank-alpha, beta, gamma, delta)
7676
WorkModel work_model_;
77-
77+
7878
/// @brief Tolerance for convergence
7979
double converge_tolerance_ = 0.01;
8080
};
8181

82-
template <typename T, typename CommT>
83-
struct TemperedLB : baselb::BaseLB<T> {
82+
template <typename CommT>
83+
struct TemperedLB : baselb::BaseLB {
8484

8585
// Assert that CommT conforms to the communication interface we expect
86-
//static_assert(comm::is_comm_conformant<CommT>::value, "CommT must be comm conformant");
86+
static_assert(comm::is_comm_conformant<CommT>::value, "CommT must be comm conformant");
8787

8888
/**
8989
* @brief Construct a new TemperedLB object
90-
*
90+
*
9191
* @param comm Communication interface
9292
* @param config Configuration parameters
9393
*/
@@ -96,11 +96,21 @@ struct TemperedLB : baselb::BaseLB<T> {
9696
config_(config)
9797
{ }
9898

99+
void makeHandle() {
100+
handle_ = comm_.template registerInstanceCollective<TemperedLB<CommT>>(this);
101+
}
102+
103+
void run() {
104+
// Implementation of the TemperedLB algorithm would go here
105+
}
106+
99107
private:
100108
/// @brief Communication interface
101109
CommT& comm_;
102-
/// @brief Configuration parameters
110+
/// @brief Configuration parameters
103111
Configuration config_;
112+
/// @brief Handle to this load balancer instance
113+
typename CommT::template HandleType<TemperedLB<CommT>> handle_;
104114
};
105115

106116
} /* end namespace vt_lb::algo::temperedlb */

src/vt-lb/comm/class_handle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ struct ClassHandle {
9090

9191
friend struct ClassHandleRank<T>;
9292

93+
int getIndex() const { return index_; }
94+
9395
private:
9496
int index_ = 0;
9597
CommMPI* comm_;

src/vt-lb/comm/class_handle.impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ClassHandleRank<T> ClassHandle<T>::operator[](int rank) {
9191
template <typename T>
9292
template <auto fn, typename... Args>
9393
void ClassHandle<T>::send(int dest, Args&&... args) {
94-
comm_->template send<fn>(dest, index_, std::forward<Args>(args)...);
94+
comm_->template send<fn>(dest, *this, std::forward<Args>(args)...);
9595
}
9696

9797
template <typename T>

src/vt-lb/comm/comm_mpi.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555

5656
#include <checkpoint/checkpoint.h>
5757

58-
#include "termination.h"
59-
#include "class_handle.h"
58+
#include "vt-lb/comm/termination.h"
59+
#include "vt-lb/comm/class_handle.h"
6060

6161
/**
6262
* \namespace vt_lb::comm
@@ -167,6 +167,9 @@ struct CommMPI {
167167
using SizeType = std::size_t;
168168
using RequestType = MPI_Request;
169169

170+
template <typename T>
171+
using HandleType = ClassHandle<T>;
172+
170173
/**
171174
* \brief Construct a new CommMPI instance
172175
* \param comm The MPI communicator to use (defaults to MPI_COMM_WORLD)
@@ -247,9 +250,9 @@ struct CommMPI {
247250
* \param args Arguments to serialize and send
248251
* \throws std::runtime_error if destination rank is invalid
249252
*/
250-
template <auto fn, typename... Args>
251-
void send(int dest, int idx, Args&&... args) {
252-
sendImpl<fn>(dest, idx, false, std::forward<Args>(args)...);
253+
template <auto fn, typename ProxyT, typename... Args>
254+
void send(int dest, ProxyT proxy, Args&&... args) {
255+
sendImpl<fn>(dest, proxy.getIndex(), false, std::forward<Args>(args)...);
253256
}
254257

255258
template <auto fn, typename... Args>

0 commit comments

Comments
 (0)