[mathicgb] 114/393: Since tbb uses a global object to set the number of threads there is no longer a purpose of passing threadCount parameters around everywhere. Those are all removed now.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:58:43 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch upstream
in repository mathicgb.
commit 6a535fb74a23c9ad9841ededc819ea052a341946
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date: Fri Nov 16 14:27:45 2012 +0100
Since tbb uses a global object to set the number of threads there is no longer a purpose of passing threadCount parameters around everywhere. Those are all removed now.
---
src/mathicgb/BuchbergerAlg.cpp | 2 --
src/mathicgb/BuchbergerAlg.hpp | 5 -----
src/mathicgb/F4MatrixBuilder.cpp | 7 +------
src/mathicgb/F4MatrixBuilder.hpp | 4 +---
src/mathicgb/F4MatrixReducer.cpp | 18 ++++++------------
src/mathicgb/F4MatrixReducer.hpp | 3 +--
src/mathicgb/F4Reducer.cpp | 14 +++++---------
src/mathicgb/F4Reducer.hpp | 4 +---
src/mathicgb/QuadMatrix.cpp | 2 +-
src/mathicgb/QuadMatrix.hpp | 5 ++---
src/mathicgb/Reducer.hpp | 4 ----
src/mathicgb/TypicalReducer.cpp | 4 ----
src/mathicgb/TypicalReducer.hpp | 2 --
src/test/F4MatrixBuilder.cpp | 20 +++++++++++---------
src/test/F4MatrixReducer.cpp | 2 +-
src/test/QuadMatrixBuilder.cpp | 6 +++---
src/test/gb-test.cpp | 3 ++-
17 files changed, 35 insertions(+), 70 deletions(-)
diff --git a/src/mathicgb/BuchbergerAlg.cpp b/src/mathicgb/BuchbergerAlg.cpp
index 1675bd6..32e45c6 100755
--- a/src/mathicgb/BuchbergerAlg.cpp
+++ b/src/mathicgb/BuchbergerAlg.cpp
@@ -15,7 +15,6 @@ BuchbergerAlg::BuchbergerAlg(
mBreakAfter(0),
mPrintInterval(0),
mSPairGroupSize(0),
- mThreadCount(0),
mUseAutoTopReduction(true),
mUseAutoTailReduction(false),
mRing(*ideal.getPolyRing()),
@@ -187,7 +186,6 @@ void BuchbergerAlg::insertReducedPoly(
}
void BuchbergerAlg::computeGrobnerBasis() {
- mReducer->setThreadCount(mThreadCount);
size_t counter = 0;
mTimer.reset();
mRing.resetCoefficientStats();
diff --git a/src/mathicgb/BuchbergerAlg.hpp b/src/mathicgb/BuchbergerAlg.hpp
index 583c67d..91cce45 100755
--- a/src/mathicgb/BuchbergerAlg.hpp
+++ b/src/mathicgb/BuchbergerAlg.hpp
@@ -50,10 +50,6 @@ public:
mSPairGroupSize = groupSize;
}
- void setThreadCount(int threadCount) {
- mThreadCount = threadCount;
- }
-
void setReducerMemoryQuantum(size_t memoryQuantum) {
mReducer->setMemoryQuantum(memoryQuantum);
}
@@ -70,7 +66,6 @@ private:
unsigned int mBreakAfter;
unsigned int mPrintInterval;
unsigned int mSPairGroupSize;
- int mThreadCount;
bool mUseAutoTopReduction;
bool mUseAutoTailReduction;
diff --git a/src/mathicgb/F4MatrixBuilder.cpp b/src/mathicgb/F4MatrixBuilder.cpp
index 6647d33..88a9ef9 100755
--- a/src/mathicgb/F4MatrixBuilder.cpp
+++ b/src/mathicgb/F4MatrixBuilder.cpp
@@ -47,10 +47,8 @@ void F4MatrixBuilder::createTwoColumns(
F4MatrixBuilder::F4MatrixBuilder(
const PolyBasis& basis,
- const int threadCount,
const size_t memoryQuantum
):
- mThreadCount(threadCount),
mTmp(basis.ring().allocMonomial()),
mBasis(basis),
mMap(basis.ring()),
@@ -60,8 +58,6 @@ F4MatrixBuilder::F4MatrixBuilder(
mLeftColCount(0),
mRightColCount(0)
{
- MATHICGB_ASSERT(threadCount >= 1);
-
// This assert to be _NO_ASSUME since otherwise the compiler will assume that
// the error checking branch here cannot be taken and optimize it away.
const Scalar maxScalar = std::numeric_limits<Scalar>::max();
@@ -131,7 +127,6 @@ void F4MatrixBuilder::buildMatrixAndClear(QuadMatrix& matrix) {
monomial tmp2;
};
- MATHICGB_ASSERT(mThreadCount >= 1);
tbb::enumerable_thread_specific<ThreadData> threadData([&](){
ThreadData data = {QuadMatrixBuilder(
ring(), mMap, mMonomialsLeft, mMonomialsRight, mBuilder.memoryQuantum()
@@ -221,7 +216,7 @@ void F4MatrixBuilder::buildMatrixAndClear(QuadMatrix& matrix) {
}
}
#endif
- matrix.sortColumnsLeftRightParallel(mThreadCount);
+ matrix.sortColumnsLeftRightParallel();
mMap.clearNonConcurrent();
}
diff --git a/src/mathicgb/F4MatrixBuilder.hpp b/src/mathicgb/F4MatrixBuilder.hpp
index 6a40216..f2db0eb 100755
--- a/src/mathicgb/F4MatrixBuilder.hpp
+++ b/src/mathicgb/F4MatrixBuilder.hpp
@@ -28,8 +28,7 @@ public:
/// memoryQuantum is how much to increase the memory size by each time the
/// current amount of memory is exhausted. A value of 0 indicates to start
/// small and double the quantum at each exhaustion.
- F4MatrixBuilder
- (const PolyBasis& basis, int threadCount, size_t memoryQuantum = 0);
+ F4MatrixBuilder(const PolyBasis& basis, size_t memoryQuantum = 0);
/** Schedules a row representing the S-polynomial between polyA and
polyB to be added to the matrix. No ownership is taken, but polyA
@@ -147,7 +146,6 @@ private:
ColIndex mLeftColCount;
ColIndex mRightColCount;
monomial mTmp;
- const int mThreadCount;
const PolyBasis& mBasis;
Monomials mMonomialsLeft;
Monomials mMonomialsRight;
diff --git a/src/mathicgb/F4MatrixReducer.cpp b/src/mathicgb/F4MatrixReducer.cpp
index a691a42..a8a37a4 100755
--- a/src/mathicgb/F4MatrixReducer.cpp
+++ b/src/mathicgb/F4MatrixReducer.cpp
@@ -125,8 +125,7 @@ namespace {
SparseMatrix reduce(
const QuadMatrix& qm,
- SparseMatrix::Scalar modulus,
- const int threadCount
+ SparseMatrix::Scalar modulus
) {
const SparseMatrix& toReduceLeft = qm.bottomLeft;
const SparseMatrix& toReduceRight = qm.bottomRight;
@@ -245,8 +244,7 @@ namespace {
void reduceToEchelonForm(
SparseMatrix& toReduce,
const SparseMatrix::ColIndex colCount,
- const SparseMatrix::Scalar modulus,
- int threadCount
+ const SparseMatrix::Scalar modulus
) {
// making no assumptions on toReduce except no zero rows
@@ -371,15 +369,14 @@ namespace {
}
SparseMatrix F4MatrixReducer::reduce(const QuadMatrix& matrix) {
- MATHICGB_ASSERT(mThreadCount >= 1);
MATHICGB_ASSERT(matrix.debugAssertValid());
if (tracingLevel >= 3)
matrix.printSizes(std::cerr);
const auto rightColCount =
static_cast<SparseMatrix::ColIndex>(matrix.rightColumnMonomials.size());
- SparseMatrix newPivots(::reduce(matrix, mModulus, mThreadCount));
- ::reduceToEchelonForm(newPivots, rightColCount, mModulus, mThreadCount);
+ SparseMatrix newPivots(::reduce(matrix, mModulus));
+ ::reduceToEchelonForm(newPivots, rightColCount, mModulus);
return std::move(newPivots);
}
@@ -398,8 +395,5 @@ namespace {
}
}
-F4MatrixReducer::F4MatrixReducer(const PolyRing& ring, const int threadCount):
- mModulus(checkModulus(ring)),
- mThreadCount(std::max(threadCount, 1)
-) {
-}
+F4MatrixReducer::F4MatrixReducer(const PolyRing& ring):
+ mModulus(checkModulus(ring)) {}
diff --git a/src/mathicgb/F4MatrixReducer.hpp b/src/mathicgb/F4MatrixReducer.hpp
index f984738..f282584 100755
--- a/src/mathicgb/F4MatrixReducer.hpp
+++ b/src/mathicgb/F4MatrixReducer.hpp
@@ -9,7 +9,7 @@ class PolyRing;
answer you get is the submatrix that contains new pivots. */
class F4MatrixReducer {
public:
- F4MatrixReducer(const PolyRing& ring, int threadCount);
+ F4MatrixReducer(const PolyRing& ring);
/// Reduces the lower right part of the row echelon form of matrix. Assumes
/// that there is a permutation of the upper rows that makes the upper
@@ -18,7 +18,6 @@ public:
private:
const SparseMatrix::Scalar mModulus;
- const int mThreadCount;
};
#endif
diff --git a/src/mathicgb/F4Reducer.cpp b/src/mathicgb/F4Reducer.cpp
index 8b44c52..6cef465 100755
--- a/src/mathicgb/F4Reducer.cpp
+++ b/src/mathicgb/F4Reducer.cpp
@@ -59,7 +59,7 @@ std::unique_ptr<Poly> F4Reducer::classicReduceSPoly
SparseMatrix reduced;
{
- F4MatrixReducer red(basis.ring(), mThreadCount);
+ F4MatrixReducer red(basis.ring());
reduced = red.reduce(qm);
}
@@ -103,7 +103,7 @@ void F4Reducer::classicReduceSPolySet
{
QuadMatrix qm;
{
- F4MatrixBuilder builder(basis, mThreadCount, mMemoryQuantum);
+ F4MatrixBuilder builder(basis, mMemoryQuantum);
for (auto it = spairs.begin(); it != spairs.end(); ++it) {
builder.addSPolynomialToMatrix
(basis.poly(it->first), basis.poly(it->second));
@@ -113,7 +113,7 @@ void F4Reducer::classicReduceSPolySet
// there has to be something to reduce
MATHICGB_ASSERT(qm.bottomLeft.rowCount() > 0);
}
- reduced = F4MatrixReducer(basis.ring(), mThreadCount).reduce(qm);
+ reduced = F4MatrixReducer(basis.ring()).reduce(qm);
monomials = std::move(qm.rightColumnMonomials);
for (auto it = qm.leftColumnMonomials.begin();
it != qm.leftColumnMonomials.end(); ++it)
@@ -158,7 +158,7 @@ void F4Reducer::classicReducePolySet
{
QuadMatrix qm;
{
- F4MatrixBuilder builder(basis, mThreadCount, mMemoryQuantum);
+ F4MatrixBuilder builder(basis, mMemoryQuantum);
for (auto it = polys.begin(); it != polys.end(); ++it)
builder.addPolynomialToMatrix(**it);
builder.buildMatrixAndClear(qm);
@@ -166,7 +166,7 @@ void F4Reducer::classicReducePolySet
// there has to be something to reduce
MATHICGB_ASSERT(qm.bottomLeft.rowCount() > 0);
}
- reduced = F4MatrixReducer(basis.ring(), mThreadCount).reduce(qm);
+ reduced = F4MatrixReducer(basis.ring()).reduce(qm);
monomials = std::move(qm.rightColumnMonomials);
for (auto it = qm.leftColumnMonomials.begin();
it != qm.leftColumnMonomials.end(); ++it)
@@ -197,10 +197,6 @@ Poly* F4Reducer::regularReduce
return p;
}
-void F4Reducer::setThreadCount(int threadCount) {
- mThreadCount = threadCount;
-}
-
void F4Reducer::setMemoryQuantum(size_t quantum) {
mMemoryQuantum = quantum;
}
diff --git a/src/mathicgb/F4Reducer.hpp b/src/mathicgb/F4Reducer.hpp
index fe113d7..a4eba3f 100755
--- a/src/mathicgb/F4Reducer.hpp
+++ b/src/mathicgb/F4Reducer.hpp
@@ -34,9 +34,7 @@ public:
size_t basisElement,
const GroebnerBasis& basis);
- virtual void setThreadCount(int threadCount);
-
- virtual void setMemoryQuantum(size_t quantum);
+ virtual void setMemoryQuantum(size_t quantum);
virtual std::string description() const;
virtual size_t getMemoryUse() const;
diff --git a/src/mathicgb/QuadMatrix.cpp b/src/mathicgb/QuadMatrix.cpp
index 30b62f2..edfe89e 100755
--- a/src/mathicgb/QuadMatrix.cpp
+++ b/src/mathicgb/QuadMatrix.cpp
@@ -273,7 +273,7 @@ namespace {
}
}
-void QuadMatrix::sortColumnsLeftRightParallel(const int threadCount) {
+void QuadMatrix::sortColumnsLeftRightParallel() {
typedef SparseMatrix::ColIndex ColIndex;
std::vector<ColIndex> leftPermutation;
std::vector<ColIndex> rightPermutation;
diff --git a/src/mathicgb/QuadMatrix.hpp b/src/mathicgb/QuadMatrix.hpp
index 67ed7bb..e9d858a 100755
--- a/src/mathicgb/QuadMatrix.hpp
+++ b/src/mathicgb/QuadMatrix.hpp
@@ -56,9 +56,8 @@ public:
std::string toString() const;
/// Sort the left columns to be in decreasing order according to the monomial
- /// order from the ring. The operation is parallel using up to threadCount
- /// threads.
- void sortColumnsLeftRightParallel(int threadCount);
+ /// order from the ring. The operation is done in parallel.
+ void sortColumnsLeftRightParallel();
/// Makes a copy of this matrix whose rows are sorted in some canonical way.
/// TODO: Actually only coarsely sorts the top rows right now.
diff --git a/src/mathicgb/Reducer.hpp b/src/mathicgb/Reducer.hpp
index 4db9f10..675e0f8 100755
--- a/src/mathicgb/Reducer.hpp
+++ b/src/mathicgb/Reducer.hpp
@@ -62,10 +62,6 @@ public:
size_t basisElement,
const GroebnerBasis& basis) = 0;
- /** Sets how many parallel threads to use for reduction - if the
- reducer supports it. */
- virtual void setThreadCount(int threadCount) = 0;
-
/** Sets how many bytes of memory to increase the memory use by
at a time - if such a thing is appropriate for the reducer. */
virtual void setMemoryQuantum(size_t quantum) = 0;
diff --git a/src/mathicgb/TypicalReducer.cpp b/src/mathicgb/TypicalReducer.cpp
index 9053949..7b55e74 100755
--- a/src/mathicgb/TypicalReducer.cpp
+++ b/src/mathicgb/TypicalReducer.cpp
@@ -155,10 +155,6 @@ void TypicalReducer::classicReducePolySet
}
}
-void TypicalReducer::setThreadCount(int threadCount) {
- // multithreading not supported here (yet!)
-}
-
void TypicalReducer::setMemoryQuantum(size_t quantum) {
}
diff --git a/src/mathicgb/TypicalReducer.hpp b/src/mathicgb/TypicalReducer.hpp
index de234b2..401e4b7 100755
--- a/src/mathicgb/TypicalReducer.hpp
+++ b/src/mathicgb/TypicalReducer.hpp
@@ -43,8 +43,6 @@ public:
const PolyBasis& basis,
std::vector<std::unique_ptr<Poly> >& reducedOut);
- virtual void setThreadCount(int threadCount);
-
virtual void setMemoryQuantum(size_t quantum);
protected:
diff --git a/src/test/F4MatrixBuilder.cpp b/src/test/F4MatrixBuilder.cpp
index 623982a..c96d6fc 100755
--- a/src/test/F4MatrixBuilder.cpp
+++ b/src/test/F4MatrixBuilder.cpp
@@ -9,6 +9,7 @@
#include "mathicgb/io-util.hpp"
#include <gtest/gtest.h>
+#include <tbb/tbb.h>
#include <memory>
namespace {
@@ -18,8 +19,7 @@ namespace {
// @todo: This whole thing is fairly ridiculous - some kind of more
// general dependency injection mechanism might be nice here.
struct BuilderMaker {
- BuilderMaker(int threadCount):
- mThreadCount(threadCount),
+ BuilderMaker():
mRing(ringFromString("101 6 1\n1 1 1 1 1 1")),
mIdeal(*mRing),
mOrder(FreeModuleOrder::makeOrder(1, &mIdeal)),
@@ -36,14 +36,13 @@ namespace {
F4MatrixBuilder& create() {
MATHICGB_ASSERT(mBuilder.get() == 0);
- mBuilder.reset(new F4MatrixBuilder(mBasis, mThreadCount));
+ mBuilder.reset(new F4MatrixBuilder(mBasis));
return *mBuilder;
}
const PolyRing& ring() const {return *mRing;}
private:
- const int mThreadCount;
std::unique_ptr<PolyRing> mRing;
Ideal mIdeal;
std::unique_ptr<FreeModuleOrder> mOrder;
@@ -54,7 +53,8 @@ namespace {
TEST(F4MatrixBuilder, Empty) {
for (int threadCount = 1; threadCount < 4; ++threadCount) {
- BuilderMaker maker(threadCount);
+ tbb::task_scheduler_init scheduler(threadCount);
+ BuilderMaker maker;
F4MatrixBuilder& builder = maker.create();
QuadMatrix matrix;
@@ -70,7 +70,8 @@ TEST(F4MatrixBuilder, Empty) {
TEST(F4MatrixBuilder, SPair) {
for (int threadCount = 1; threadCount < 4; ++threadCount) {
- BuilderMaker maker(threadCount);
+ tbb::task_scheduler_init scheduler(threadCount);
+ BuilderMaker maker;
const Poly& p1 = maker.addBasisElement("a4c2-d");
const Poly& p2 = maker.addBasisElement("a4b+d");
// S-pair of p1 and p2 is -c2d-bd
@@ -91,7 +92,8 @@ TEST(F4MatrixBuilder, SPair) {
TEST(F4MatrixBuilder, OneByOne) {
for (int threadCount = 1; threadCount < 4; ++threadCount) {
- BuilderMaker maker(threadCount);
+ tbb::task_scheduler_init scheduler(threadCount);
+ BuilderMaker maker;
const Poly& p = maker.addBasisElement("a");
F4MatrixBuilder& builder = maker.create();
builder.addPolynomialToMatrix(p.getLeadMonomial(), p);
@@ -109,7 +111,7 @@ TEST(F4MatrixBuilder, OneByOne) {
TEST(F4MatrixBuilder, DirectReducers) {
for (int threadCount = 1; threadCount < 4; ++threadCount) {
- BuilderMaker maker(threadCount);
+ BuilderMaker maker;
maker.addBasisElement("a6<0>"); // reducer == to lead term
maker.addBasisElement("a3b2<0>+a3c"); // reducer == to lower order term
maker.addBasisElement("c<0>"); // reducer divides
@@ -149,7 +151,7 @@ TEST(F4MatrixBuilder, DirectReducers) {
TEST(F4MatrixBuilder, IteratedReducer) {
for (int threadCount = 1; threadCount < 4; ++threadCount) {
- BuilderMaker maker(threadCount);
+ BuilderMaker maker;
const Poly& p1 = maker.addBasisElement("a4-a3");
const Poly& p2 = maker.addBasisElement("a-1");
F4MatrixBuilder& builder = maker.create();
diff --git a/src/test/F4MatrixReducer.cpp b/src/test/F4MatrixReducer.cpp
index 0e9916a..ec55c1c 100755
--- a/src/test/F4MatrixReducer.cpp
+++ b/src/test/F4MatrixReducer.cpp
@@ -116,7 +116,7 @@ TEST(F4MatrixReducer, Reduce) {
ASSERT_EQ(origStr, m.toString()) << "Printed m:\n" << m;
- SparseMatrix reduced(F4MatrixReducer(*ring, 1).reduce(m));
+ SparseMatrix reduced(F4MatrixReducer(*ring).reduce(m));
const char* redStr =
"0: 0#1 2#4 3#22 4#11\n"
diff --git a/src/test/QuadMatrixBuilder.cpp b/src/test/QuadMatrixBuilder.cpp
index ee4f828..8aaf1eb 100755
--- a/src/test/QuadMatrixBuilder.cpp
+++ b/src/test/QuadMatrixBuilder.cpp
@@ -159,7 +159,7 @@ TEST(QuadMatrixBuilder, SortColumns) {
QuadMatrixBuilder b(*ring, map, monoLeft, monoRight);
b.rowDoneTopLeftAndRight();
auto matrix = b.buildMatrixAndClear();
- matrix.sortColumnsLeftRightParallel(1);
+ matrix.sortColumnsLeftRightParallel();
const char* matrixStr =
"Left columns:\n"
"Right columns:\n"
@@ -206,10 +206,10 @@ TEST(QuadMatrixBuilder, SortColumns) {
"0: 1#1 0#2 | 0: 2#3 0#4 1#5 \n"
" | \n"
"0: 1#6 0#7 | 0: 2#8 0#9 1#10\n";
- matrix.sortColumnsLeftRightParallel(1);
+ matrix.sortColumnsLeftRightParallel();
ASSERT_EQ(matrixStr2, matrix.toString());
- matrix.sortColumnsLeftRightParallel(1);
+ matrix.sortColumnsLeftRightParallel();
ASSERT_EQ(matrixStr2, matrix.toString());
}
}
diff --git a/src/test/gb-test.cpp b/src/test/gb-test.cpp
index ea5a465..474803e 100755
--- a/src/test/gb-test.cpp
+++ b/src/test/gb-test.cpp
@@ -19,6 +19,7 @@
#include <sstream>
#include <memory>
#include <gtest/gtest.h>
+#include <tbb/tbb.h>
TEST(IO, ideal) {
const char* idealA_fromStr_format =
@@ -278,6 +279,7 @@ spairQueue reducerType divLookup monTable buchberger postponeKoszul useBaseDivis
MATHICGB_ASSERT
(Reducer::makeReducerNullOnUnknown(red, I->ring()).get() != 0);
+ tbb::task_scheduler_init scheduler(threadCount);
if (buchberger) {
BuchbergerAlg alg
(*I, freeModuleOrder, Reducer::reducerType(reducerType),
@@ -285,7 +287,6 @@ spairQueue reducerType divLookup monTable buchberger postponeKoszul useBaseDivis
alg.setUseAutoTopReduction(autoTopReduce);
alg.setUseAutoTailReduction(autoTailReduce);
alg.setSPairGroupSize(sPairGroupSize);
- alg.setThreadCount(threadCount);
alg.computeGrobnerBasis();
std::unique_ptr<Ideal> initialIdeal =
alg.basis().initialIdeal();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git
More information about the debian-science-commits
mailing list