Macaulay2 Engine
Loading...
Searching...
No Matches

◆ gauss_reduce()

void F4GB::gauss_reduce ( bool diagonalize)
private

Definition at line 612 of file f4.cpp.

614{
615 // For each row which is a non-pivot row:
616 // note that the row must be reducible, since the lead term corresponds to an
617 // spair cancellation
618 // actually: not true: generators will often not be reducible...
619 // also each such row must be non-zero, for the same reason
620 int nrows = INTSIZE(mat->rows);
621 int ncols = INTSIZE(mat->columns);
622
623 int n_newpivots = -1; // the number of new GB elements in this degree
624 std::atomic<long> n_zero_reductions = 0;
625
626 mtbb::tick_count t0;
627 mtbb::tick_count t1;
628 std::vector<int> spair_rows;
629
630 if (hilbert)
631 {
632 n_newpivots = hilbert->nRemainingExpected();
633 if (n_newpivots == 0)
634 {
635 std::cout << "Oh crap, our logic is wrong: should not get here if no new GB elements expected in this degree" << std::endl;
636 return;
637 }
638 }
639
640 for (int i = 0; i < nrows; ++i)
641 {
642 if (not is_pivot_row(i))
643 spair_rows.push_back(i);
644 }
645
646 t0 = mtbb::tick_count::now();
647
648#if defined(WITH_TBB)
649
650 std::mutex cout_guard;
651 using threadLocalDense_t = mtbb::enumerable_thread_specific<ElementArray>;
652 // create a dense array for each thread
653 threadLocalDense_t threadLocalDense([&]() {
654 return mVectorArithmetic->allocateElementArray(ncols);
655 });
656
657 if (M2_gbTrace >= 2) {
658 // TODO: where to display this info
659 std::cout << "Number of Threads Used: " << mNumThreads << std::endl;
660 }
661
662 mScheduler.execute([&] {
663 mtbb::parallel_for(mtbb::blocked_range<int>{0, INTSIZE(spair_rows)},
664 [&](const mtbb::blocked_range<int>& r)
665 {
666 // long actual_reductions = 0;
667 // for (auto i = r.begin(); i != r.end(); ++i)
668 // {
669 // if (not is_pivot_row(i))
670 // ++ actual_reductions;
671 // }
672
673 // cout_guard.lock();
674 // std::cout << "#reductions to do: " << actual_reductions << std::endl;
675 // cout_guard.unlock();
676
677 threadLocalDense_t::reference my_dense = threadLocalDense.local();
678 for (auto i = r.begin(); i != r.end(); ++i)
679 {
680 bool newNonzeroReduction = gauss_reduce_row(spair_rows[i], my_dense);
681 }
682 });
683 });
684 for (auto tlDense : threadLocalDense)
685 mVectorArithmetic->deallocateElementArray(tlDense);
686
687#else
688
689 ElementArray my_dense { mVectorArithmetic->allocateElementArray(ncols) };
690
691 for (int i = 0; i < INTSIZE(spair_rows); ++i)
692 gauss_reduce_row(spair_rows[i], my_dense);
693
694 mVectorArithmetic->deallocateElementArray(my_dense);
695
696#endif
697
698 t1 = mtbb::tick_count::now();
699 mParallelGaussTime += (t1-t0).seconds();
700
701 if (M2_gbTrace >= 2)
702 std::cout << "About to do serial loop, n_newpivots = " << n_newpivots << std::endl;
703 t0 = mtbb::tick_count::now();
704 ElementArray gauss_row { mVectorArithmetic->allocateElementArray(ncols) };
705 for (auto i = 0; i < spair_rows.size(); i++)
706 {
707 auto this_row = spair_rows[i];
708 if ((not hilbert) or (n_newpivots > 0))
709 {
710 bool newNonzeroReduction = gauss_reduce_row(this_row, gauss_row);
711 if (newNonzeroReduction)
712 {
713 row_elem &r = mat->rows[this_row];
714 mVectorArithmetic->makeMonic(r.coeffs);
715 mat->columns[r.comps[0]].head = this_row;
716 if (hilbert) --n_newpivots;
717 }
718 else
719 ++n_zero_reductions;
720 } else if (hilbert)
721 {
722 // Inform code that we don't want a new GB element from this row.
723 // The row will be deleted with clear_matrix.
724 row_elem &r = mat->rows[this_row];
725 r.len = 0;
726 }
727 }
728 mVectorArithmetic->deallocateElementArray(gauss_row);
729 t1 = mtbb::tick_count::now();
730 mSerialGaussTime += (t1-t0).seconds();
731
732 if (M2_gbTrace >= 3)
733 fprintf(stderr, "-- #zeroreductions %ld\n", n_zero_reductions.load());
734
735 t0 = mtbb::tick_count::now();
736 if (diagonalize) tail_reduce();
737 t1 = mtbb::tick_count::now();
738 mTailReduceTime += (t1-t0).seconds();
739}
void tail_reduce()
Definition f4.cpp:817
double mSerialGaussTime
Definition f4.hpp:198
coefficient_matrix * mat
Definition f4.hpp:186
double mTailReduceTime
Definition f4.hpp:199
HilbertController * hilbert
Definition f4.hpp:175
bool is_pivot_row(int index) const
Definition f4.cpp:741
double mParallelGaussTime
Definition f4.hpp:197
const VectorArithmetic * mVectorArithmetic
Definition f4.hpp:156
bool gauss_reduce_row(int index, ElementArray &gauss_row)
Definition f4.cpp:749
int M2_gbTrace
Definition m2-types.cpp:52
int * comps
Definition f4-types.hpp:163
ElementArray coeffs
Definition f4-types.hpp:162
#define INTSIZE(a)
Definition style.hpp:37
double seconds(DurationType time_diff)
Definition timing.hpp:59

References row_elem::coeffs, row_elem::comps, gauss_reduce_row(), hilbert, INTSIZE, is_pivot_row(), row_elem::len, M2_gbTrace, mat, mParallelGaussTime, mSerialGaussTime, mTailReduceTime, mVectorArithmetic, seconds(), and tail_reduce().

Referenced by do_spairs().