partially parallel Compress

This commit is contained in:
Joachim Schöberl 2019-09-30 08:53:32 +02:00
parent bd589a4cca
commit 7019504265
3 changed files with 70 additions and 28 deletions

View File

@ -41,6 +41,7 @@ namespace netgen
void MeshOptimize2d :: EdgeSwapping (Mesh & mesh, int usemetric) void MeshOptimize2d :: EdgeSwapping (Mesh & mesh, int usemetric)
{ {
static Timer timer("EdgeSwapping (2D)"); RegionTimer reg(timer);
if (!faceindex) if (!faceindex)
{ {
if (usemetric) if (usemetric)
@ -62,9 +63,6 @@ namespace netgen
} }
static int timer = NgProfiler::CreateTimer ("EdgeSwapping 2D");
NgProfiler::RegionTimer reg1 (timer);
static int timerstart = NgProfiler::CreateTimer ("EdgeSwapping 2D start"); static int timerstart = NgProfiler::CreateTimer ("EdgeSwapping 2D start");
NgProfiler::StartTimer (timerstart); NgProfiler::StartTimer (timerstart);

View File

@ -3256,8 +3256,7 @@ namespace netgen
NgLock lock(mutex); NgLock lock(mutex);
lock.Lock(); lock.Lock();
NgArray<PointIndex,PointIndex::BASE,PointIndex> op2np(GetNP()); Array<PointIndex,PointIndex> op2np(GetNP());
NgArray<MeshPoint> hpoints;
Array<bool, PointIndex> pused(GetNP()); Array<bool, PointIndex> pused(GetNP());
/* /*
@ -3299,20 +3298,44 @@ namespace netgen
segments.DeleteElement(i--); segments.DeleteElement(i--);
pused = false; pused = false;
/*
for (int i = 0; i < volelements.Size(); i++) for (int i = 0; i < volelements.Size(); i++)
{ {
const Element & el = volelements[i]; const Element & el = volelements[i];
for (int j = 0; j < el.GetNP(); j++) for (int j = 0; j < el.GetNP(); j++)
pused[el[j]] = true; pused[el[j]] = true;
} }
*/
/*
for (const Element & el : volelements)
for (PointIndex pi : el.PNums())
pused[pi] = true;
*/
ParallelForRange
(volelements.Range(), [&] (auto myrange)
{
for (const Element & el : volelements.Range(myrange))
for (PointIndex pi : el.PNums())
pused[pi] = true;
});
/*
for (int i = 0; i < surfelements.Size(); i++) for (int i = 0; i < surfelements.Size(); i++)
{ {
const Element2d & el = surfelements[i]; const Element2d & el = surfelements[i];
for (int j = 0; j < el.GetNP(); j++) for (int j = 0; j < el.GetNP(); j++)
pused[el[j]] = true; pused[el[j]] = true;
} }
*/
ParallelForRange
(surfelements.Range(), [&] (auto myrange)
{
for (const Element2d & el : surfelements.Range(myrange))
for (PointIndex pi : el.PNums())
pused[pi] = true;
});
for (int i = 0; i < segments.Size(); i++) for (int i = 0; i < segments.Size(); i++)
{ {
const Segment & seg = segments[i]; const Segment & seg = segments[i];
@ -3346,40 +3369,59 @@ namespace netgen
// pused.Set(); // pused.Set();
int npi = PointIndex::BASE-1; {
Array<MeshPoint> hpoints;
// for (PointIndex pi = points.Begin(); pi < points.End(); pi++) int npi = PointIndex::BASE;
for (PointIndex pi : points.Range()) for (PointIndex pi : points.Range())
if (pused[pi]) if (pused[pi])
{ {
npi++; op2np[pi] = npi;
op2np[pi] = npi; npi++;
hpoints.Append (points[pi]); hpoints.Append (points[pi]);
} }
else else
{ {
op2np[pi].Invalidate(); // = -1; op2np[pi].Invalidate();
} }
points.SetSize(0);
points.SetSize(0); for (int i = 0; i < hpoints.Size(); i++)
for (int i = 0; i < hpoints.Size(); i++) points.Append (hpoints[i]);
points.Append (hpoints[i]); }
/*
for (int i = 1; i <= volelements.Size(); i++) for (int i = 1; i <= volelements.Size(); i++)
{ {
Element & el = VolumeElement(i); Element & el = VolumeElement(i);
for (int j = 0; j < el.GetNP(); j++) for (int j = 0; j < el.GetNP(); j++)
el[j] = op2np[el[j]]; el[j] = op2np[el[j]];
} }
*/
ParallelForRange
(volelements.Range(), [&] (auto myrange)
{
for (Element & el : volelements.Range(myrange))
for (PointIndex & pi : el.PNums())
pi = op2np[pi];
});
/*
for (int i = 1; i <= surfelements.Size(); i++) for (int i = 1; i <= surfelements.Size(); i++)
{ {
Element2d & el = SurfaceElement(i); Element2d & el = SurfaceElement(i);
for (int j = 0; j < el.GetNP(); j++) for (int j = 0; j < el.GetNP(); j++)
el[j] = op2np[el[j]]; el[j] = op2np[el[j]];
} }
*/
ParallelForRange
(surfelements.Range(), [&] (auto myrange)
{
for (Element2d & el : surfelements.Range(myrange))
for (PointIndex & pi : el.PNums())
pi = op2np[pi];
});
for (int i = 0; i < segments.Size(); i++) for (int i = 0; i < segments.Size(); i++)
{ {
Segment & seg = segments[i]; Segment & seg = segments[i];
@ -5565,6 +5607,8 @@ namespace netgen
void Mesh :: RebuildSurfaceElementLists () void Mesh :: RebuildSurfaceElementLists ()
{ {
static Timer t("Mesh::LinkSurfaceElements"); RegionTimer reg (t);
for (int i = 0; i < facedecoding.Size(); i++) for (int i = 0; i < facedecoding.Size(); i++)
facedecoding[i].firstelement = -1; facedecoding[i].firstelement = -1;
for (int i = surfelements.Size()-1; i >= 0; i--) for (int i = surfelements.Size()-1; i >= 0; i--)

View File

@ -795,8 +795,8 @@ namespace netgen
/// ///
const PointIndex & operator[] (int i) const { return pnum[i]; } const PointIndex & operator[] (int i) const { return pnum[i]; }
auto PNums () const auto PNums () const { return FlatArray<const PointIndex> (np, &pnum[0]); }
{ return FlatArray<const PointIndex> (np, &pnum[0]); } auto PNums () { return FlatArray<PointIndex> (np, &pnum[0]); }
template <int NP> template <int NP>
auto PNums() const { return FlatArray<const PointIndex> (NP, &pnum[0]); } auto PNums() const { return FlatArray<const PointIndex> (NP, &pnum[0]); }