diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2019-07-09 23:07:23 +0530 |
---|---|---|
committer | Dennis Francis <dennis.francis@collabora.com> | 2019-10-01 18:11:36 +0200 |
commit | 46d0afba738d8ee7c9b63384fef513f42ee587f3 (patch) | |
tree | bc4f6927f56974f6fc3cdb6224437e01a01e372c /comphelper | |
parent | 845e1cdca3349c72e3083186502285d5b776abbe (diff) |
Implement parallel version of super-scalar-sample-sort...
and use it for the pivot table construction routine processBuckets().
The implementation uses ideas from the non-parallel sample sort discussed in the below paper,
but parallelizes the "binning"/"classification" operations and the sorting of the bins
themselves.
Sanders, Peter, and Sebastian Winkel. "Super scalar sample sort."
European Symposium on Algorithms. Springer, Berlin, Heidelberg, 2004.
which can be accessed at :
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.366&rep=rep1&type=pdf
Change-Id: I3723b87e2feb8d7d9ee03f71f6025e26add914ce
Reviewed-on: https://gerrit.libreoffice.org/79486
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/CppunitTest_comphelper_parallelsort_test.mk | 30 | ||||
-rw-r--r-- | comphelper/Module_comphelper.mk | 1 | ||||
-rw-r--r-- | comphelper/qa/unit/parallelsorttest.cxx | 101 |
3 files changed, 132 insertions, 0 deletions
diff --git a/comphelper/CppunitTest_comphelper_parallelsort_test.mk b/comphelper/CppunitTest_comphelper_parallelsort_test.mk new file mode 100644 index 000000000000..e1d2eab9ec36 --- /dev/null +++ b/comphelper/CppunitTest_comphelper_parallelsort_test.mk @@ -0,0 +1,30 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_CppunitTest_CppunitTest,comphelper_parallelsort_test)) + +$(eval $(call gb_CppunitTest_add_exception_objects,comphelper_parallelsort_test, \ + comphelper/qa/unit/parallelsorttest \ +)) + +$(eval $(call gb_CppunitTest_use_externals,comphelper_parallelsort_test,\ + boost_headers \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,comphelper_parallelsort_test)) + +$(eval $(call gb_CppunitTest_use_libraries,comphelper_parallelsort_test, \ + comphelper \ + cppuhelper \ + cppu \ + sal \ + tl \ +)) + +# vim: set noet sw=4 ts=4:
\ No newline at end of file diff --git a/comphelper/Module_comphelper.mk b/comphelper/Module_comphelper.mk index 30ac708a927d..7541a59f1641 100644 --- a/comphelper/Module_comphelper.mk +++ b/comphelper/Module_comphelper.mk @@ -30,6 +30,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,comphelper,\ )) $(eval $(call gb_Module_add_check_targets,comphelper,\ + CppunitTest_comphelper_parallelsort_test \ CppunitTest_comphelper_threadpool_test \ CppunitTest_comphelper_syntaxhighlight_test \ CppunitTest_comphelper_variadictemplates_test \ diff --git a/comphelper/qa/unit/parallelsorttest.cxx b/comphelper/qa/unit/parallelsorttest.cxx new file mode 100644 index 000000000000..90dcb3c235ba --- /dev/null +++ b/comphelper/qa/unit/parallelsorttest.cxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <comphelper/parallelsort.hxx> +#include <comphelper/threadpool.hxx> +#include <rtl/string.hxx> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <cstdlib> +#include <vector> +#include <algorithm> +#include <random> + +class ParallelSortTest : public CppUnit::TestFixture +{ +public: + void testSortTiny(); + void testSortMedium(); + void testSortBig(); + + virtual void setUp() override; + virtual void tearDown() override; + + CPPUNIT_TEST_SUITE(ParallelSortTest); + CPPUNIT_TEST(testSortTiny); + CPPUNIT_TEST(testSortMedium); + CPPUNIT_TEST(testSortBig); + CPPUNIT_TEST_SUITE_END(); + +private: + void sortTest(size_t nLen); + void fillRandomUptoN(std::vector<size_t>& rVector, size_t N); + + comphelper::ThreadPool* pThreadPool; + size_t mnThreads; +}; + +void ParallelSortTest::setUp() +{ + pThreadPool = &comphelper::ThreadPool::getSharedOptimalPool(); + mnThreads = pThreadPool->getWorkerCount(); +} + +void ParallelSortTest::tearDown() +{ + if (pThreadPool) + pThreadPool->joinAll(); +} + +void ParallelSortTest::fillRandomUptoN(std::vector<size_t>& rVector, size_t N) +{ + rVector.resize(N); + for (size_t nIdx = 0; nIdx < N; ++nIdx) + rVector[nIdx] = nIdx; + std::shuffle(rVector.begin(), rVector.end(), std::default_random_engine(42)); +} + +void ParallelSortTest::sortTest(size_t nLen) +{ + std::vector<size_t> aVector(nLen); + fillRandomUptoN(aVector, nLen); + comphelper::parallelSort(aVector.begin(), aVector.end()); + for (size_t nIdx = 0; nIdx < nLen; ++nIdx) + { + OString aMsg = "Wrong aVector[" + OString::number(nIdx) + "]"; + CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsg.getStr(), nIdx, aVector[nIdx]); + } +} + +void ParallelSortTest::testSortTiny() +{ + sortTest(5); + sortTest(15); + sortTest(16); + sortTest(17); +} + +void ParallelSortTest::testSortMedium() +{ + sortTest(1025); + sortTest(1029); + sortTest(1024 * 2 + 1); + sortTest(1024 * 2 + 9); +} + +void ParallelSortTest::testSortBig() { sortTest(1024 * 16 + 3); } + +CPPUNIT_TEST_SUITE_REGISTRATION(ParallelSortTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |