Skip to content

Commit

Permalink
some sequential fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ascannel committed Oct 23, 2024
1 parent 470ba7e commit eb96a84
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 66 deletions.
1 change: 0 additions & 1 deletion tasks/mpi/lopatin_i_count_words/src/countWordsMPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ bool TestMPITaskSequential::validation() {

bool TestMPITaskSequential::run() {
internal_order_test();
wordCount = 0;
bool inWord = false;
for (char c : input_) {
if (c == ' ' || c == '\n') {
Expand Down
52 changes: 7 additions & 45 deletions tasks/seq/lopatin_i_count_words/func_tests/countWordsFuncTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,8 @@

#include "seq/lopatin_i_count_words/include/countWordsSeqHeader.hpp"

TEST(lopatin_i_count_words_seq, test_empty_string) {
std::string input;
std::vector<int> out(1, 0);

std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>();
taskData->inputs.emplace_back(reinterpret_cast<uint8_t *>(input.data()));
taskData->inputs_count.emplace_back(input.size());
taskData->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
taskData->outputs_count.emplace_back(out.size());

lopatin_i_count_words_seq::TestTaskSequential testTask(taskData);
ASSERT_EQ(testTask.validation(), false);
testTask.pre_processing();
testTask.run();
testTask.post_processing();

ASSERT_EQ(out[0], 0);
}

TEST(lopatin_i_count_words_seq, test_single_word) {
std::string input = "Hello";
std::vector<int> out(1, 0);

std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>();
taskData->inputs.emplace_back(reinterpret_cast<uint8_t *>(input.data()));
taskData->inputs_count.emplace_back(input.size());
taskData->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
taskData->outputs_count.emplace_back(out.size());

lopatin_i_count_words_seq::TestTaskSequential testTask(taskData);
ASSERT_EQ(testTask.validation(), true);
testTask.pre_processing();
testTask.run();
testTask.post_processing();

ASSERT_EQ(out[0], 1);
}

TEST(lopatin_i_count_words_seq, test_5_words) {
std::string input = "This is a test sentence";
TEST(lopatin_i_count_words_seq, test_300_words) {
std::vector<char> input = lopatin_i_count_words_seq::generateLongString(20);
std::vector<int> out(1, 0);

std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>();
Expand All @@ -56,11 +18,11 @@ TEST(lopatin_i_count_words_seq, test_5_words) {
testTask.run();
testTask.post_processing();

ASSERT_EQ(out[0], 5);
ASSERT_EQ(out[0], 300);
}

TEST(lopatin_i_count_words_seq, test_1500_words) {
std::string input = lopatin_i_count_words_seq::generateLongString(100);
std::vector<char> input = lopatin_i_count_words_seq::generateLongString(100);
std::vector<int> out(1, 0);

std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>();
Expand All @@ -78,8 +40,8 @@ TEST(lopatin_i_count_words_seq, test_1500_words) {
ASSERT_EQ(out[0], 1500);
}

TEST(lopatin_i_count_words_seq, test_15k_words) {
std::string input = lopatin_i_count_words_seq::generateLongString(1000);
TEST(lopatin_i_count_words_seq, test_6k_words) {
std::vector<char> input = lopatin_i_count_words_seq::generateLongString(400);
std::vector<int> out(1, 0);

std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>();
Expand All @@ -94,5 +56,5 @@ TEST(lopatin_i_count_words_seq, test_15k_words) {
testTask.run();
testTask.post_processing();

ASSERT_EQ(out[0], 15000);
ASSERT_EQ(out[0], 6000);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#include "core/task/include/task.hpp"

namespace lopatin_i_count_words_seq {

int countWords(const std::string& str);
std::string generateLongString(int n);
std::vector<char> generateLongString(int n);

class TestTaskSequential : public ppc::core::Task {
public:
Expand All @@ -21,7 +19,7 @@ class TestTaskSequential : public ppc::core::Task {
bool post_processing() override;

private:
std::string input_;
std::vector<char> input_;
int wordCount{};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include "core/perf/include/perf.hpp"
#include "seq/lopatin_i_count_words/include/countWordsSeqHeader.hpp"

std::string testData = lopatin_i_count_words_seq::generateLongString(1000);
std::vector<char> testData = lopatin_i_count_words_seq::generateLongString(1000);

TEST(word_count_seq, test_pipeline_run) {
std::string input = testData;
std::vector<char> input = testData;
std::vector<int> word_count(1, 0);

std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>();
Expand Down Expand Up @@ -36,7 +36,7 @@ TEST(word_count_seq, test_pipeline_run) {
}

TEST(word_count_seq, test_task_run) {
std::string input = testData;
std::vector<char> input = testData;
std::vector<int> word_count(1, 0);

std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>();
Expand Down
32 changes: 19 additions & 13 deletions tasks/seq/lopatin_i_count_words/src/countWordsSeq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,44 @@

namespace lopatin_i_count_words_seq {

int countWords(const std::string& str) {
std::istringstream iss(str);
return std::distance(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>());
}

std::string generateLongString(int n) {
std::string testData;
std::vector<char> generateLongString(int n) {
std::vector<char> testData;
std::string testString = "This is a long sentence for performance testing of the word count algorithm using MPI. ";
for (int i = 0; i < n; i++) {
testData += testString;
for (unsigned long int j = 0; j < testString.length(); j++) {
testData.push_back(testString[j]);
}
}
return testData;
}

bool lopatin_i_count_words_seq::TestTaskSequential::pre_processing() {
internal_order_test();
// Init string
input_ = std::string(reinterpret_cast<char*>(taskData->inputs[0]), taskData->inputs_count[0]);
// Init value for output
input_ = std::vector<char>(taskData->inputs_count[0]);
auto* tempPtr = reinterpret_cast<char*>(taskData->inputs[0]);
for (unsigned i = 0; i < taskData->inputs_count[0]; i++) {
input_[i] = tempPtr[i];
}
wordCount = 0;
return true;
}

bool lopatin_i_count_words_seq::TestTaskSequential::validation() {
internal_order_test();
// Check if inout is not empty and output is prepared
return taskData->inputs_count[0] > 0 && taskData->outputs_count[0] == 1;
}

bool lopatin_i_count_words_seq::TestTaskSequential::run() {
internal_order_test();
wordCount = countWords(input_);
bool inWord = false;
for (char c : input_) {
if (c == ' ' || c == '\n') {
inWord = false;
} else if (!inWord) {
wordCount++;
inWord = true;
}
}
return true;
}

Expand Down

0 comments on commit eb96a84

Please sign in to comment.