Skip to content

Commit

Permalink
Few small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
martun committed Jan 25, 2024
1 parent 488fdf0 commit a5a65ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
4 changes: 0 additions & 4 deletions include/nil/crypto3/math/multithreading/thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ namespace nil {
std::size_t cpu_usage = std::min(elements_count, pool_size);
std::size_t element_per_cpu = elements_count / cpu_usage;

std::cout << "cpu_usage = " << cpu_usage << std::endl;
std::cout << "pool_size = " << pool_size << std::endl;
std::cout << "element_per_cpu = " << element_per_cpu << std::endl;

for (int i = 0; i < cpu_usage; i++) {
auto begin = element_per_cpu * i;
auto end = (i == cpu_usage - 1) ? elements_count : element_per_cpu * (i + 1);
Expand Down
28 changes: 19 additions & 9 deletions include/nil/crypto3/math/polynomial/polynomial_dfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ namespace nil {
wait_for_all(ThreadPool::get_instance().block_execution<void>(
result.size(),
[&result, &tmp](std::size_t begin, std::size_t end) {
std::cout << "Adding range " << begin << " " << end << std::endl;
for (std::size_t i = begin; i < end; i++) {
result[i] += tmp[i];
}
Expand All @@ -451,7 +450,6 @@ std::cout << "Adding range " << begin << " " << end << std::endl;
wait_for_all(ThreadPool::get_instance().block_execution<void>(
result.size(),
[&result, &other](std::size_t begin, std::size_t end) {
std::cout << "Adding range " << begin << " " << end << std::endl;
for (std::size_t i = begin; i < end; i++) {
result[i] += other[i];
}
Expand All @@ -476,8 +474,7 @@ std::cout << "Adding range " << begin << " " << end << std::endl;

wait_for_all(ThreadPool::get_instance().block_execution<void>(
this->size(),
[&result, &tmp](std::size_t begin, std::size_t end) {
std::cout << "Adding range " << begin << " " << end << std::endl;
[this, &tmp](std::size_t begin, std::size_t end) {
for (std::size_t i = begin; i < end; i++) {
(*this)[i] += tmp[i];
}
Expand All @@ -487,8 +484,7 @@ std::cout << "Adding range " << begin << " " << end << std::endl;

wait_for_all(ThreadPool::get_instance().block_execution<void>(
this->size(),
[&result, &tmp](std::size_t begin, std::size_t end) {
std::cout << "Adding range " << begin << " " << end << std::endl;
[this, &other](std::size_t begin, std::size_t end) {
for (std::size_t i = begin; i < end; i++) {
(*this)[i] += other[i];
}
Expand Down Expand Up @@ -600,10 +596,11 @@ std::cout << "Adding range " << begin << " " << end << std::endl;
wait_for_all(ThreadPool::get_instance().block_execution<void>(
result.size(),
[&result, &other](std::size_t begin, std::size_t end) {
std::cout << "Multiplying range " << begin << " " << end << std::endl;
//std::cout << "Multiplying range " << begin << " " << end << std::endl;
for (std::size_t i = begin; i < end; i++) {
result[i] *= other[i];
}
//std::cout << "Done Multiplying range " << begin << " " << end << std::endl;
}));

return result;
Expand All @@ -629,10 +626,23 @@ std::cout << "Multiplying range " << begin << " " << end << std::endl;
polynomial_dfs tmp(other);
tmp.resize(polynomial_s);

std::transform(tmp.begin(), tmp.end(), this->begin(), this->begin(), std::multiplies<FieldValueType>());
wait_for_all(ThreadPool::get_instance().block_execution<void>(
this->size(),
[this, &tmp](std::size_t begin, std::size_t end) {
for (std::size_t i = begin; i < end; i++) {
(*this)[i] *= tmp[i];
}
}));
return *this;
}
std::transform(this->begin(), this->end(), other.begin(), this->begin(), std::multiplies<FieldValueType>());
wait_for_all(ThreadPool::get_instance().block_execution<void>(
this->size(),
[this, &other](std::size_t begin, std::size_t end) {
for (std::size_t i = begin; i < end; i++) {
(*this)[i] *= other[i];
}
}));

return *this;
}

Expand Down
24 changes: 9 additions & 15 deletions test/polynomial_dfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,26 +1310,19 @@ BOOST_AUTO_TEST_CASE(polynomial_dfs_addition_perf_test) {
}

BOOST_AUTO_TEST_CASE(polynomial_dfs_multiplication_perf_test) {
nil::crypto3::ThreadPool::start(16);
nil::crypto3::ThreadPool::start(8);

std::vector<typename FieldType::value_type> values;
size_t size = 131072 * 16;
for (int i = 0; i < size; i++) {
values.push_back(nil::crypto3::algebra::random_element<FieldType>());
}
size_t size = 131072 * 32;

polynomial_dfs<typename FieldType::value_type> poly = {
size - 1, values};

polynomial_dfs<typename FieldType::value_type> poly2 = {
size - 1, values};
size / 4096, size, nil::crypto3::algebra::random_element<FieldType>()};

poly.resize(2 * size);
polynomial_dfs<typename FieldType::value_type> poly4 = poly;

for (int i = 0; i < 100; ++i) {
poly2 = poly2 + poly * poly;
poly4 *= poly;
}
BOOST_CHECK(poly2 != poly);
BOOST_CHECK(poly4 != poly);
}

BOOST_AUTO_TEST_CASE(polynomial_dfs_resize_perf_test) {
Expand All @@ -1350,8 +1343,9 @@ BOOST_AUTO_TEST_CASE(polynomial_dfs_resize_perf_test) {
BOOST_AUTO_TEST_CASE(vector_mult_test) {
nil::crypto3::ThreadPool::start(8);

std::vector<int> result(100000000);
std::vector<int> other(result.size());
size_t size = 131072 * 16 * 16;
std::vector<int> result(size);
std::vector<int> other(size);
for (int i = 0; i < result.size(); ++i) {
result[i] = rand();
other[i] = rand();
Expand Down

0 comments on commit a5a65ea

Please sign in to comment.