diff options
author | Tor Lillqvist <tml@collabora.com> | 2015-01-28 20:00:29 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2015-01-28 20:20:00 +0200 |
commit | c8818044e6e0cbcca0dcbd4aada7b260f88e8818 (patch) | |
tree | a5c460caf75816caab6f3265de7b2652382d723b /sc | |
parent | 1224bca6b7815760f106116b0dd1a895563c019b (diff) |
Make the OpenCL test document construction and calculation a bit faster
Turn off AutoCalc while constructing it and then calculate it when ready.
Use a smaller number for the minimum formula group size required for OpenCL to
be used while calculating it. Use less hardcoded magic numbers in the code.
Change-Id: I6f2c3b1035947a542776d6087bd229cb9c2892fb
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/optdlg/calcoptionsdlg.cxx | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx index a460f540f34e..12b071f3edad 100644 --- a/sc/source/ui/optdlg/calcoptionsdlg.cxx +++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx @@ -231,7 +231,7 @@ struct Area OUString msTitle; int mnRows; - Area(const OUString& rTitle, int nRows = ScInterpreter::GetGlobalConfig().mnOpenCLMinimumFormulaGroupSize + 1) : + Area(const OUString& rTitle, int nRows = ScInterpreter::GetGlobalConfig().mnOpenCLMinimumFormulaGroupSize + 2) : msTitle(rTitle), mnRows(nRows) { @@ -253,6 +253,8 @@ struct OpenCLTester int mnTestAreas; ScDocShell* mpDocShell; ScDocument *mpDoc; + bool mbOldAutoCalc; + ScCalcConfig maOldCalcConfig; OpenCLTester() : mnTestAreas(0) @@ -269,13 +271,18 @@ struct OpenCLTester mpDoc = &mpDocShell->GetDocument(); + mbOldAutoCalc = mpDoc->GetAutoCalc(); + mpDoc->SetAutoCalc(false); + maOldCalcConfig = ScInterpreter::GetGlobalConfig(); + ScCalcConfig aConfig(maOldCalcConfig); + aConfig.mnOpenCLMinimumFormulaGroupSize = 20; + ScInterpreter::SetGlobalConfig(aConfig); + mpDoc->SetString(ScAddress(0,0,0), "Result:"); } void addTest(const Area &rArea) { - sc::AutoCalcSwitch aACSwitch(*mpDoc, true); - mnTestAreas++; (void) mpDocShell->GetDocFunc().InsertTable(mnTestAreas, rArea.msTitle, false, true); @@ -570,21 +577,18 @@ struct Normdist : Area struct Reduction : Op { - int mnNum; double mnAccumInitial; - double (*mpFun)(double nAccum, double nArg); + double (*mpFun)(double nAccum, double nArg, const Reduction& rReduction); bool (*mpFilterOut)(double nArg); Reduction(const OUString& rTitle, const OUString& rOp, - int nNum, double nAccumInitial, double nRangeLo, double nRangeHi, double nEpsilon, - double (*pFun)(double nAccum, double nArg), + double (*pFun)(double nAccum, double nArg, const Reduction& rReduction), bool (*pFilterOut)(double nArg) = nullptr) : Op(rTitle, rOp, nRangeLo, nRangeHi, nEpsilon), - mnNum(nNum), mnAccumInitial(nAccumInitial), mpFun(pFun), mpFilterOut(pFilterOut) @@ -612,30 +616,30 @@ struct Reduction : Op pDoc->SetValue(ScAddress(0,1+nRow,nTab), nArg); - if (nRow >= mnNum-1) + if (nRow >= mnRows/2-1) { - pDoc->SetString(ScAddress(1,1+nRow-mnNum+1,nTab), + pDoc->SetString(ScAddress(1,1+nRow-mnRows/2+1,nTab), "=" + msOp + "(" + - ScRange(ScAddress(0,1+nRow-mnNum+1,nTab), + ScRange(ScAddress(0,1+nRow-mnRows/2+1,nTab), ScAddress(0,1+nRow,nTab)).Format(SCA_VALID|SCA_TAB_3D|SCA_VALID_COL|SCA_VALID_ROW) + ")"); double nAccum(mnAccumInitial); - for (int i = 0; i < mnNum; i++) - nAccum = mpFun(nAccum, pDoc->GetValue(ScAddress(0,1+nRow-mnNum+i+1,nTab))); + for (int i = 0; i < mnRows/2; i++) + nAccum = mpFun(nAccum, pDoc->GetValue(ScAddress(0,1+nRow-mnRows/2+i+1,nTab)), *this); - pDoc->SetValue(ScAddress(2,1+nRow-mnNum+1,nTab), nAccum); + pDoc->SetValue(ScAddress(2,1+nRow-mnRows/2+1,nTab), nAccum); if (mnEpsilon != 0) - pDoc->SetString(ScAddress(3,1+nRow-mnNum+1,nTab), - "=IF(ABS(" + ScAddress(1,1+nRow-mnNum+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) + - "-" + ScAddress(2,1+nRow-mnNum+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) + + pDoc->SetString(ScAddress(3,1+nRow-mnRows/2+1,nTab), + "=IF(ABS(" + ScAddress(1,1+nRow-mnRows/2+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) + + "-" + ScAddress(2,1+nRow-mnRows/2+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) + ")<=" + OUString::number(mnEpsilon) + ",0,1)"); else - pDoc->SetString(ScAddress(3,1+nRow-mnNum+1,nTab), - "=IF(" + ScAddress(1,1+nRow-mnNum+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) + - "=" + ScAddress(2,1+nRow-mnNum+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) + + pDoc->SetString(ScAddress(3,1+nRow-mnRows/2+1,nTab), + "=IF(" + ScAddress(1,1+nRow-mnRows/2+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) + + "=" + ScAddress(2,1+nRow-mnRows/2+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) + ",0,1)"); } } @@ -644,7 +648,7 @@ struct Reduction : Op { return "=SUM(" + ScRange(ScAddress(3,1+0,nTab), - ScAddress(3,1+mnRows-mnNum-1,nTab)).Format(SCA_VALID|SCA_TAB_3D|SCA_VALID_COL|SCA_VALID_ROW|SCA_VALID_TAB, pDoc) + + ScAddress(3,1+mnRows-mnRows/2-1,nTab)).Format(SCA_VALID|SCA_TAB_3D|SCA_VALID_COL|SCA_VALID_ROW|SCA_VALID_TAB, pDoc) + ")"; } }; @@ -746,36 +750,39 @@ IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, ) xTestDocument->addTest(Normdist()); - xTestDocument->addTest(Reduction("Sum", "SUM", 100, 0, -1000, 1000, 3e-10, - [] (double nAccum, double nArg) + xTestDocument->addTest(Reduction("Sum", "SUM", 0, -1000, 1000, 3e-10, + [] (double nAccum, double nArg, const Reduction&) { return (nAccum + nArg); })); - xTestDocument->addTest(Reduction("Average", "AVERAGE", 100, 0, -1000, 1000, 3e-10, - [] (double nAccum, double nArg) + xTestDocument->addTest(Reduction("Average", "AVERAGE", 0, -1000, 1000, 3e-10, + [] (double nAccum, double nArg, const Reduction& rReduction) { - return (nAccum + nArg/100.); + return (nAccum + nArg/(rReduction.mnRows/2)); })); - xTestDocument->addTest(Reduction("Product", "PRODUCT", 100, 1, 0.1, 2.5, 3e-10, - [] (double nAccum, double nArg) + xTestDocument->addTest(Reduction("Product", "PRODUCT", 1, 0.1, 2.5, 3e-10, + [] (double nAccum, double nArg, const Reduction&) { return (nAccum * nArg); })); - xTestDocument->addTest(Reduction("Min", "MIN", 100, DBL_MAX, -1000, 1000, 0, - [] (double nAccum, double nArg) + xTestDocument->addTest(Reduction("Min", "MIN", DBL_MAX, -1000, 1000, 0, + [] (double nAccum, double nArg, const Reduction&) { return std::min(nAccum, nArg); })); - xTestDocument->addTest(Reduction("Max", "MAX", 100, -DBL_MAX, -1000, 1000, 0, - [] (double nAccum, double nArg) + xTestDocument->addTest(Reduction("Max", "MAX", -DBL_MAX, -1000, 1000, 0, + [] (double nAccum, double nArg, const Reduction&) { return std::max(nAccum, nArg); })); + xTestDocument->mpDoc->CalcAll(); + ScInterpreter::SetGlobalConfig(xTestDocument->maOldCalcConfig); + return 0; } |