From 69429c6e09506111054c13a753f2c7f3a630c30c Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Tue, 20 Jan 2015 17:41:16 +0000 Subject: [PATCH] occ meshing, lock in block-allocator --- libsrc/general/optmem.cpp | 49 ++++++++++++++++++++-------------- libsrc/general/optmem.hpp | 6 +++-- libsrc/meshing/meshclass.cpp | 1 - libsrc/meshing/python_mesh.cpp | 24 ++++++++--------- libsrc/occ/occgenmesh.cpp | 4 +-- 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/libsrc/general/optmem.cpp b/libsrc/general/optmem.cpp index 2fba3043..7621f22c 100644 --- a/libsrc/general/optmem.cpp +++ b/libsrc/general/optmem.cpp @@ -35,30 +35,39 @@ namespace netgen void * BlockAllocator :: Alloc () { - // return new char[size]; - if (!freelist) - { - // cout << "freelist = " << freelist << endl; - // cout << "BlockAlloc: " << size*blocks << endl; - char * hcp = new char [size * blocks]; - bablocks.Append (hcp); - bablocks.Last() = hcp; - for (unsigned i = 0; i < blocks-1; i++) - *(void**)&(hcp[i * size]) = &(hcp[ (i+1) * size]); - *(void**)&(hcp[(blocks-1)*size]) = NULL; - freelist = hcp; - } - - void * p = freelist; - freelist = *(void**)freelist; + void * p; +#pragma omp critical (BlockAllocator) + { + // return new char[size]; + if (!freelist) + { + // cout << "freelist = " << freelist << endl; + // cout << "BlockAlloc: " << size*blocks << endl; + char * hcp = new char [size * blocks]; + bablocks.Append (hcp); + bablocks.Last() = hcp; + for (unsigned i = 0; i < blocks-1; i++) + *(void**)&(hcp[i * size]) = &(hcp[ (i+1) * size]); + *(void**)&(hcp[(blocks-1)*size]) = NULL; + freelist = hcp; + } + + p = freelist; + freelist = *(void**)freelist; + } return p; } - /* void BlockAllocator :: Free (void * p) { - *(void**)p = freelist; - freelist = p; +#pragma omp critical (BlockAllocator) + { + if (bablocks.Size()) + { + *(void**)p = freelist; + freelist = p; + } + } } - */ + } diff --git a/libsrc/general/optmem.hpp b/libsrc/general/optmem.hpp index aaa02dd4..658bf055 100644 --- a/libsrc/general/optmem.hpp +++ b/libsrc/general/optmem.hpp @@ -46,13 +46,15 @@ public: /// - void Free (void * p) + void Free (void * p); + /* { if (!bablocks.Size()) return; *(void**)p = freelist; freelist = p; } - + */ + private: // void Alloc2 (); diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 651cb916..0efefb5a 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -101,7 +101,6 @@ namespace netgen { NgLock lock(mutex); lock.Lock(); - points.SetSize(0); segments.SetSize(0); surfelements.SetSize(0); diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 625ff280..d67e9180 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -69,7 +69,7 @@ DLL_HEADER void ExportNetgenMeshing() return bp::tuple(l); })) ; - + bp::class_("Element3D") .add_property("index", &Element::GetIndex, &Element::SetIndex) .add_property("vertices", @@ -82,17 +82,17 @@ DLL_HEADER void ExportNetgenMeshing() })) ; - bp::class_("Element2D") - .add_property("index", &Element2d::GetIndex, &Element2d::SetIndex) - .add_property("vertices", - FunctionPointer([](const Element2d & self) -> bp::list - { - bp::list li; - for (int i = 0; i < self.GetNV(); i++) - li.append(self[i]); - return li; - })) - ; + bp::class_("Element2D") + .add_property("index", &Element2d::GetIndex, &Element2d::SetIndex) + .add_property("vertices", + FunctionPointer([](const Element2d & self) -> bp::list + { + bp::list li; + for (int i = 0; i < self.GetNV(); i++) + li.append(self[i]); + return li; + })) + ; ExportArray(); ExportArray(); ExportArray(); diff --git a/libsrc/occ/occgenmesh.cpp b/libsrc/occ/occgenmesh.cpp index f3ebec6e..4b361ab5 100644 --- a/libsrc/occ/occgenmesh.cpp +++ b/libsrc/occ/occgenmesh.cpp @@ -1281,9 +1281,9 @@ namespace netgen if (perfstepsstart <= MESHCONST_ANALYSE) { // delete mesh; - mesh = make_shared(); + // mesh = make_shared(); mesh->geomtype = Mesh::GEOM_OCC; - + OCCSetLocalMeshSize(geom,*mesh); }