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

1125 scheduler: template runInEpoch* functions #1133

Merged
merged 3 commits into from
Nov 4, 2020
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
22 changes: 0 additions & 22 deletions src/vt/scheduler/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,26 +387,4 @@ void runSchedulerThrough(EpochType epoch) {
theTerm()->consume();
}

void runInEpochRooted(ActionType&& fn) {
theSched()->triggerEvent(sched::SchedulerEvent::PendingSchedulerLoop);

auto ep = theTerm()->makeEpochRooted();
theMsg()->pushEpoch(ep);
fn();
theMsg()->popEpoch(ep);
theTerm()->finishedEpoch(ep);
runSchedulerThrough(ep);
}

void runInEpochCollective(ActionType&& fn) {
theSched()->triggerEvent(sched::SchedulerEvent::PendingSchedulerLoop);

auto ep = theTerm()->makeEpochCollective();
theMsg()->pushEpoch(ep);
fn();
theMsg()->popEpoch(ep);
theTerm()->finishedEpoch(ep);
runSchedulerThrough(ep);
}

} //end namespace vt
18 changes: 12 additions & 6 deletions src/vt/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ namespace vt {
void runScheduler();
void runSchedulerThrough(EpochType epoch);

void runInEpochRooted(ActionType&& fn);
void runInEpochCollective(ActionType&& fn);
template <typename Callable>
void runInEpochRooted(Callable&& fn);

template <typename Callable>
void runInEpochCollective(Callable&& fn);
}

namespace vt { namespace sched {
Expand Down Expand Up @@ -314,8 +317,11 @@ struct Scheduler : runtime::component::Component<Scheduler> {
std::size_t last_memory_usage_poll_ = 0;

// Access to triggerEvent.
friend void vt::runInEpochRooted(ActionType&& fn);
friend void vt::runInEpochCollective(ActionType&& fn);
template <typename Callable>
friend void vt::runInEpochRooted(Callable&& fn);

template <typename Callable>
friend void vt::runInEpochCollective(Callable&& fn);

private:
diagnostic::Counter progressCount;
Expand All @@ -329,12 +335,12 @@ struct Scheduler : runtime::component::Component<Scheduler> {

}} //end namespace vt::sched

#include "vt/scheduler/scheduler.impl.h"

namespace vt {

extern sched::Scheduler* theSched();

} //end namespace vt

#include "vt/scheduler/scheduler.impl.h"

#endif /*INCLUDED_SCHEDULER_SCHEDULER_H*/
29 changes: 29 additions & 0 deletions src/vt/scheduler/scheduler.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@
#define INCLUDED_VT_SCHEDULER_SCHEDULER_IMPL_H

#include "vt/config.h"
#include "vt/messaging/active.h"
#include "vt/termination/termination.h"

namespace vt {

template <typename Callable>
void runInEpoch(EpochType ep, Callable&& fn) {
theSched()->triggerEvent(sched::SchedulerEvent::PendingSchedulerLoop);

theMsg()->pushEpoch(ep);
fn();
theMsg()->popEpoch(ep);
theTerm()->finishedEpoch(ep);
runSchedulerThrough(ep);
}

template <typename Callable>
void runInEpochCollective(Callable&& fn) {
auto ep = theTerm()->makeEpochCollective();
runInEpoch(ep, std::forward<Callable>(fn));
}

template <typename Callable>
void runInEpochRooted(Callable&& fn) {
auto ep = theTerm()->makeEpochRooted();
runInEpoch(ep, std::forward<Callable>(fn));
}

} /* end namespace vt */

namespace vt { namespace sched {

Expand Down
90 changes: 90 additions & 0 deletions tests/unit/scheduler/test_high_level_calls.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
//@HEADER
// *****************************************************************************
//
// test_high_level_calls.cc
// DARMA Toolkit v. 1.0.0
// DARMA/vt => Virtual Transport
//
// Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact [email protected]
//
// *****************************************************************************
//@HEADER
*/

#include <gtest/gtest.h>

#include "vt/transport.h"
#include "test_parallel_harness.h"

namespace vt { namespace tests { namespace unit {

struct TestHighLevelCalls : TestParallelHarness {
bool called = false;
};
cz4rs marked this conversation as resolved.
Show resolved Hide resolved

TEST_F(TestHighLevelCalls, test_collective_lambda) {
runInEpochCollective([&]{
called = true;
});

EXPECT_EQ(called, true);
}

TEST_F(TestHighLevelCalls, test_collective_std_function) {
std::function<void()> fn = [&]{
called = true;
};
runInEpochCollective(fn);

EXPECT_EQ(called, true);
}

TEST_F(TestHighLevelCalls, test_rooted_lambda) {
runInEpochRooted([&]{
called = true;
});

EXPECT_EQ(called, true);
}

TEST_F(TestHighLevelCalls, test_rooted_std_function) {
std::function<void()> fn = [&]{
called = true;
};
runInEpochRooted(fn);

EXPECT_EQ(called, true);
}

}}} /* end namespace vt::tests::unit */