diff --git a/libsrc/core/table.hpp b/libsrc/core/table.hpp index 2e6d37d6..6a851605 100644 --- a/libsrc/core/table.hpp +++ b/libsrc/core/table.hpp @@ -351,6 +351,8 @@ namespace ngcore template Table CreateTable( const TRange & range, const TFunc & func, std::optional< size_t > cnt ) { + static Timer timer("CreateTable"); + RegionTimer rt(timer); std::unique_ptr> pcreator; if(cnt) @@ -375,6 +377,8 @@ namespace ngcore template Table CreateSortedTable( const TRange & range, const TFunc & func, std::optional< size_t > cnt ) { + static Timer timer("CreateSortedTable"); + RegionTimer rt(timer); Table table = CreateTable(range, func, cnt); ParallelForRange (table.Range(), [&] (auto myrange) diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 645eb080..b63a0462 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -271,18 +271,18 @@ template <> NGX_INLINE DLL_HEADER const Ng_Node<0> Ngx_Mesh :: GetNode<0> (int v node.elements.ne = ia.Size(); node.elements.ptr = (int*)&ia[0]; - NgFlatArray bia = mesh->GetTopology().GetVertexSegments(vnr); + auto bia = mesh->GetTopology().GetVertexSegments(vnr); node.bnd_elements.ne = bia.Size(); node.bnd_elements.ptr = (int*)&bia[0]; break; } case 1: { - NgFlatArray ia = mesh->GetTopology().GetVertexSegments(vnr); + auto ia = mesh->GetTopology().GetVertexSegments(vnr); node.elements.ne = ia.Size(); node.elements.ptr = (int*)&ia[0]; - NgFlatArray bia = mesh->GetTopology().GetVertexPointElements(vnr); + auto bia = mesh->GetTopology().GetVertexPointElements(vnr); node.bnd_elements.ne = bia.Size(); node.bnd_elements.ptr = (int*)&bia[0]; break; diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 5b329569..24da6783 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -1653,7 +1653,7 @@ void Ng_GetVertexElements (int vnr, int * els) } case 1: { - NgFlatArray ia = mesh->GetTopology().GetVertexSegments(vnr); + auto ia = mesh->GetTopology().GetVertexSegments(vnr); for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; break; /* diff --git a/libsrc/meshing/clusters.cpp b/libsrc/meshing/clusters.cpp index dae820df..97e77e36 100644 --- a/libsrc/meshing/clusters.cpp +++ b/libsrc/meshing/clusters.cpp @@ -16,13 +16,13 @@ namespace netgen ; } - void AnisotropicClusters :: Update(NgTaskManager tm, NgTracer tracer) + void AnisotropicClusters :: Update() { - static int timer = NgProfiler::CreateTimer ("clusters"); + static Timer timer("clusters"); // static int timer1 = NgProfiler::CreateTimer ("clusters1"); // static int timer2 = NgProfiler::CreateTimer ("clusters2"); // static int timer3 = NgProfiler::CreateTimer ("clusters3"); - NgProfiler::RegionTimer reg (timer); + RegionTimer reg (timer); const MeshTopology & top = mesh.GetTopology(); @@ -81,13 +81,14 @@ namespace netgen cluster_reps.Elem(nnums[j]) = nnums[j]; } */ - ParallelForRange - (tm, ne, - [&] (size_t begin, size_t end) + ngcore::ParallelForRange + (mesh.VolumeElements().Range(), + [&] (auto myrange) { NgArray nnums, ednums, fanums; - for (int i = begin+1; i <= end; i++) + for (int i_ : myrange) { + int i = i_+1; const Element & el = mesh.VolumeElement(i); ELEMENT_TYPE typ = el.GetType(); @@ -110,7 +111,7 @@ namespace netgen for (int j = 0; j < nnums.Size(); j++) cluster_reps.Elem(nnums[j]) = nnums[j]; } - }); + }, ngcore::TasksPerThread(4)); // NgProfiler::StopTimer(timer1); // NgProfiler::StartTimer(timer2); @@ -137,13 +138,14 @@ namespace netgen cluster_reps.Elem(nnums[j]) = nnums[j]; } */ - ParallelForRange - (tm, nse, - [&] (size_t begin, size_t end) + ngcore::ParallelForRange + (mesh.SurfaceElements().Range(), + [&] (auto myrange) { NgArrayMem nnums, ednums; - for (int i = begin+1; i <= end; i++) + for (int i_ : myrange) { + int i = i_+1; const Element2d & el = mesh.SurfaceElement(i); ELEMENT_TYPE typ = el.GetType(); @@ -163,7 +165,7 @@ namespace netgen for (int j = 0; j < nnums.Size(); j++) cluster_reps.Elem(nnums[j]) = nnums[j]; } - }); + }, ngcore::TasksPerThread(4)); // NgProfiler::StopTimer(timer2); @@ -215,7 +217,8 @@ namespace netgen do { - (*tracer) ("update cluster, identify", false); + static Timer t("update cluster, identify"); + RegionTimer rtr(t); cnt++; changed = 0; @@ -338,7 +341,6 @@ namespace netgen } */ } - (*tracer) ("update cluster, identify", true); } while (changed); // NgProfiler::StopTimer(timer3); diff --git a/libsrc/meshing/clusters.hpp b/libsrc/meshing/clusters.hpp index 21e122fb..21854f39 100644 --- a/libsrc/meshing/clusters.hpp +++ b/libsrc/meshing/clusters.hpp @@ -27,7 +27,7 @@ public: AnisotropicClusters (const Mesh & amesh); ~AnisotropicClusters(); - void Update(NgTaskManager tm = &DummyTaskManager, NgTracer trace = &DummyTracer); + void Update(); int GetVertexRepresentant (int vnr) const { return cluster_reps.Get(vnr); } diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index d9fc8fb7..c31a6a2c 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -916,6 +916,7 @@ namespace netgen void Mesh :: Load (istream & infile) { + static Timer timer("Mesh::Load"); RegionTimer rt(timer); if (! (infile.good()) ) { cout << "cannot load mesh" << endl; @@ -956,6 +957,7 @@ namespace netgen if (strcmp (str, "surfaceelements") == 0 || strcmp (str, "surfaceelementsgi")==0 || strcmp (str, "surfaceelementsuv") == 0) { + static Timer t1("read surface elements"); RegionTimer rt1(t1); infile >> n; PrintMessage (3, n, " surface elements"); @@ -1020,6 +1022,7 @@ namespace netgen if (strcmp (str, "volumeelements") == 0) { + static Timer t1("read volume elements"); RegionTimer rt1(t1); infile >> n; PrintMessage (3, n, " volume elements"); for (i = 1; i <= n; i++) @@ -1045,6 +1048,7 @@ namespace netgen if (strcmp (str, "edgesegments") == 0) { + static Timer t1("read edge segments"); RegionTimer rt1(t1); infile >> n; for (i = 1; i <= n; i++) { @@ -1059,6 +1063,7 @@ namespace netgen if (strcmp (str, "edgesegmentsgi") == 0) { + static Timer t1("read edge segmentsgi"); RegionTimer rt1(t1); infile >> n; for (i = 1; i <= n; i++) { @@ -1073,6 +1078,7 @@ namespace netgen if (strcmp (str, "edgesegmentsgi2") == 0) { + static Timer t1("read edge segmentsgi2"); RegionTimer rt1(t1); int a; infile >> a; n=a; @@ -1106,6 +1112,7 @@ namespace netgen if (strcmp (str, "points") == 0) { + static Timer t1("read points"); RegionTimer rt1(t1); infile >> n; PrintMessage (3, n, " points"); for (i = 1; i <= n; i++) @@ -1122,6 +1129,7 @@ namespace netgen if (strcmp (str, "pointelements") == 0) { + static Timer t1("read point elements"); RegionTimer rt1(t1); infile >> n; PrintMessage (3, n, " pointelements"); for (i = 1; i <= n; i++) @@ -6698,7 +6706,7 @@ namespace netgen static Timer t("Update Topology"); RegionTimer reg(t); topology.Update(tm, tracer); (*tracer)("call update clusters", false); - clusters->Update(tm, tracer); + clusters->Update(); (*tracer)("call update clusters", true); #ifdef PARALLEL if (paralleltop) diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index e0c1ccf3..95122a11 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -5,6 +5,7 @@ namespace netgen { using ngcore::ParallelForRange; using ngcore::INT; + using ngcore::TasksPerThread; template void QuickSortRec (NgFlatArray data, @@ -367,6 +368,7 @@ namespace netgen void MeshTopology :: Update (NgTaskManager tm_unused, NgTracer tracer) { static Timer timer("Topology::Update"); + static Timer timer_tables("Build vertex to element table"); RegionTimer reg (timer); #ifdef PARALLEL @@ -405,46 +407,34 @@ namespace netgen vertex to segment */ + timer_tables.Start(); vert2element = mesh->CreatePoint2ElementTable(); vert2surfelement = mesh->CreatePoint2SurfaceElementTable(0); - cnt = 0; - for (SegmentIndex si = 0; si < nseg; si++) - { - const Segment & seg = mesh->LineSegment(si); - cnt[seg[0]]++; - cnt[seg[1]]++; - } - - vert2segment = TABLE (cnt); - for (SegmentIndex si = 0; si < nseg; si++) - { - const Segment & seg = mesh->LineSegment(si); - vert2segment.AddSave (seg[0], si); - vert2segment.AddSave (seg[1], si); - } + vert2segment = ngcore::CreateSortedTable( mesh->LineSegments().Range(), + [&](auto & table, SegmentIndex segi) + { + const Segment & seg = (*mesh)[segi]; + table.Add (seg[0], segi); + table.Add (seg[1], segi); + }, np); + + vert2pointelement = ngcore::CreateSortedTable( mesh->pointelements.Range(), + [&](auto & table, int pei) + { + const Element0d & pointel = mesh->pointelements[pei]; + table.Add(pointel.pnum, pei); + }, np); + timer_tables.Stop(); - cnt = 0; - for (int pei = 0; pei < mesh->pointelements.Size(); pei++) - { - const Element0d & pointel = mesh->pointelements[pei]; - cnt[pointel.pnum]++; - } - - vert2pointelement = TABLE (cnt); - for (int pei = 0; pei < mesh->pointelements.Size(); pei++) - { - const Element0d & pointel = mesh->pointelements[pei]; - vert2pointelement.AddSave (pointel.pnum, pei); - } (*tracer) ("Topology::Update setup tables", true); if (buildedges) { - static int timer1 = NgProfiler::CreateTimer ("topology::buildedges"); - NgProfiler::RegionTimer reg1 (timer1); + static Timer timer1("topology::buildedges"); + RegionTimer reg1(timer1); if (id == 0) PrintMessage (5, "Update edges "); @@ -535,7 +525,7 @@ namespace netgen }); cnt[v] = cnti; } - } ); + }, TasksPerThread(4) ); // accumulate number of edges int ned = edge2vert.Size(); @@ -624,7 +614,7 @@ namespace netgen } }); } - } ); + }, TasksPerThread(4) ); if (build_parent_edges) @@ -907,12 +897,12 @@ namespace netgen // generate faces if (buildfaces) { - static int timer2 = NgProfiler::CreateTimer ("topology::buildfaces"); + static Timer timer2("topology::buildfaces"); // static int timer2a = NgProfiler::CreateTimer ("topology::buildfacesa"); // static int timer2b = NgProfiler::CreateTimer ("topology::buildfacesb"); // static int timer2b1 = NgProfiler::CreateTimer ("topology::buildfacesb1"); // static int timer2c = NgProfiler::CreateTimer ("topology::buildfacesc"); - NgProfiler::RegionTimer reg2 (timer2); + RegionTimer reg2 (timer2); if (id == 0) PrintMessage (5, "Update faces "); @@ -1051,7 +1041,7 @@ namespace netgen }); cnt[v] = cnti; } - } ); + }, TasksPerThread(4) ); // NgProfiler::StopTimer (timer2b1); // accumulate number of faces @@ -1156,7 +1146,7 @@ namespace netgen } }); } - }); + }, TasksPerThread(4) ); /* int oldnfa = face2vert.Size(); @@ -1485,7 +1475,7 @@ namespace netgen for (auto f : hfaces) AsAtomic(face_els[f-1])++; } - }); + }, TasksPerThread(4)); for (int i = 1; i <= nse; i++) face_surfels[GetSurfaceElementFace (i)-1]++; (*tracer) ("Topology::Update count face_els", true); diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index 9ce2e47a..e6bcf76f 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -67,8 +67,8 @@ class MeshTopology Array edge2segment; Table vert2element; Table vert2surfelement; - TABLE vert2segment; - TABLE vert2pointelement; + Table vert2segment; + Table vert2pointelement; int timestamp; public: int GetNSurfedges() const {return surfedges.Size();} @@ -183,10 +183,10 @@ public: FlatArray GetVertexSurfaceElements(PointIndex vnr) const { return vert2surfelement[vnr]; } - NgFlatArray GetVertexSegments (int vnr) const + FlatArray GetVertexSegments (int vnr) const { return vert2segment[vnr]; } - NgFlatArray GetVertexPointElements (int vnr) const + FlatArray GetVertexPointElements (int vnr) const { return vert2pointelement[vnr]; } int GetVerticesEdge ( int v1, int v2) const;