more parallelism in netgen-topology

This commit is contained in:
Joachim Schöberl 2018-01-04 11:48:45 +01:00
parent 5469356147
commit 789305c3bc
5 changed files with 53 additions and 9 deletions

View File

@ -3622,7 +3622,7 @@ namespace netgen
mtris.SetAllocSize (mtris.Size()); mtris.SetAllocSize (mtris.Size());
mquads.SetAllocSize (mquads.Size()); mquads.SetAllocSize (mquads.Size());
(*opt.tracer)("copy tets", false);
mesh.ClearVolumeElements(); mesh.ClearVolumeElements();
mesh.VolumeElements().SetAllocSize (mtets.Size()+mprisms.Size()); mesh.VolumeElements().SetAllocSize (mtets.Size()+mprisms.Size());
for (int i = 1; i <= mtets.Size(); i++) for (int i = 1; i <= mtets.Size(); i++)
@ -3634,6 +3634,8 @@ namespace netgen
el.SetOrder (mtets.Get(i).order); el.SetOrder (mtets.Get(i).order);
mesh.AddVolumeElement (el); mesh.AddVolumeElement (el);
} }
(*opt.tracer)("copy tets", true);
for (int i = 1; i <= mprisms.Size(); i++) for (int i = 1; i <= mprisms.Size(); i++)
{ {
Element el(PRISM); Element el(PRISM);
@ -3845,7 +3847,10 @@ namespace netgen
mesh.ComputeNVertices(); mesh.ComputeNVertices();
(*opt.tracer)("call RebuildSurfElList", false);
mesh.RebuildSurfaceElementLists(); mesh.RebuildSurfaceElementLists();
(*opt.tracer)("call RebuildSurfElList", true);
// update identification tables // update identification tables
@ -4027,7 +4032,7 @@ namespace netgen
NgProfiler::StartTimer (timer3a); NgProfiler::StartTimer (timer3a);
(*opt.tracer)("topology from bisect", false); (*opt.tracer)("topology from bisect", false);
mesh.UpdateTopology(opt.task_manager); mesh.UpdateTopology(opt.task_manager, opt.tracer);
(*opt.tracer)("topology from bisect", true); (*opt.tracer)("topology from bisect", true);
NgProfiler::StopTimer (timer3a); NgProfiler::StopTimer (timer3a);

View File

@ -5768,10 +5768,13 @@ namespace netgen
return 1; return 1;
} }
void Mesh :: UpdateTopology (TaskManager tm) void Mesh :: UpdateTopology (TaskManager tm,
Tracer tracer)
{ {
topology.Update(tm); topology.Update(tm, tracer);
(*tracer)("call update clusters", false);
clusters->Update(tm); clusters->Update(tm);
(*tracer)("call update clusters", true);
#ifdef PARALLEL #ifdef PARALLEL
if (paralleltop) if (paralleltop)
{ {

View File

@ -705,7 +705,8 @@ namespace netgen
const MeshTopology & GetTopology () const const MeshTopology & GetTopology () const
{ return topology; } { return topology; }
DLL_HEADER void UpdateTopology (TaskManager tm = &DummyTaskManager); DLL_HEADER void UpdateTopology (TaskManager tm = &DummyTaskManager,
Tracer tracer = &DummyTracer);
class CurvedElements & GetCurvedElements () const class CurvedElements & GetCurvedElements () const
{ return *curvedelems; } { return *curvedelems; }

View File

@ -4,6 +4,11 @@
namespace netgen namespace netgen
{ {
template<typename T>
inline atomic<T> & AsAtomic (T & d)
{
return reinterpret_cast<atomic<T>&> (d);
}
@ -331,7 +336,7 @@ namespace netgen
} }
void MeshTopology :: Update (TaskManager tm) void MeshTopology :: Update (TaskManager tm, Tracer tracer)
{ {
static int timer = NgProfiler::CreateTimer ("topology"); static int timer = NgProfiler::CreateTimer ("topology");
NgProfiler::RegionTimer reg (timer); NgProfiler::RegionTimer reg (timer);
@ -358,7 +363,8 @@ namespace netgen
(*testout) << "nseg = " << nseg << endl; (*testout) << "nseg = " << nseg << endl;
(*testout) << "np = " << np << endl; (*testout) << "np = " << np << endl;
(*testout) << "nv = " << nv << endl; (*testout) << "nv = " << nv << endl;
(*tracer) ("Topology::Update setup tables", false);
Array<int,PointIndex::BASE> cnt(nv); Array<int,PointIndex::BASE> cnt(nv);
Array<int> vnums; Array<int> vnums;
@ -369,13 +375,26 @@ namespace netgen
vertex to segment vertex to segment
*/ */
cnt = 0; cnt = 0;
/*
for (ElementIndex ei = 0; ei < ne; ei++) for (ElementIndex ei = 0; ei < ne; ei++)
{ {
const Element & el = (*mesh)[ei]; const Element & el = (*mesh)[ei];
for (int j = 0; j < el.GetNV(); j++) for (int j = 0; j < el.GetNV(); j++)
cnt[el[j]]++; cnt[el[j]]++;
} }
*/
ParallelForRange
(tm, ne,
[&] (size_t begin, size_t end)
{
for (ElementIndex ei = begin; ei < end; ei++)
{
const Element & el = (*mesh)[ei];
for (int j = 0; j < el.GetNV(); j++)
AsAtomic(cnt[el[j]])++;
}
});
vert2element = TABLE<ElementIndex,PointIndex::BASE> (cnt); vert2element = TABLE<ElementIndex,PointIndex::BASE> (cnt);
for (ElementIndex ei = 0; ei < ne; ei++) for (ElementIndex ei = 0; ei < ne; ei++)
{ {
@ -385,12 +404,27 @@ namespace netgen
} }
cnt = 0; cnt = 0;
/*
for (SurfaceElementIndex sei = 0; sei < nse; sei++) for (SurfaceElementIndex sei = 0; sei < nse; sei++)
{ {
const Element2d & el = (*mesh)[sei]; const Element2d & el = (*mesh)[sei];
for (int j = 0; j < el.GetNV(); j++) for (int j = 0; j < el.GetNV(); j++)
cnt[el[j]]++; cnt[el[j]]++;
} }
*/
ParallelForRange
(tm, nse,
[&] (size_t begin, size_t end)
{
for (SurfaceElementIndex ei = begin; ei < end; ei++)
{
const Element2d & el = (*mesh)[ei];
for (int j = 0; j < el.GetNV(); j++)
AsAtomic(cnt[el[j]])++;
}
});
vert2surfelement = TABLE<SurfaceElementIndex,PointIndex::BASE> (cnt); vert2surfelement = TABLE<SurfaceElementIndex,PointIndex::BASE> (cnt);
for (SurfaceElementIndex sei = 0; sei < nse; sei++) for (SurfaceElementIndex sei = 0; sei < nse; sei++)
@ -430,6 +464,7 @@ namespace netgen
const Element0d & pointel = mesh->pointelements[pei]; const Element0d & pointel = mesh->pointelements[pei];
vert2pointelement.AddSave (pointel.pnum, pei); vert2pointelement.AddSave (pointel.pnum, pei);
} }
(*tracer) ("Topology::Update setup tables", true);
if (buildedges) if (buildedges)

View File

@ -83,7 +83,7 @@ public:
bool HasFaces () const bool HasFaces () const
{ return buildfaces; } { return buildfaces; }
void Update(TaskManager tm = &DummyTaskManager); void Update(TaskManager tm = &DummyTaskManager, Tracer tracer = &DummyTracer);
int GetNEdges () const { return edge2vert.Size(); } int GetNEdges () const { return edge2vert.Size(); }