-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from LBNL-ETA/ChangeThreadingAlgorithm
Change threading algorithm
- Loading branch information
Showing
24 changed files
with
295 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "Utility.hpp" | ||
|
||
namespace FenestrationCommon | ||
{ | ||
IndexRange::IndexRange(unsigned startIndex, unsigned endIndex) : | ||
start(startIndex), end(endIndex) | ||
{} | ||
|
||
std::vector<IndexRange> chunkIt(unsigned start, unsigned end, unsigned numberOfSplits) | ||
{ | ||
unsigned stepSize{numberOfSplits < (end - start) | ||
? static_cast<unsigned>((end - start) / numberOfSplits) | ||
: 0u}; | ||
|
||
std::vector<IndexRange> result; | ||
|
||
unsigned currentStart{start}; | ||
unsigned currentEnd{currentStart}; | ||
|
||
do | ||
{ | ||
currentEnd = currentStart + stepSize < end ? currentStart + stepSize + 1u : end + 1u; | ||
result.emplace_back(currentStart, currentEnd); | ||
currentStart = currentEnd; | ||
} while(currentEnd < end + 1u); | ||
|
||
return result; | ||
} | ||
} // namespace FenestrationCommon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
namespace FenestrationCommon | ||
{ | ||
struct IndexRange | ||
{ | ||
IndexRange(unsigned startIndex, unsigned endIndex); | ||
unsigned start{0u}; | ||
unsigned end{0u}; | ||
}; | ||
|
||
//! Makes division for indexes that are defined from start to end for the purpose of multithreading. | ||
std::vector<IndexRange> chunkIt(unsigned start, unsigned end, unsigned numberOfSplits); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#include <vector> | ||
#include <gtest/gtest.h> | ||
|
||
#include "WCECommon.hpp" | ||
|
||
using namespace FenestrationCommon; | ||
|
||
class TestChunkIt : public testing::Test | ||
{}; | ||
|
||
TEST_F(TestChunkIt, Chunk1) | ||
{ | ||
constexpr size_t start{0u}; | ||
constexpr size_t end{3u}; | ||
constexpr size_t numberOfSplits{2u}; | ||
|
||
const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; | ||
const std::vector<FenestrationCommon::IndexRange> correct{{0u, 2u}, {2u, 4u}}; | ||
|
||
EXPECT_EQ(result.size(), correct.size()); | ||
for(size_t i = 0u; i < correct.size(); ++i) | ||
{ | ||
EXPECT_EQ(result[i].start, correct[i].start); | ||
EXPECT_EQ(result[i].end, correct[i].end); | ||
} | ||
} | ||
|
||
TEST_F(TestChunkIt, Chunk2) | ||
{ | ||
constexpr size_t start{0u}; | ||
constexpr size_t end{3u}; | ||
constexpr size_t numberOfSplits{12u}; | ||
|
||
const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; | ||
const std::vector<FenestrationCommon::IndexRange> correct{ | ||
{0u, 1u}, {1u, 2u}, {2u, 3u}, {3u, 4u}}; | ||
|
||
EXPECT_EQ(result.size(), correct.size()); | ||
for(size_t i = 0u; i < correct.size(); ++i) | ||
{ | ||
EXPECT_EQ(result[i].start, correct[i].start); | ||
EXPECT_EQ(result[i].end, correct[i].end); | ||
} | ||
} | ||
|
||
TEST_F(TestChunkIt, Chunk3) | ||
{ | ||
constexpr size_t start{1u}; | ||
constexpr size_t end{4u}; | ||
constexpr size_t numberOfSplits{2u}; | ||
|
||
const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; | ||
const std::vector<FenestrationCommon::IndexRange> correct{{1u, 3u}, {3u, 5u}}; | ||
|
||
EXPECT_EQ(result.size(), correct.size()); | ||
for(size_t i = 0u; i < correct.size(); ++i) | ||
{ | ||
EXPECT_EQ(result[i].start, correct[i].start); | ||
EXPECT_EQ(result[i].end, correct[i].end); | ||
} | ||
} | ||
|
||
TEST_F(TestChunkIt, Chunk4) | ||
{ | ||
constexpr size_t start{3u}; | ||
constexpr size_t end{5u}; | ||
constexpr size_t numberOfSplits{12u}; | ||
|
||
const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; | ||
const std::vector<FenestrationCommon::IndexRange> correct{{3u, 4u}, {4u, 5u}, {5u, 6u}}; | ||
|
||
EXPECT_EQ(result.size(), correct.size()); | ||
for(size_t i = 0u; i < correct.size(); ++i) | ||
{ | ||
EXPECT_EQ(result[i].start, correct[i].start); | ||
EXPECT_EQ(result[i].end, correct[i].end); | ||
} | ||
} | ||
|
||
TEST_F(TestChunkIt, Chunk5) | ||
{ | ||
constexpr size_t start{5u}; | ||
constexpr size_t end{5u}; | ||
constexpr size_t numberOfSplits{12u}; | ||
|
||
const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; | ||
const std::vector<FenestrationCommon::IndexRange> correct{{5u, 6u}}; | ||
|
||
EXPECT_EQ(result.size(), correct.size()); | ||
for(size_t i = 0u; i < correct.size(); ++i) | ||
{ | ||
EXPECT_EQ(result[i].start, correct[i].start); | ||
EXPECT_EQ(result[i].end, correct[i].end); | ||
} | ||
} | ||
|
||
TEST_F(TestChunkIt, Chunk6) | ||
{ | ||
constexpr size_t start{0u}; | ||
constexpr size_t end{110u}; | ||
constexpr size_t numberOfSplits{12u}; | ||
|
||
const auto result{FenestrationCommon::chunkIt(start, end, numberOfSplits)}; | ||
const std::vector<FenestrationCommon::IndexRange> correct{{0u, 10u}, | ||
{10u, 20u}, | ||
{20u, 30u}, | ||
{30u, 40u}, | ||
{40u, 50u}, | ||
{50u, 60u}, | ||
{60u, 70u}, | ||
{70u, 80u}, | ||
{80u, 90u}, | ||
{90u, 100u}, | ||
{100u, 110u}, | ||
{110u, 111u}}; | ||
|
||
EXPECT_EQ(result.size(), correct.size()); | ||
for(size_t i = 0u; i < correct.size(); ++i) | ||
{ | ||
EXPECT_EQ(result[i].start, correct[i].start); | ||
EXPECT_EQ(result[i].end, correct[i].end); | ||
} | ||
} |
Oops, something went wrong.