From 472073c22b9c4b739fd047cba1f94537889c5e27 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sun, 21 May 2023 14:35:09 +0200 Subject: [PATCH] counting num vertices in parallel --- libsrc/core/array.hpp | 4 ++-- libsrc/meshing/meshclass.cpp | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/libsrc/core/array.hpp b/libsrc/core/array.hpp index 7414db78..170f51b8 100644 --- a/libsrc/core/array.hpp +++ b/libsrc/core/array.hpp @@ -628,7 +628,7 @@ namespace ngcore FlatArray View (FlatArray fa) { return fa; } template - auto Max (FlatArray array, T max = std::numeric_limits::min()) -> T + auto Max (FlatArray array, typename std::remove_const::type max = std::numeric_limits::min()) -> T { for (auto & v : array) if (v > max) max = v; @@ -636,7 +636,7 @@ namespace ngcore } template - auto Min (FlatArray array, T min = std::numeric_limits::max()) -> T + auto Min (FlatArray array, typename std::remove_const::type min = std::numeric_limits::max()) -> T { for (auto & v : array) if (v < min) min = v; diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 9f230ac9..a5595b23 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -6810,8 +6810,9 @@ namespace netgen void Mesh :: ComputeNVertices () { - numvertices = 0; + numvertices = 0; + /* for (const Element & el : VolumeElements()) for (PointIndex v : el.Vertices()) if (v > numvertices) numvertices = v; @@ -6821,6 +6822,25 @@ namespace netgen if (v > numvertices) numvertices = v; numvertices += 1-PointIndex::BASE; + */ + numvertices = 0; + numvertices = + ParallelReduce (VolumeElements().Size(), + [&](size_t nr) + { + return int(Max(VolumeElements()[nr].Vertices())); + }, + [](auto a, auto b) { return a > b ? a : b; }, + numvertices); + numvertices = + ParallelReduce (SurfaceElements().Size(), + [&](size_t nr) + { + return int(Max(SurfaceElements()[nr].Vertices())); + }, + [](auto a, auto b) { return a > b ? a : b; }, + numvertices); + numvertices += 1-PointIndex::BASE; } int Mesh :: GetNV () const