Use ParallelFor instead of ParallelForRange

better readability and no performance difference (if using
        NETGEN_LAMBDA_INLINE)
This commit is contained in:
Matthias Hochsteger 2019-10-09 09:57:37 +02:00
parent 95df0ea73e
commit 6e5d806d92

View File

@ -7,11 +7,6 @@
namespace netgen namespace netgen
{ {
using ngcore::ParallelForRange;
class trionedge class trionedge
{ {
public: public:
@ -191,15 +186,12 @@ namespace netgen
if(faceindex==0) if(faceindex==0)
{ {
seia.SetSize(mesh.GetNSE()); seia.SetSize(mesh.GetNSE());
ParallelForRange( Range(seia), [&] (auto myrange) ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE
{
for (auto i : myrange)
{ {
SurfaceElementIndex sei(i); SurfaceElementIndex sei(i);
seia[i] = sei; seia[i] = sei;
if (mesh[sei].GetNP() != 3) if (mesh[sei].GetNP() != 3)
mixed = true; mixed = true;
}
}); });
} }
else else
@ -225,28 +217,22 @@ namespace netgen
if(faceindex == 0) if(faceindex == 0)
{ {
ParallelForRange( Range(pangle), [&] (auto myrange) ParallelFor( Range(pangle), [&] (auto i) NETGEN_LAMBDA_INLINE
{ {
for (auto i : myrange)
pangle[i] = 0.0; pangle[i] = 0.0;
}); });
} }
else else
{ {
ParallelForRange( Range(seia), [&] (auto myrange) ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE
{
for (auto i : myrange)
{ {
const Element2d & sel = mesh[seia[i]]; const Element2d & sel = mesh[seia[i]];
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
pangle[sel[j]] = 0.0; pangle[sel[j]] = 0.0;
}
}); });
} }
ParallelForRange( Range(seia), [&] (auto myrange) ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE
{
for (auto i : myrange)
{ {
const Element2d & sel = mesh[seia[i]]; const Element2d & sel = mesh[seia[i]];
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
@ -259,12 +245,9 @@ namespace netgen
mesh[sel[(j+2)%3]] - mesh[sel[j]])); mesh[sel[(j+2)%3]] - mesh[sel[j]]));
} }
} }
}
}); });
ParallelForRange( Range(seia), [&] (auto myrange) ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE
{
for (auto i : myrange)
{ {
const Element2d & sel = mesh[seia[i]]; const Element2d & sel = mesh[seia[i]];
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
@ -277,12 +260,9 @@ namespace netgen
if (pangle[pi] >= minangle[j]) if (pangle[pi] >= minangle[j])
pdef[pi] = -1-j; pdef[pi] = -1-j;
} }
}
}); });
ParallelForRange( Range(seia), [&pdef, &neighbors, &mesh, &seia, &elements_on_node] (auto myrange) ParallelFor( Range(seia), [&pdef, &neighbors, &mesh, &seia, &elements_on_node] (auto i) NETGEN_LAMBDA_INLINE
{
for (auto i : myrange)
{ {
auto sei = seia[i]; auto sei = seia[i];
for (PointIndex pi : mesh[sei].template PNums<3>()) for (PointIndex pi : mesh[sei].template PNums<3>())
@ -324,7 +304,6 @@ namespace netgen
} }
} }
} }
}
}); });
@ -343,17 +322,15 @@ namespace netgen
while (!done && t >= 2) while (!done && t >= 2)
{ {
cnt = 0; cnt = 0;
ParallelForRange( Range(seia), [&] (auto myrange) ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE
{
for (auto i : myrange)
{ {
SurfaceElementIndex t1 = seia[i]; SurfaceElementIndex t1 = seia[i];
if (mesh[t1].IsDeleted()) if (mesh[t1].IsDeleted())
continue; return;
if (mesh[t1].GetIndex() != faceindex) if (mesh[t1].GetIndex() != faceindex)
continue; return;
if (multithread.terminate) if (multithread.terminate)
throw NgException ("Meshing stopped"); throw NgException ("Meshing stopped");
@ -361,7 +338,6 @@ namespace netgen
for (int o1 = 0; o1 < 3; o1++) for (int o1 = 0; o1 < 3; o1++)
if(EdgeSwapping(mesh, usemetric, neighbors, swapped, t1, o1, t, pdef, true)) if(EdgeSwapping(mesh, usemetric, neighbors, swapped, t1, o1, t, pdef, true))
improvement_candidates[cnt++]= std::make_pair(t1,o1); improvement_candidates[cnt++]= std::make_pair(t1,o1);
}
}); });
auto elements_with_improvement = improvement_candidates.Range(cnt.load()); auto elements_with_improvement = improvement_candidates.Range(cnt.load());