Skip to content

Move test functions to the test modules in examples #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ Navigate to a source code folder.
e.g.
namespace nesterov_a_test_task_seq {

std::vector<int> getRandomVector(int sz);
class TestTaskSequential : public ppc::core::Task {
...
};
Expand Down
23 changes: 18 additions & 5 deletions tasks/mpi/example/func_tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@

#include <boost/mpi/communicator.hpp>
#include <boost/mpi/environment.hpp>
#include <random>
#include <vector>

#include "mpi/example/include/ops_mpi.hpp"

namespace {
std::vector<int> GetRandomVector(int sz) {
std::random_device dev;
std::mt19937 gen(dev());
std::vector<int> vec(sz);
for (int i = 0; i < sz; i++) {
vec[i] = gen() % 100 - 50;
}
return vec;
}
} // namespace

TEST(Parallel_Operations_MPI, Test_Sum) {
boost::mpi::communicator world;
std::vector<int> global_vec;
Expand All @@ -15,7 +28,7 @@ TEST(Parallel_Operations_MPI, Test_Sum) {

if (world.rank() == 0) {
const int count_size_vector = 120;
global_vec = nesterov_a_test_task_mpi::getRandomVector(count_size_vector);
global_vec = GetRandomVector(count_size_vector);
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(global_vec.data()));
taskDataPar->inputs_count.emplace_back(global_vec.size());
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_sum.data()));
Expand Down Expand Up @@ -59,7 +72,7 @@ TEST(Parallel_Operations_MPI, Test_Diff) {

if (world.rank() == 0) {
const int count_size_vector = 240;
global_vec = nesterov_a_test_task_mpi::getRandomVector(count_size_vector);
global_vec = GetRandomVector(count_size_vector);
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(global_vec.data()));
taskDataPar->inputs_count.emplace_back(global_vec.size());
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_diff.data()));
Expand Down Expand Up @@ -103,7 +116,7 @@ TEST(Parallel_Operations_MPI, Test_Diff_2) {

if (world.rank() == 0) {
const int count_size_vector = 120;
global_vec = nesterov_a_test_task_mpi::getRandomVector(count_size_vector);
global_vec = GetRandomVector(count_size_vector);
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(global_vec.data()));
taskDataPar->inputs_count.emplace_back(global_vec.size());
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_diff.data()));
Expand Down Expand Up @@ -147,7 +160,7 @@ TEST(Parallel_Operations_MPI, Test_Max) {

if (world.rank() == 0) {
const int count_size_vector = 240;
global_vec = nesterov_a_test_task_mpi::getRandomVector(count_size_vector);
global_vec = GetRandomVector(count_size_vector);
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(global_vec.data()));
taskDataPar->inputs_count.emplace_back(global_vec.size());
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_max.data()));
Expand Down Expand Up @@ -191,7 +204,7 @@ TEST(Parallel_Operations_MPI, Test_Max_2) {

if (world.rank() == 0) {
const int count_size_vector = 120;
global_vec = nesterov_a_test_task_mpi::getRandomVector(count_size_vector);
global_vec = GetRandomVector(count_size_vector);
taskDataPar->inputs.emplace_back(reinterpret_cast<uint8_t*>(global_vec.data()));
taskDataPar->inputs_count.emplace_back(global_vec.size());
taskDataPar->outputs.emplace_back(reinterpret_cast<uint8_t*>(global_max.data()));
Expand Down
2 changes: 0 additions & 2 deletions tasks/mpi/example/include/ops_mpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

namespace nesterov_a_test_task_mpi {

std::vector<int> getRandomVector(int sz);

class TestMPITaskSequential : public ppc::core::Task {
public:
explicit TestMPITaskSequential(ppc::core::TaskDataPtr taskData_, std::string ops_)
Expand Down
12 changes: 0 additions & 12 deletions tasks/mpi/example/src/ops_mpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
#include <thread>
#include <vector>

using namespace std::chrono_literals;

std::vector<int> nesterov_a_test_task_mpi::getRandomVector(int sz) {
std::random_device dev;
std::mt19937 gen(dev());
std::vector<int> vec(sz);
for (int i = 0; i < sz; i++) {
vec[i] = gen() % 100;
}
return vec;
}

bool nesterov_a_test_task_mpi::TestMPITaskSequential::pre_processing_impl() {
// Init vectors
input_ = std::vector<int>(taskData->inputs_count[0]);
Expand Down
23 changes: 18 additions & 5 deletions tasks/omp/example/func_tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#include <gtest/gtest.h>

#include <random>
#include <vector>

#include "omp/example/include/ops_omp.hpp"

namespace {
std::vector<int> GetRandomVector(int sz) {
std::random_device dev;
std::mt19937 gen(dev());
std::vector<int> vec(sz);
for (int i = 0; i < sz; i++) {
vec[i] = gen() % 100 - 50;
}
return vec;
}
} // namespace

TEST(Parallel_Operations_OpenMP, Test_Sum) {
std::vector<int> vec = nesterov_a_test_task_omp::getRandomVector(100);
std::vector<int> vec = GetRandomVector(100);
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -44,7 +57,7 @@ TEST(Parallel_Operations_OpenMP, Test_Sum) {
}

TEST(Parallel_Operations_OpenMP, Test_Diff) {
std::vector<int> vec = nesterov_a_test_task_omp::getRandomVector(100);
std::vector<int> vec = GetRandomVector(100);
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -82,7 +95,7 @@ TEST(Parallel_Operations_OpenMP, Test_Diff) {
}

TEST(Parallel_Operations_OpenMP, Test_Diff_2) {
std::vector<int> vec = nesterov_a_test_task_omp::getRandomVector(10);
std::vector<int> vec = GetRandomVector(10);
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -120,7 +133,7 @@ TEST(Parallel_Operations_OpenMP, Test_Diff_2) {
}

TEST(Parallel_Operations_OpenMP, Test_Mult) {
std::vector<int> vec = nesterov_a_test_task_omp::getRandomVector(10);
std::vector<int> vec = GetRandomVector(10);
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -158,7 +171,7 @@ TEST(Parallel_Operations_OpenMP, Test_Mult) {
}

TEST(Parallel_Operations_OpenMP, Test_Mult_2) {
std::vector<int> vec = nesterov_a_test_task_omp::getRandomVector(5);
std::vector<int> vec = GetRandomVector(5);
// Create data
std::vector<int> ref_res(1, 0);

Expand Down
2 changes: 0 additions & 2 deletions tasks/omp/example/include/ops_omp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace nesterov_a_test_task_omp {

std::vector<int> getRandomVector(int sz);

class TestOMPTaskSequential : public ppc::core::Task {
public:
explicit TestOMPTaskSequential(ppc::core::TaskDataPtr taskData_, std::string ops_)
Expand Down
13 changes: 0 additions & 13 deletions tasks/omp/example/src/ops_omp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,10 @@

#include <iostream>
#include <numeric>
#include <random>
#include <string>
#include <thread>
#include <vector>

using namespace std::chrono_literals;

std::vector<int> nesterov_a_test_task_omp::getRandomVector(int sz) {
std::random_device dev;
std::mt19937 gen(dev());
std::vector<int> vec(sz);
for (int i = 0; i < sz; i++) {
vec[i] = gen() % 100 + 1;
}
return vec;
}

bool nesterov_a_test_task_omp::TestOMPTaskSequential::pre_processing_impl() {
// Init vectors
input_ = std::vector<int>(taskData->inputs_count[0]);
Expand Down
2 changes: 0 additions & 2 deletions tasks/seq/example/src/ops_seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <thread>

using namespace std::chrono_literals;

bool nesterov_a_test_task_seq::TestTaskSequential::pre_processing_impl() {
// Init value for input and output
input_ = reinterpret_cast<int*>(taskData->inputs[0])[0];
Expand Down
23 changes: 18 additions & 5 deletions tasks/stl/example/func_tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
#include <gtest/gtest.h>

#include <random>
#include <thread>
#include <vector>

#include "stl/example/include/ops_stl.hpp"

namespace {
std::vector<int> GetRandomVector(int sz) {
std::random_device dev;
std::mt19937 gen(dev());
std::vector<int> vec(sz);
for (int i = 0; i < sz; i++) {
vec[i] = gen() % 100 - 50;
}
return vec;
}
} // namespace

TEST(Parallel_Operations_STL_Threads, Test_Sum) {
auto nthreads = std::thread::hardware_concurrency() * 10;
std::vector<int> vec = nesterov_a_test_task_stl::getRandomVector(static_cast<int>(nthreads));
std::vector<int> vec = GetRandomVector(static_cast<int>(nthreads));
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -46,7 +59,7 @@ TEST(Parallel_Operations_STL_Threads, Test_Sum) {

TEST(Parallel_Operations_STL_Threads, Test_Sum_2) {
auto nthreads = std::thread::hardware_concurrency() * 11;
std::vector<int> vec = nesterov_a_test_task_stl::getRandomVector(static_cast<int>(nthreads));
std::vector<int> vec = GetRandomVector(static_cast<int>(nthreads));
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -85,7 +98,7 @@ TEST(Parallel_Operations_STL_Threads, Test_Sum_2) {

TEST(Parallel_Operations_STL_Threads, Test_Sum_3) {
auto nthreads = std::thread::hardware_concurrency() * 13;
std::vector<int> vec = nesterov_a_test_task_stl::getRandomVector(static_cast<int>(nthreads));
std::vector<int> vec = GetRandomVector(static_cast<int>(nthreads));
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -124,7 +137,7 @@ TEST(Parallel_Operations_STL_Threads, Test_Sum_3) {

TEST(Parallel_Operations_STL_Threads, Test_Diff) {
auto nthreads = std::thread::hardware_concurrency() * 14;
std::vector<int> vec = nesterov_a_test_task_stl::getRandomVector(static_cast<int>(nthreads));
std::vector<int> vec = GetRandomVector(static_cast<int>(nthreads));
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -163,7 +176,7 @@ TEST(Parallel_Operations_STL_Threads, Test_Diff) {

TEST(Parallel_Operations_STL_Threads, Test_Diff_2) {
auto nthreads = std::thread::hardware_concurrency() * 15;
std::vector<int> vec = nesterov_a_test_task_stl::getRandomVector(static_cast<int>(nthreads));
std::vector<int> vec = GetRandomVector(static_cast<int>(nthreads));
// Create data
std::vector<int> ref_res(1, 0);

Expand Down
2 changes: 0 additions & 2 deletions tasks/stl/example/include/ops_stl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace nesterov_a_test_task_stl {

std::vector<int> getRandomVector(int sz);

class TestSTLTaskSequential : public ppc::core::Task {
public:
explicit TestSTLTaskSequential(ppc::core::TaskDataPtr taskData_, std::string ops_)
Expand Down
13 changes: 0 additions & 13 deletions tasks/stl/example/src/ops_stl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,11 @@
#include <future>
#include <iostream>
#include <numeric>
#include <random>
#include <string>
#include <thread>
#include <utility>
#include <vector>

using namespace std::chrono_literals;

std::vector<int> nesterov_a_test_task_stl::getRandomVector(int sz) {
std::random_device dev;
std::mt19937 gen(dev());
std::vector<int> vec(sz);
for (int i = 0; i < sz; i++) {
vec[i] = static_cast<int>(gen()) % 100;
}
return vec;
}

bool nesterov_a_test_task_stl::TestSTLTaskSequential::pre_processing_impl() {
// Init vectors
input_ = std::vector<int>(taskData->inputs_count[0]);
Expand Down
23 changes: 18 additions & 5 deletions tasks/tbb/example/func_tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#include <gtest/gtest.h>

#include <random>
#include <vector>

#include "tbb/example/include/ops_tbb.hpp"

namespace {
std::vector<int> GetRandomVector(int sz) {
std::random_device dev;
std::mt19937 gen(dev());
std::vector<int> vec(sz);
for (int i = 0; i < sz; i++) {
vec[i] = gen() % 100 - 50;
}
return vec;
}
} // namespace

TEST(Parallel_Operations_TBB, Test_Sum) {
std::vector<int> vec = nesterov_a_test_task_tbb::getRandomVector(100);
std::vector<int> vec = GetRandomVector(100);
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -43,7 +56,7 @@ TEST(Parallel_Operations_TBB, Test_Sum) {
}

TEST(Parallel_Operations_TBB, Test_Diff) {
std::vector<int> vec = nesterov_a_test_task_tbb::getRandomVector(100);
std::vector<int> vec = GetRandomVector(100);
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -81,7 +94,7 @@ TEST(Parallel_Operations_TBB, Test_Diff) {
}

TEST(Parallel_Operations_TBB, Test_Diff_2) {
std::vector<int> vec = nesterov_a_test_task_tbb::getRandomVector(50);
std::vector<int> vec = GetRandomVector(50);
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -119,7 +132,7 @@ TEST(Parallel_Operations_TBB, Test_Diff_2) {
}

TEST(Parallel_Operations_TBB, Test_Mult) {
std::vector<int> vec = nesterov_a_test_task_tbb::getRandomVector(10);
std::vector<int> vec = GetRandomVector(10);
// Create data
std::vector<int> ref_res(1, 0);

Expand Down Expand Up @@ -157,7 +170,7 @@ TEST(Parallel_Operations_TBB, Test_Mult) {
}

TEST(Parallel_Operations_TBB, Test_Mult_2) {
std::vector<int> vec = nesterov_a_test_task_tbb::getRandomVector(5);
std::vector<int> vec = GetRandomVector(5);
// Create data
std::vector<int> ref_res(1, 0);

Expand Down
2 changes: 0 additions & 2 deletions tasks/tbb/example/include/ops_tbb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace nesterov_a_test_task_tbb {

std::vector<int> getRandomVector(int sz);

class TestTBBTaskSequential : public ppc::core::Task {
public:
explicit TestTBBTaskSequential(ppc::core::TaskDataPtr taskData_, std::string ops_)
Expand Down
12 changes: 0 additions & 12 deletions tasks/tbb/example/src/ops_tbb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@
#include <thread>
#include <vector>

using namespace std::chrono_literals;

std::vector<int> nesterov_a_test_task_tbb::getRandomVector(int sz) {
std::random_device dev;
std::mt19937 gen(dev());
std::vector<int> vec(sz);
for (int i = 0; i < sz; i++) {
vec[i] = gen() % 20 + 1;
}
return vec;
}

bool nesterov_a_test_task_tbb::TestTBBTaskSequential::pre_processing_impl() {
// Init vectors
input_ = std::vector<int>(taskData->inputs_count[0]);
Expand Down
Loading