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 <atomic>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "array.hpp"
|
#include "array.hpp"
|
||||||
#include "bitarray.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>
|
class NGCORE_API FilteredTableCreator : public TableCreator<int>
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
@ -6534,70 +6534,36 @@ namespace netgen
|
|||||||
|
|
||||||
Table<ElementIndex, PointIndex> Mesh :: CreatePoint2ElementTable() const
|
Table<ElementIndex, PointIndex> Mesh :: CreatePoint2ElementTable() const
|
||||||
{
|
{
|
||||||
TableCreator<ElementIndex, PointIndex> creator(GetNP());
|
return ngcore::CreateSortedTable<ElementIndex, PointIndex>( volelements.Range(),
|
||||||
for ( ; !creator.Done(); creator++)
|
[&](auto & table, ElementIndex ei)
|
||||||
ngcore::ParallelForRange
|
{
|
||||||
(Range(volelements), [&] (auto myrange)
|
|
||||||
{
|
|
||||||
for (ElementIndex ei : myrange)
|
|
||||||
for (PointIndex pi : (*this)[ei].PNums())
|
for (PointIndex pi : (*this)[ei].PNums())
|
||||||
creator.Add (pi, ei);
|
table.Add (pi, ei);
|
||||||
});
|
}, GetNP());
|
||||||
|
|
||||||
auto elementsonnode = creator.MoveTable();
|
|
||||||
ngcore::ParallelForRange
|
|
||||||
(elementsonnode.Range(), [&] (auto myrange)
|
|
||||||
{
|
|
||||||
for (PointIndex pi : myrange)
|
|
||||||
QuickSort(elementsonnode[pi]);
|
|
||||||
}, ngcore::TasksPerThread(4));
|
|
||||||
|
|
||||||
return move(elementsonnode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Table<SurfaceElementIndex, PointIndex> Mesh :: CreatePoint2SurfaceElementTable( int faceindex ) const
|
Table<SurfaceElementIndex, PointIndex> Mesh :: CreatePoint2SurfaceElementTable( int faceindex ) const
|
||||||
{
|
{
|
||||||
static Timer timer("Mesh::CreatePoint2SurfaceElementTable"); RegionTimer rt(timer);
|
static Timer timer("Mesh::CreatePoint2SurfaceElementTable"); RegionTimer rt(timer);
|
||||||
|
|
||||||
TableCreator<SurfaceElementIndex, PointIndex> creator(GetNP());
|
|
||||||
|
|
||||||
if(faceindex==0)
|
if(faceindex==0)
|
||||||
{
|
{
|
||||||
for ( ; !creator.Done(); creator++)
|
return ngcore::CreateSortedTable<SurfaceElementIndex, PointIndex>( surfelements.Range(),
|
||||||
ngcore::ParallelForRange
|
[&](auto & table, SurfaceElementIndex ei)
|
||||||
(Range(surfelements), [&] (auto myrange)
|
{
|
||||||
{
|
|
||||||
for (SurfaceElementIndex ei : myrange)
|
|
||||||
for (PointIndex pi : (*this)[ei].PNums())
|
for (PointIndex pi : (*this)[ei].PNums())
|
||||||
creator.Add (pi, ei);
|
table.Add (pi, ei);
|
||||||
},
|
}, GetNP());
|
||||||
// ngcore::TasksPerThread(4));
|
|
||||||
(surfelements.Size()>100) ? ngcore::TasksPerThread(4) : 1);
|
|
||||||
}
|
}
|
||||||
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