20#include "../../system/supervisor.hpp"
21#include "../../system/supervisorinterface.h"
23static void* testFcn1(
void* vint)
25 long v =
reinterpret_cast<long>(vint);
26 std::cout <<
"starting fcn1 with v = " << v << std::endl;
30static void* testFcn2(
void* vint)
32 long v =
reinterpret_cast<long>(vint);
33 std::cout <<
"starting fcn2 with v = " << v << std::endl;
41 ThreadTask* t1 = createThreadTask(
"task 1", testFcn1,
reinterpret_cast<void*
>(1L), 0, 0, 0);
42 ThreadTask* t2 = createThreadTask(
"task 1", testFcn2,
reinterpret_cast<void*
>(2L), 0, 0, 0);
46 std::cout << val[0] <<
" " << val[1] << std::endl;
57 std::cout <<
"hardware threads: " << std::thread::hardware_concurrency() << std::endl;
58 std::cout <<
"testing thread tasks" << std::endl;
60 std::cout <<
" done testing thread tasks" << std::endl;
89 mRing.vectorArithmetic().deallocateElementArray(f.mCoeffs);
94 mRing.vectorArithmetic().deallocateElementArray(f.mCoeffs);
119 for (
auto j = elem.mBegin; j < elem.mEnd; ++j)
156 int& result_sign_if_skew)
158 result_sign_if_skew = 1;
161 if (
p.mBegin ==
p.mEnd)
return -1;
168 if (
ring().isSkewCommutative())
171 if (result_sign_if_skew == 0)
195 if (
mHashTable.find_or_insert(thisMonom, new_m))
247 if (val < 0) fprintf(stderr,
"ERROR: expected monomial to live\n");
258 auto&
p = thiselement.mSyzygy;
261 for (; i !=
end; ++i)
267 if (val < 0)
continue;
270 mRing.vectorArithmetic().pushBackElement(
271 r.
mCoeffs,
p.coeffs, i.coefficient_index());
275 mRing.vectorArithmetic().pushBackNegatedElement(
276 r.
mCoeffs,
p.coeffs, i.coefficient_index());
282 std::vector<ComponentIndex>& entries)
287 entries[i] = permutation[entries[i]];
292 if (entries[i] <= entries[i - 1])
294 fprintf(stderr,
"Internal error: array out of order\n");
308 std::cout <<
"-- rows --" << std::endl;
310 std::cout <<
"-- columns --" << std::endl;
313 std::cout <<
"reorderColumns" << std::endl;
319 auto timeA =
timer();
321 auto column_order =
sorter.sort();
322 auto timeB =
timer();
323 double nsec_sort2 =
seconds(timeB - timeA);
324 mFrame.timeSortMatrix += nsec_sort2;
325 auto ncompares =
sorter.numComparisons();
328 std::cout <<
" #comparisons sorting " << ncols <<
" columns = " << ncompares <<
" ";
331 std::cout <<
" sort time: " << nsec_sort2 << std::endl;
338 ord[column_order[i]] = i;
342 std::cout <<
"column_order: ";
343 for (
ComponentIndex i=0; i<ncols; i++) std::cout <<
" " << column_order[i];
344 std::cout << std::endl;
345 std::cout <<
"ord: ";
346 for (
ComponentIndex i=0; i<ncols; i++) std::cout <<
" " << ord[i];
347 std::cout << std::endl;
350 std::vector<res_packed_monomial> sortedColumnArray;
351 std::vector<Row> sortedRowArray;
353 sortedColumnArray.reserve(ncols);
354 sortedRowArray.reserve(ncols);
359 sortedColumnArray.push_back(
mColumns[newc]);
360 sortedRowArray.push_back(
Row());
368 std::cout <<
"applying permutation to reducers" << std::endl;
374 std::cout <<
"reducer " << i <<
" before:";
376 std::cout << std::endl;
380 std::cout <<
"reducer " << i <<
" after:";
382 std::cout << std::endl;
386 std::cout <<
"applying permutation to spairs" << std::endl;
391 std::cout <<
"spair " << i <<
" before:";
393 std::cout << std::endl;
397 std::cout <<
"spair " << i <<
" after:";
399 std::cout << std::endl;
414 for (
auto it = myframe.begin(); it != myframe.end(); ++it)
426 std::cout <<
"makeMatrix sp: " << r
427 <<
" #rows = " <<
mColumns.size() << std::endl;
445 <<
" #rows = " <<
mReducers.size() << std::endl;
453 std :: cout <<
"-- reducer matrix --" << std::endl;
457 std :: cout <<
"-- spair matrix --" << std::endl;
467 bool onlyConstantMaps,
468 const std::vector<bool>& track)
473 std::cout <<
"reducing row " << i << std::endl;
496 std::cout <<
"about to fill from sparse " << i << std::endl;
499 mRing.vectorArithmetic().fillDenseArray(gauss_row,
504 while (firstcol <= lastcol)
507 std::cout <<
"about to reduce with col " << firstcol << std::endl;
508 std::cout <<
"gauss_row: "
509 << (gauss_row.
isNull() ?
"null" :
"not-null")
511 std::cout <<
"mReducers[" << firstcol <<
"]: "
512 << (
mReducers[firstcol].mCoeffs.isNull() ?
"null"
515 std::cout <<
"result: " << (
result.coefficientInserter().isNull()
519 std::cout <<
" dense: ";
520 mRing.vectorArithmetic().displayElementArray(std::cout, gauss_row)
522 mRing.vectorArithmetic().displayElementArray(std::cout,
524 std::cout << std::endl;
525 mRing.vectorArithmetic().displayElementArray(std::cout,
526 result.coefficientInserter());
527 std::cout << std::endl;
530 if (onlyConstantMaps and not track[firstcol])
532 mRing.vectorArithmetic().denseCancelFromSparse(gauss_row,
540 mRing.vectorArithmetic().denseCancelFromSparse(gauss_row,
545 result.coefficientInserter());
548 std::cout <<
" done with sparseCancel" << std::endl;
549 mRing.vectorArithmetic().displayElementArray(std::cout, gauss_row)
551 mRing.vectorArithmetic().displayElementArray(std::cout,
554 mRing.vectorArithmetic().displayElementArray(std::cout,
555 result.coefficientInserter())
557 std::cout <<
" about to push back term" << std::endl;
563 std::cout <<
"done with col " << firstcol << std::endl;
566 firstcol =
mRing.vectorArithmetic().denseNextNonzero(gauss_row, firstcol + 1, lastcol);
571 std::cout <<
"about to set syz" << std::endl;
575 std::cout <<
"just set syz" << std::endl;
581 bool onlyConstantMaps =
false;
582 std::vector<bool> track(
mReducers.size());
584 if (onlyConstantMaps)
586 for (
auto i = 0; i <
mReducers.size(); i++)
597 using threadLocalDense_t = mtbb::enumerable_thread_specific<ElementArray>;
599 threadLocalDense_t threadLocalDense([&]() {
613 mFrame.getScheduler().execute([
this,&onlyConstantMaps,&track,&threadLocalDense] {
615 mtbb::parallel_for(mtbb::blocked_range<int>{0,(
int)
mSPairs.size()},
616 [&](
const mtbb::blocked_range<int>& r)
619 threadLocalDense_t::reference my_dense = threadLocalDense.local();
620 for (
auto i = r.begin(); i != r.end(); ++i) {
626 for (
auto tlDense : threadLocalDense)
627 mRing.vectorArithmetic().deallocateElementArray(tlDense);
632 for (
long i = 0; i <
mSPairs.size(); i++)
636 mRing.vectorArithmetic().deallocateElementArray(gauss_row);
642 decltype(
timer()) timeA, timeB;
647 std::cout <<
"construct (" << lev <<
"," << degree-lev <<
")" << std::endl;
657 std::cout <<
" make (" << lev <<
"," << degree-lev <<
"): " <<
seconds(timeB - timeA) <<
" sec"
661 std::cout <<
"-- rows --" << std::endl;
663 std::cout <<
"-- columns --" << std::endl;
665 std :: cout <<
"-- reducer matrix --" << std::endl;
666 if (
true or lev <= 2)
671 std :: cout <<
"-- reducer matrix --" << std::endl;
675 std :: cout <<
"-- spair matrix --" << std::endl;
694 std::cout <<
" gauss (" << lev <<
"," << degree-lev <<
"): " <<
seconds(timeB - timeA) <<
" sec"
707 std::cout <<
"-- reducers(rows) -- " << std::endl;
712 std::cout << std::endl;
717 std::cout <<
"-- columns --" << std::endl;
722 std::cout << std::endl;
730 std::cout <<
"coeffs[" << i <<
"] = ";
731 mRing.vectorArithmetic().displayElementArray(std::cout, rows[i].mCoeffs);
732 std::cout <<
" comps = ";
733 for (
long j = 0; j < rows[i].mComponents.size(); ++j)
734 std::cout << rows[i].mComponents[j] <<
" ";
735 std::cout << std::endl;
743 mRing.vectorArithmetic().displayAsDenseArray(std::cout,
746 Range(rows[i].mComponents.data(), rows[i].mComponents.data() + rows[i].mComponents.size()));
Dense exponent-vector template [e_0, ..., e_{nvars-1}] for monomial operations.
Type-erased owning handle to a dense coefficient vector held by a ConcreteVectorArithmetic<Ring>.
void debugOutputReducers()
void resetMatrix(int lev, int degree)
MonomialHashTable< ResMonomialsWithComponent > mHashTable
ComponentIndex processMonomialProduct(res_const_packed_monomial m, res_const_packed_monomial n, int &result_sign_if_skew)
F4Res(SchreyerFrame &res)
void construct(int lev, int degree)
const VectorArithmetic & vectorArithmetic() const
const ResPolyRing & ring() const
void debugOutputColumns()
std::unique_ptr< const ResMonomialsWithComponent > mSchreyerRes
const ResMonoid & monoid() const
std::vector< res_packed_monomial > mColumns
void debugOutputMatrixSparse(std::vector< Row > &)
MonomialMemorySpace mMonomSpace2
std::vector< Row > mReducers
bool findDivisor(res_const_packed_monomial m, res_packed_monomial result)
findDivisor
void gaussReduceRow(int index, ElementArray &dense, bool onlyConstantMaps, const std::vector< bool > &track)
const ResPolyRing & mRing
void debugOutputMatrix(std::vector< Row > &)
std::vector< long > mSPairComponents
void debugOutputSPairMatrix()
ComponentIndex processCurrentMonomial(res_packed_monomial thisMonom)
void debugOutputReducerMatrix()
long mNextReducerToProcess
std::vector< Row > mSPairs
component_index get_component(res_const_packed_monomial m) const
void showAlpha(res_const_packed_monomial m) const
void set_component(component_index component, res_packed_monomial m) const
bool is_divisible_by_var_in_range(res_const_packed_monomial monom, int lo, int hi) const
void unchecked_mult(res_const_packed_monomial m, res_const_packed_monomial n, res_packed_monomial result) const
int skew_mult_sign(const SkewMultiplication *skew, res_const_packed_monomial m, res_const_packed_monomial n) const
Sorter that orders res_packed_monomials by their total (Schreyer) monomial, with a stable tiebreaker ...
MonHashTable trait for the resolution engine's res_packed_monomials, with components included.
const VectorArithmetic & vectorArithmetic() const
Builder that accumulates terms into a ResPolynomial and finalises the layout in one shot via setPoly.
Forward iterator over the terms of a ResPolynomial.
State container for the in-progress free resolution built by the F4 resolution engine.
ElementArray allocateElementArray(ComponentIndex nelems) const
Create a coefficient vector with room for nelems coefficients.
void pushBackMinusOne(ElementArray &coeffs) const
VALGRIND_MAKE_MEM_DEFINED & result(result)
Monoid — variable count, naming, grading, and monomial order of a polynomial ring.
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
static void applyPermutation(ComponentIndex *permutation, std::vector< ComponentIndex > &entries)
F4Res — F4-style matrix-reduction worker over a SchreyerFrame.
Schreyer-order column sorters for the F4 resolution Macaulay matrix.
const res_monomial_word * res_const_packed_monomial
res_monomial_word * res_packed_monomial
SchreyerFrame — in-progress representation of a free resolution organised by (level,...
TermIterator< Nterm > end(Nterm *)
std::vector< ComponentIndex > mComponents
res_packed_monomial mLeadTerm
One row of the Macaulay matrix built by F4Res::construct.
Text-formatting helpers layered on buffer: bignum print, line wrapping, M2_gbTrace-gated emit.
std::chrono::steady_clock::time_point timer()
double seconds(DurationType time_diff)
Inline std::chrono::steady_clock wrappers and elapsed-time conversion helpers.