Skip to content

Commit

Permalink
[software] Simplify omp dynamic schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
sant0s12 committed Jun 13, 2024
1 parent 4936e8a commit d4805c1
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions software/runtime/kmp/team.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <array>
#include <mutex>
#include <optional>
#include <variant>

namespace kmp {

Expand All @@ -22,16 +21,12 @@ class Barrier;

class Team {

template <typename T, typename SignedT = typename std::make_signed<T>::type,
typename UnsignedT = typename std::make_unsigned<T>::type>
struct DynamicSchedule {
DynamicSchedule() {}

T lowerNext = 0;
T upper = 0;
SignedT chunk = 0;
SignedT incr = 0;
SignedT stride = 0;
kmp_uint32 lowerNext = 0;
kmp_uint32 upper = 0;
kmp_uint32 chunk = 0; // Chunk size assumed to be positive
kmp_int32 incr = 0;
kmp_int32 stride = 0;

bool valid = false;
kmp_uint32 numDone = 0;
Expand Down Expand Up @@ -150,7 +145,7 @@ class Team {

DEBUG_PRINT("Dispatch init\n");

auto &dynamicSchedule = std::get<DynamicSchedule<T>>(this->dynamicSchedule);
DEBUG_PRINT("Got dynamic schedule\n");

switch (schedtype) {
case kmp_sch_dynamic_chunked: {
Expand All @@ -163,9 +158,9 @@ class Team {

SignedT span = incr * chunk;

dynamicSchedule.lowerNext = lower;
dynamicSchedule.upper = upper;
dynamicSchedule.chunk = chunk;
dynamicSchedule.lowerNext = static_cast<kmp_uint32>(lower);
dynamicSchedule.upper = static_cast<kmp_uint32>(upper);
dynamicSchedule.chunk = static_cast<kmp_uint32>(chunk);
dynamicSchedule.incr = incr;
dynamicSchedule.stride = span * static_cast<SignedT>(numThreads);

Expand Down Expand Up @@ -193,8 +188,6 @@ class Team {

DEBUG_PRINT("Dispatch next\n");

auto &dynamicSchedule = std::get<DynamicSchedule<T>>(this->dynamicSchedule);

std::lock_guard<Mutex> lock(dynamicSchedule.mutex);
assert(dynamicSchedule.valid && "Dynamic schedule is not valid");

Expand All @@ -208,14 +201,14 @@ class Team {
return false;
}

*plower = dynamicSchedule.lowerNext;
*plower = static_cast<T>(dynamicSchedule.lowerNext);

dynamicSchedule.lowerNext += static_cast<T>(dynamicSchedule.chunk);
dynamicSchedule.lowerNext += dynamicSchedule.chunk;
if (dynamicSchedule.lowerNext > dynamicSchedule.upper) {
*pupper = dynamicSchedule.upper;
*pupper = static_cast<T>(dynamicSchedule.upper);
*plastiter = true;
} else {
*pupper = dynamicSchedule.lowerNext - 1;
*pupper = static_cast<T>(dynamicSchedule.lowerNext - 1);
*plastiter = false;
}

Expand All @@ -231,8 +224,7 @@ class Team {

Barrier barrier;

std::variant<DynamicSchedule<kmp_int32>, DynamicSchedule<kmp_uint32>>
dynamicSchedule;
DynamicSchedule dynamicSchedule;

void *copyPrivateData = nullptr;

Expand Down

0 comments on commit d4805c1

Please sign in to comment.