diff --git a/libsrc/core/python_ngcore.hpp b/libsrc/core/python_ngcore.hpp index 6bedabf9..a089c5e8 100644 --- a/libsrc/core/python_ngcore.hpp +++ b/libsrc/core/python_ngcore.hpp @@ -11,6 +11,7 @@ #include "archive.hpp" #include "flags.hpp" #include "ngcore_api.hpp" +#include "profiler.hpp" namespace py = pybind11; namespace ngcore @@ -297,18 +298,25 @@ namespace ngcore { PyArchive ar; ar & self; + static Timer t("ngspickle 2"); + t.Start(); auto output = pybind11::make_tuple(ar.WriteOut()); + t.Stop(); + /* GetLogger("Archive")->trace("Pickling output for object of type {} = {}", Demangle(typeid(T).name()), std::string(pybind11::str(output))); + */ return output; }, [](const pybind11::tuple & state) { T* val = nullptr; + /* GetLogger("Archive")->trace("State for unpickling of object of type {} = {}", Demangle(typeid(T).name()), std::string(pybind11::str(state[0]))); + */ PyArchive ar(state[0]); ar & val; return val; diff --git a/libsrc/general/parthreads.hpp b/libsrc/general/parthreads.hpp index 2e242484..d7f42a4a 100644 --- a/libsrc/general/parthreads.hpp +++ b/libsrc/general/parthreads.hpp @@ -96,8 +96,8 @@ void ParallelFor( int first, int next, const TFunc & f ) - typedef void (*TaskManager)(std::function); - typedef void (*Tracer)(string, bool); // false .. start, true .. stop + typedef void (*NgTaskManager)(std::function); + typedef void (*NgTracer)(string, bool); // false .. start, true .. stop inline void DummyTaskManager (std::function func) { @@ -108,7 +108,7 @@ void ParallelFor( int first, int next, const TFunc & f ) inline void DummyTracer (string, bool) { ; } template - inline void ParallelFor (TaskManager tm, size_t n, FUNC func) + inline void ParallelFor (NgTaskManager tm, size_t n, FUNC func) { (*tm) ([n,func] (size_t nr, size_t nums) { @@ -121,7 +121,7 @@ void ParallelFor( int first, int next, const TFunc & f ) } template - inline void ParallelForRange (TaskManager tm, size_t n, FUNC func) + inline void ParallelForRange (NgTaskManager tm, size_t n, FUNC func) { (*tm) ([n,func] (size_t nr, size_t nums) { diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index e06d83eb..e2501ab4 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -1157,7 +1157,7 @@ namespace netgen void Ngx_Mesh :: Refine (NG_REFINEMENT_TYPE reftype, void (*task_manager)(function), - Tracer tracer) + NgTracer tracer) { NgLock meshlock (mesh->MajorMutex(), 1); diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index 9b5c770f..1f9bbba8 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -1681,7 +1681,7 @@ namespace netgen int MarkHangingTets (T_MTETS & mtets, const INDEX_2_CLOSED_HASHTABLE & cutedges, - TaskManager tm) + NgTaskManager tm) { static int timer = NgProfiler::CreateTimer ("MarkHangingTets"); NgProfiler::RegionTimer reg (timer); @@ -1759,7 +1759,7 @@ namespace netgen bool MarkHangingTris (T_MTRIS & mtris, const INDEX_2_CLOSED_HASHTABLE & cutedges, - TaskManager tm) + NgTaskManager tm) { bool hanging = false; // for (int i = 1; i <= mtris.Size(); i++) diff --git a/libsrc/meshing/bisect.hpp b/libsrc/meshing/bisect.hpp index 6b96bd07..16849227 100644 --- a/libsrc/meshing/bisect.hpp +++ b/libsrc/meshing/bisect.hpp @@ -12,8 +12,8 @@ public: int usemarkedelements; bool refine_hp; bool refine_p; - TaskManager task_manager = &DummyTaskManager; - Tracer tracer = &DummyTracer; + NgTaskManager task_manager = &DummyTaskManager; + NgTracer tracer = &DummyTracer; DLL_HEADER BisectionOptions (); }; diff --git a/libsrc/meshing/clusters.cpp b/libsrc/meshing/clusters.cpp index dafe81f8..dae820df 100644 --- a/libsrc/meshing/clusters.cpp +++ b/libsrc/meshing/clusters.cpp @@ -16,7 +16,7 @@ namespace netgen ; } - void AnisotropicClusters :: Update(TaskManager tm, Tracer tracer) + void AnisotropicClusters :: Update(NgTaskManager tm, NgTracer tracer) { static int timer = NgProfiler::CreateTimer ("clusters"); // static int timer1 = NgProfiler::CreateTimer ("clusters1"); diff --git a/libsrc/meshing/clusters.hpp b/libsrc/meshing/clusters.hpp index bf9a5a56..21e122fb 100644 --- a/libsrc/meshing/clusters.hpp +++ b/libsrc/meshing/clusters.hpp @@ -27,7 +27,7 @@ public: AnisotropicClusters (const Mesh & amesh); ~AnisotropicClusters(); - void Update(TaskManager tm = &DummyTaskManager, Tracer trace = &DummyTracer); + void Update(NgTaskManager tm = &DummyTaskManager, NgTracer trace = &DummyTracer); int GetVertexRepresentant (int vnr) const { return cluster_reps.Get(vnr); } diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 2eacb717..5229f5d2 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -1280,10 +1280,14 @@ namespace netgen void Mesh :: DoArchive (Archive & archive) { + static Timer t("Mesh::Archive"); RegionTimer r(t); + static Timer tvol("Mesh::Archive vol elements"); archive & dimension; archive & points; archive & surfelements; + tvol.Start(); archive & volelements; + tvol.Stop(); archive & segments; archive & facedecoding; archive & materials & bcnames & cd2names & cd3names; @@ -6417,8 +6421,8 @@ namespace netgen return 1; } - void Mesh :: UpdateTopology (TaskManager tm, - Tracer tracer) + void Mesh :: UpdateTopology (NgTaskManager tm, + NgTracer tracer) { static Timer t("Update Topology"); RegionTimer reg(t); topology.Update(tm, tracer); diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 4ff21ae8..5139cb8c 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -777,8 +777,8 @@ namespace netgen const MeshTopology & GetTopology () const { return topology; } - DLL_HEADER void UpdateTopology (TaskManager tm = &DummyTaskManager, - Tracer tracer = &DummyTracer); + DLL_HEADER void UpdateTopology (NgTaskManager tm = &DummyTaskManager, + NgTracer tracer = &DummyTracer); class CurvedElements & GetCurvedElements () const { return *curvedelems; } diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index a7edcec5..0d0877b0 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -11,6 +11,15 @@ // #include // #include #include <../interface/writeuser.hpp> +#include <../include/nginterface.h> + + +class ClearSolutionClass +{ +public: + ClearSolutionClass() { } + ~ClearSolutionClass() { Ng_ClearSolutionData(); } +}; #ifdef NG_MPI4PY @@ -1238,6 +1247,10 @@ grow_edges : bool = False }, py::arg("quads")=true, py::arg("nx")=10, py::arg("ny")=10, py::arg("flip_triangles")=false, py::arg("bbbpts")=py::list(), py::arg("bbbnames")=py::list()) ; ; + + py::class_ (m, "ClearSolutionClass") + .def(py::init<>()) + ; } PYBIND11_MODULE(libmesh, m) { diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index 6fd54b8b..65dca902 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -3,7 +3,8 @@ namespace netgen { - + using ngcore::ParallelForRange; + template void QuickSortRec (NgFlatArray data, @@ -332,10 +333,10 @@ namespace netgen } - void MeshTopology :: Update (TaskManager tm, Tracer tracer) + void MeshTopology :: Update (NgTaskManager tm_unused, NgTracer tracer) { - static int timer = NgProfiler::CreateTimer ("topology"); - NgProfiler::RegionTimer reg (timer); + static Timer timer("Topology::Update"); + RegionTimer reg (timer); #ifdef PARALLEL // ParallelMeshTopology & paralleltop = mesh.GetParallelTopology(); @@ -382,10 +383,9 @@ namespace netgen } */ ParallelForRange - (tm, ne, - [&] (size_t begin, size_t end) + (ne, [&] (IntRange r) { - for (ElementIndex ei = begin; ei < end; ei++) + for (ElementIndex ei : r) { const Element & el = (*mesh)[ei]; for (int j = 0; j < el.GetNV(); j++) @@ -426,10 +426,10 @@ namespace netgen } */ ParallelForRange - (tm, nse, - [&] (size_t begin, size_t end) + (nse, + [&] (IntRange r) { - for (SurfaceElementIndex ei = begin; ei < end; ei++) + for (SurfaceElementIndex ei : r) { const Element2d & el = (*mesh)[ei]; for (int j = 0; j < el.GetNV(); j++) @@ -553,9 +553,11 @@ namespace netgen cnt = 0; ParallelForRange - (tm, mesh->GetNV(), // Points().Size(), - [&] (size_t begin, size_t end) + (mesh->GetNV(), // Points().Size(), + [&] (IntRange r) { + auto begin = r.First(); + auto end = r.Next(); INDEX_CLOSED_HASHTABLE v2eht(2*max_edge_on_vertex+10); for (PointIndex v = begin+PointIndex::BASE; v < end+PointIndex::BASE; v++) @@ -607,9 +609,11 @@ namespace netgen // for (PointIndex v = PointIndex::BASE; v < nv+PointIndex::BASE; v++) ParallelForRange - (tm, mesh->GetNV(), // Points().Size(), - [&] (size_t begin, size_t end) + (mesh->GetNV(), // Points().Size(), + [&] (IntRange r) { + auto begin = r.First(); + auto end = r.Next(); INDEX_CLOSED_HASHTABLE v2eht(2*max_edge_on_vertex+10); NgArray vertex2; for (PointIndex v = begin+PointIndex::BASE; @@ -731,9 +735,11 @@ namespace netgen // for (auto v : mesh.Points().Range()) // NgProfiler::StartTimer (timer2b1); ParallelForRange - (tm, mesh->GetNV(), // Points().Size(), - [&] (size_t begin, size_t end) + (mesh->GetNV(), // Points().Size(), + [&] (IntRange r) { + auto begin = r.First(); + auto end = r.Next(); INDEX_3_CLOSED_HASHTABLE vert2face(2*max_face_on_vertex+10); for (PointIndex v = begin+PointIndex::BASE; v < end+PointIndex::BASE; v++) @@ -779,9 +785,11 @@ namespace netgen // for (auto v : mesh.Points().Range()) ParallelForRange - (tm, mesh->GetNV(), // Points().Size(), - [&] (size_t begin, size_t end) + (mesh->GetNV(), // Points().Size(), + [&] (IntRange r) { + auto begin = r.First(); + auto end = r.Next(); INDEX_3_CLOSED_HASHTABLE vert2face(2*max_face_on_vertex+10); for (PointIndex v = begin+PointIndex::BASE; v < end+PointIndex::BASE; v++) @@ -1164,11 +1172,11 @@ namespace netgen } */ ParallelForRange - (tm, ne, - [&] (size_t begin, size_t end) + (ne, + [&] (IntRange r) { NgArray hfaces; - for (ElementIndex ei = begin; ei < end; ei++) + for (ElementIndex ei : r) { GetElementFaces (ei+1, hfaces); for (auto f : hfaces) diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index 8335f101..00f599f6 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -81,7 +81,7 @@ public: bool HasFaces () const { return buildfaces; } - void Update(TaskManager tm = &DummyTaskManager, Tracer tracer = &DummyTracer); + void Update(NgTaskManager tm = &DummyTaskManager, NgTracer tracer = &DummyTracer); bool NeedsUpdate() const; diff --git a/python/__init__.py b/python/__init__.py index e7c23d66..17dbdbe1 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -22,3 +22,5 @@ def Redraw(*args, **kwargs): cnt += 1 except: pass + + diff --git a/python/meshing.py b/python/meshing.py index 788f248a..9b912b66 100644 --- a/python/meshing.py +++ b/python/meshing.py @@ -59,3 +59,6 @@ class _MeshsizeObject: optsteps3d=5) meshsize = _MeshsizeObject() + + +clearsol = ClearSolutionClass()