Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimbelan authored Jun 4, 2024
1 parent 6aaab6e commit e593626
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
33 changes: 14 additions & 19 deletions tasks/tbb/belan_vadim_mat_fox_tbb/func_tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ TEST(FoxBlockedParallel, MatrixMultiplication2x2) {

// Create Task
FoxBlockedParallel foxBlockedParallel(taskData);
foxBlockedParallel.validation();
foxBlockedParallel.pre_processing();
auto *output = reinterpret_cast<double *>(taskData->outputs[0]);
foxBlockedParallel.run();
foxBlockedParallel.post_processing();

// Get the output
auto *output = reinterpret_cast<double *>(taskData->outputs[0]);

// Check the output
for (size_t i = 0; i < 4; ++i) {
ASSERT_DOUBLE_EQ(output[i], expectedOutput[i]);
Expand Down Expand Up @@ -63,13 +62,12 @@ TEST(FoxBlockedParallel, MatrixMultiplication) {

// Create Task
FoxBlockedParallel foxBlockedParallel(taskData);
foxBlockedParallel.validation();
foxBlockedParallel.pre_processing();
auto *output = reinterpret_cast<double *>(taskData->outputs[0]);
foxBlockedParallel.run();
foxBlockedParallel.post_processing();

// Get the output
auto *output = reinterpret_cast<double *>(taskData->outputs[0]);

// Check the output
for (size_t i = 0; i < 9; ++i) {
ASSERT_DOUBLE_EQ(output[i], expectedOutput[i]);
Expand Down Expand Up @@ -114,13 +112,12 @@ TEST(FoxBlockedParallel, MatrixMultiplication_SmallMatrices) {

// Create Task
FoxBlockedParallel foxBlockedParallel(taskData);
foxBlockedParallel.validation();
foxBlockedParallel.pre_processing();
auto *output = reinterpret_cast<double *>(taskData->outputs[0]);
foxBlockedParallel.run();
foxBlockedParallel.post_processing();

// Get the output
auto *output = reinterpret_cast<double *>(taskData->outputs[0]);

// Check the output
for (size_t i = 0; i < 10 * 10; ++i) {
ASSERT_DOUBLE_EQ(output[i], expectedOutput[i]);
Expand Down Expand Up @@ -150,13 +147,12 @@ TEST(FoxBlockedParallel, MatrixMultiplication_VerySmallMatrices) {

// Create Task
FoxBlockedParallel foxBlockedParallel(taskData);
foxBlockedParallel.validation();
foxBlockedParallel.pre_processing();
auto *output = reinterpret_cast<double *>(taskData->outputs[0]);
foxBlockedParallel.run();
foxBlockedParallel.post_processing();

// Get the output
auto *output = reinterpret_cast<double *>(taskData->outputs[0]);

// Check the output
for (size_t i = 0; i < 4; ++i) {
ASSERT_DOUBLE_EQ(output[i], expectedOutput[i]);
Expand All @@ -173,31 +169,30 @@ TEST(FoxBlockedParallel, MatrixMultiplicationWithNegatives) {
std::vector<double> expectedOutput = {30, 24, 18, 84, 69, 54, 138, 114, 90};

// Create TaskData
std::shared_ptrppc::core::TaskData taskData = std::make_sharedppc::core::TaskData();
std::shared_ptr<ppc::core::TaskData> taskData = std::make_shared<ppc::core::TaskData>();
taskData->inputs.emplace_back(reinterpret_cast<uint8_t *>(matrixA.data()));
taskData->inputs_count.emplace_back(3);
taskData->inputs_count.emplace_back(3);
taskData->inputs.emplace_back(reinterpret_cast<uint8_t *>(matrixB.data()));
taskData->inputs_count.emplace_back(3);
taskData->inputs_count.emplace_back(3);
taskData->outputs.emplace_back(reinterpret_cast<uint8_t *>(new double9));
taskData->outputs.emplace_back(reinterpret_cast<uint8_t *>(new double[9]()));
taskData->outputs_count.emplace_back(3);
taskData->outputs_count.emplace_back(3);

// Create Task
FoxBlockedParallel foxBlockedParallel(taskData);
foxBlockedParallel.validation();
foxBlockedParallel.pre_processing();
auto *output = reinterpret_cast<double *>(taskData->outputs[0]);
foxBlockedParallel.run();
foxBlockedParallel.post_processing();

// Get the output
auto *output = reinterpret_cast<double *>(taskData->outputs[0]);

// Check the output
for (size_t i = 0; i < 9; ++i) {
ASSERT_DOUBLE_EQ(output[i], expectedOutput[i]);
}

// Free memory
delete[] output;
}
}
2 changes: 1 addition & 1 deletion tasks/tbb/belan_vadim_mat_fox_tbb/include/ops_tbb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <vector>

#include "core/task/include/task.hpp"
#include "tbb/tbb.h"
#include <tbb/tbb.h>

namespace BelanTBB {

Expand Down
7 changes: 3 additions & 4 deletions tasks/tbb/belan_vadim_mat_fox_tbb/src/ops_tbb.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Copyright 2024 Vadim Belan
#include "tbb/belan_vadim_mat_fox_tbb/include/ops_tbb.hpp"

Expand Down Expand Up @@ -107,11 +106,11 @@ bool FoxBlockedParallel::pre_processing() {
bool FoxBlockedParallel::run() {
internal_order_test();

tbb::parallel_for(0u, static_cast<unsigned int>(A.size()), [&](unsigned int ii) {
tbb::parallel_for(0, static_cast<int>(A.size()), block_size, [&](int ii) {
for (std::vector<double>::size_type jj = 0; jj < B[0].size();
jj += static_cast<std::vector<double>::size_type>(block_size)) {
for (std::vector<double>::size_type k = 0; k < A[0].size(); ++k) {
for (unsigned int i = ii; i < std::min(ii + static_cast<decltype(ii)>(block_size), static_cast<decltype(ii)>(A.size())); ++i) {
for (int i = ii; i < std::min(ii + block_size, static_cast<int>(A.size())); ++i) {
for (std::vector<double>::size_type j = jj;
j < std::min(jj + static_cast<std::vector<double>::size_type>(block_size), B[0].size()); ++j) {
C[i][j] += A[i][k] * B[k][j];
Expand All @@ -136,4 +135,4 @@ bool FoxBlockedParallel::post_processing() {
}

return true;
}
}

0 comments on commit e593626

Please sign in to comment.