Skip to content

Commit

Permalink
Merge pull request #133 from LBNL-ETA/ChangeThreadingAlgorithm
Browse files Browse the repository at this point in the history
Change threading algorithm
  • Loading branch information
vidanovic authored Aug 16, 2022
2 parents 9de71e9 + 5c05e6b commit cfe0782
Show file tree
Hide file tree
Showing 24 changed files with 295 additions and 209 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
cmake_minimum_required(VERSION 3.5)

project(Windows-CalcEngine VERSION 1.0.11 LANGUAGES CXX)
project(Windows-CalcEngine VERSION 1.0.32 LANGUAGES CXX)

set(target_name ${PROJECT_NAME})

#set( target_name Windows-CalcEngine )

set (CMAKE_CXX_STANDARD 17)

add_definitions(-DMULTITHREADING)

include( cmake/WCEProjectMacros.cmake )
include( cmake/WCEInternalUtils.cmake )
include( cmake/WCECompilerFlags.cmake )
Expand Down
1 change: 0 additions & 1 deletion cmake/WCECompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ ENDIF ()
if (MSVC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.11))
# VS 2017 : Disable warnings from from gtest code, using deprecated code related to TR1
add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
add_definitions(-DSTL_MULTITHREADING)
endif()

macro( warning_level_update_wce )
Expand Down
2 changes: 1 addition & 1 deletion src/Common/include/WCECommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "../src/PolynomialFit.hpp"
#include "../src/Polynom.hpp"
#include "../src/mmap.hpp"
#include "../src/wceunique.hpp"
#include "../src/WavelengthSpectrum.hpp"
#include "../src/Table2D.hpp"
#include "../src/Table2DInterpolators.hpp"
#include "../src/Utility.hpp"
3 changes: 1 addition & 2 deletions src/Common/src/IntegratorStrategy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "IntegratorStrategy.hpp"
#include "Series.hpp"
#include "wceunique.hpp"
#include <cassert>

namespace FenestrationCommon
Expand Down Expand Up @@ -156,7 +155,7 @@ namespace FenestrationCommon
aStrategy = std::make_unique<CIntegratorTrapezoidalB>();
break;
case IntegrationType::PreWeighted:
aStrategy = wce::make_unique<CIntegratorPreWeighted>();
aStrategy = std::make_unique<CIntegratorPreWeighted>();
break;
default:
assert("Irregular call of integration strategy.");
Expand Down
1 change: 0 additions & 1 deletion src/Common/src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <algorithm>
#include <cmath>

#include "wceunique.hpp"
#include "Series.hpp"
#include "IntegratorStrategy.hpp"

Expand Down
29 changes: 29 additions & 0 deletions src/Common/src/Utility.cpp
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
16 changes: 16 additions & 0 deletions src/Common/src/Utility.hpp
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);
}
18 changes: 0 additions & 18 deletions src/Common/src/wceunique.hpp

This file was deleted.

123 changes: 123 additions & 0 deletions src/Common/tst/units/ChunkIt.unit.cpp
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);
}
}
Loading

0 comments on commit cfe0782

Please sign in to comment.