File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -84,11 +84,17 @@ void System::EvalJacobian() {
8484 mat.A .num .setZero ();
8585 mat.A .num .resize (mat.m , mat.n );
8686
87- std::vector<Eigen::Triplet<double >> values;
88- values.reserve (mat.A .sym .size ());
89- for (const auto &exprTriplet : mat.A .sym ) {
90- double value = exprTriplet.value ()->Eval ();
91- values.emplace_back (exprTriplet.row (), exprTriplet.col (), value);
87+ std::vector<Eigen::Triplet<double >> values (mat.A .sym .size ());
88+ // Not using range-for to achieve (old) OpenMP compatibility:
89+ // worth it because this profiles as taking a lot of time.
90+ // Must be signed integer for MSVC.
91+ const int n = (int )mat.A .sym .size ();
92+ #pragma omp parallel for
93+ for (int i = 0 ; i < n; ++i) {
94+ const auto &exprTriplet = mat.A .sym [i];
95+ double value = exprTriplet.value ()->Eval ();
96+ // assigning rather than emplace_back so we don't have to stick a critical pragma in here for openmp.
97+ values[i] = {exprTriplet.row (), exprTriplet.col (), value};
9298 }
9399 mat.A .num .setFromTriplets (values.begin (), values.end ());
94100}
You can’t perform that action at this time.
0 commit comments