mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
helper functions for table creation
This commit is contained in:
parent
955eaa682c
commit
4b53c63fba
@ -9,6 +9,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
|
||||
#include "array.hpp"
|
||||
#include "bitarray.hpp"
|
||||
@ -347,6 +348,45 @@ namespace ngcore
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TEntry, typename TIndex, typename TRange, typename TFunc>
|
||||
Table<TEntry, TIndex> CreateTable( const TRange & range, const TFunc & func, std::optional< size_t > cnt )
|
||||
{
|
||||
std::unique_ptr<TableCreator<TEntry, TIndex>> pcreator;
|
||||
|
||||
if(cnt)
|
||||
pcreator = std::make_unique<TableCreator<TEntry, TIndex>>(*cnt);
|
||||
else
|
||||
pcreator = std::make_unique<TableCreator<TEntry, TIndex>>();
|
||||
|
||||
auto & creator = *pcreator;
|
||||
|
||||
for ( ; !creator.Done(); creator++)
|
||||
ParallelForRange
|
||||
(range, [&] (auto myrange)
|
||||
{
|
||||
for (auto i : myrange)
|
||||
func(creator, i);
|
||||
}, TasksPerThread(4)
|
||||
);
|
||||
|
||||
return creator.MoveTable();
|
||||
}
|
||||
|
||||
template <typename TEntry, typename TIndex, typename TRange, typename TFunc>
|
||||
Table<TEntry, TIndex> CreateSortedTable( const TRange & range, const TFunc & func, std::optional< size_t > cnt )
|
||||
{
|
||||
Table<TEntry, TIndex> table = CreateTable<TEntry, TIndex>(range, func, cnt);
|
||||
ParallelForRange
|
||||
(table.Range(), [&] (auto myrange)
|
||||
{
|
||||
for (auto i : myrange)
|
||||
QuickSort(table[i]);
|
||||
}, TasksPerThread(4)
|
||||
);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
class NGCORE_API FilteredTableCreator : public TableCreator<int>
|
||||
{
|
||||
protected:
|
||||
|
@ -6534,70 +6534,36 @@ namespace netgen
|
||||
|
||||
Table<ElementIndex, PointIndex> Mesh :: CreatePoint2ElementTable() const
|
||||
{
|
||||
TableCreator<ElementIndex, PointIndex> creator(GetNP());
|
||||
for ( ; !creator.Done(); creator++)
|
||||
ngcore::ParallelForRange
|
||||
(Range(volelements), [&] (auto myrange)
|
||||
{
|
||||
for (ElementIndex ei : myrange)
|
||||
return ngcore::CreateSortedTable<ElementIndex, PointIndex>( volelements.Range(),
|
||||
[&](auto & table, ElementIndex ei)
|
||||
{
|
||||
for (PointIndex pi : (*this)[ei].PNums())
|
||||
creator.Add (pi, ei);
|
||||
});
|
||||
|
||||
auto elementsonnode = creator.MoveTable();
|
||||
ngcore::ParallelForRange
|
||||
(elementsonnode.Range(), [&] (auto myrange)
|
||||
{
|
||||
for (PointIndex pi : myrange)
|
||||
QuickSort(elementsonnode[pi]);
|
||||
}, ngcore::TasksPerThread(4));
|
||||
|
||||
return move(elementsonnode);
|
||||
table.Add (pi, ei);
|
||||
}, GetNP());
|
||||
}
|
||||
|
||||
Table<SurfaceElementIndex, PointIndex> Mesh :: CreatePoint2SurfaceElementTable( int faceindex ) const
|
||||
{
|
||||
static Timer timer("Mesh::CreatePoint2SurfaceElementTable"); RegionTimer rt(timer);
|
||||
|
||||
TableCreator<SurfaceElementIndex, PointIndex> creator(GetNP());
|
||||
|
||||
if(faceindex==0)
|
||||
{
|
||||
for ( ; !creator.Done(); creator++)
|
||||
ngcore::ParallelForRange
|
||||
(Range(surfelements), [&] (auto myrange)
|
||||
{
|
||||
for (SurfaceElementIndex ei : myrange)
|
||||
return ngcore::CreateSortedTable<SurfaceElementIndex, PointIndex>( surfelements.Range(),
|
||||
[&](auto & table, SurfaceElementIndex ei)
|
||||
{
|
||||
for (PointIndex pi : (*this)[ei].PNums())
|
||||
creator.Add (pi, ei);
|
||||
},
|
||||
// ngcore::TasksPerThread(4));
|
||||
(surfelements.Size()>100) ? ngcore::TasksPerThread(4) : 1);
|
||||
table.Add (pi, ei);
|
||||
}, GetNP());
|
||||
}
|
||||
else
|
||||
{
|
||||
Array<SurfaceElementIndex> face_els;
|
||||
GetSurfaceElementsOfFace(faceindex, face_els);
|
||||
for ( ; !creator.Done(); creator++)
|
||||
ngcore::ParallelForRange
|
||||
(Range(face_els), [&] (auto myrange)
|
||||
{
|
||||
for (auto i : myrange)
|
||||
for (PointIndex pi : (*this)[face_els[i]].PNums())
|
||||
creator.Add (pi, face_els[i]);
|
||||
}, ngcore::TasksPerThread(4));
|
||||
}
|
||||
|
||||
auto elementsonnode = creator.MoveTable();
|
||||
ngcore::ParallelForRange
|
||||
(elementsonnode.Range(), [&] (auto myrange)
|
||||
{
|
||||
for (PointIndex pi : myrange)
|
||||
QuickSort(elementsonnode[pi]);
|
||||
},
|
||||
(surfelements.Size()>100) ? ngcore::TasksPerThread(1) : 1);
|
||||
|
||||
return move(elementsonnode);
|
||||
Array<SurfaceElementIndex> face_els;
|
||||
GetSurfaceElementsOfFace(faceindex, face_els);
|
||||
return ngcore::CreateSortedTable<SurfaceElementIndex, PointIndex>( face_els.Range(),
|
||||
[&](auto & table, size_t i)
|
||||
{
|
||||
for (PointIndex pi : (*this)[face_els[i]].PNums())
|
||||
table.Add (pi, face_els[i]);
|
||||
}, GetNP());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user