Memory saving opportunities for lage KDTrees
This commit is contained in:
parent
113a14e00c
commit
f0a951e38d
4 changed files with 33 additions and 10 deletions
|
@ -40,6 +40,10 @@ knowledge of the CeCILL license and that you accept its terms.
|
|||
#include "config.hpp"
|
||||
#include "bqueue.hpp"
|
||||
|
||||
#ifndef __KD_TREE_ACTIVE_CELLS
|
||||
#define __KD_TREE_ACTIVE_CELLS 1
|
||||
#endif
|
||||
|
||||
namespace CosmoTool {
|
||||
|
||||
template<int N, typename CType = ComputePrecision>
|
||||
|
@ -52,7 +56,9 @@ namespace CosmoTool {
|
|||
template<int N, typename ValType, typename CType = ComputePrecision>
|
||||
struct KDCell
|
||||
{
|
||||
#if __KD_TREE_ACTIVE_CELLS == 1
|
||||
bool active;
|
||||
#endif
|
||||
ValType val;
|
||||
typename KDDef<N,CType>::KDCoordinates coord;
|
||||
};
|
||||
|
|
|
@ -184,7 +184,9 @@ namespace CosmoTool {
|
|||
int axis = level % N;
|
||||
CoordType d2 = 0;
|
||||
|
||||
#if __KD_TREE_ACTIVE_CELLS == 1
|
||||
if (node->value->active)
|
||||
#endif
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
|
@ -229,6 +231,7 @@ namespace CosmoTool {
|
|||
uint32_t swapId = Ncells-1;
|
||||
uint32_t i = 0;
|
||||
|
||||
#if __KD_TREE_ACTIVE_CELLS == 1
|
||||
while (!cells[swapId]->active && swapId > 0)
|
||||
swapId--;
|
||||
|
||||
|
@ -244,6 +247,7 @@ namespace CosmoTool {
|
|||
}
|
||||
i++;
|
||||
}
|
||||
#endif
|
||||
return swapId+1;
|
||||
}
|
||||
|
||||
|
@ -251,7 +255,7 @@ namespace CosmoTool {
|
|||
void KD_default_cell_splitter<N,ValType,CType>::operator()(KDCell<N,ValType,CType> **cells, uint32_t Ncells, uint32_t& split_index, int axis, typename KDDef<N,CType>::KDCoordinates minBound, typename KDDef<N,CType>::KDCoordinates maxBound)
|
||||
{
|
||||
CellCompare<N,ValType,CType> compare(axis);
|
||||
std::sort(cells, cells+Ncells, compare);
|
||||
omptl::sort(cells,cells+Ncells,compare); // std::sort(cells, cells+Ncells, compare);
|
||||
split_index = Ncells/2;
|
||||
}
|
||||
|
||||
|
@ -266,10 +270,13 @@ namespace CosmoTool {
|
|||
if (Ncells == 0)
|
||||
return 0;
|
||||
|
||||
Node *node;
|
||||
int axis = depth % N;
|
||||
Node *node = &nodes[lastNode++];
|
||||
uint32_t mid;
|
||||
coords tmpBound;
|
||||
|
||||
#pragma omp critical
|
||||
node = &nodes[lastNode++];
|
||||
|
||||
// Isolate the environment
|
||||
splitter(cell0, Ncells, mid, axis, minBound, maxBound);
|
||||
|
@ -282,12 +289,20 @@ namespace CosmoTool {
|
|||
tmpBound[axis] = node->value->coord[axis];
|
||||
|
||||
depth++;
|
||||
node->children[0] = buildTree(cell0, mid, depth, minBound, tmpBound);
|
||||
#pragma omp task private(tmpBound)
|
||||
{
|
||||
node->children[0] = buildTree(cell0, mid, depth, minBound, tmpBound);
|
||||
}
|
||||
|
||||
memcpy(tmpBound, minBound, sizeof(coords));
|
||||
tmpBound[axis] = node->value->coord[axis];
|
||||
node->children[1] = buildTree(cell0+mid+1, Ncells-mid-1, depth,
|
||||
#pragma omp task private(tmpBound)
|
||||
{
|
||||
node->children[1] = buildTree(cell0+mid+1, Ncells-mid-1, depth,
|
||||
tmpBound, maxBound);
|
||||
}
|
||||
|
||||
#pragma omp taskwait
|
||||
|
||||
#ifdef __KD_TREE_NUMNODES
|
||||
node->numNodes = (node->children[0] != 0) ? node->children[0]->numNodes : 0;
|
||||
|
@ -304,7 +319,9 @@ namespace CosmoTool {
|
|||
uint32_t numActive = 0;
|
||||
for (uint32_t i = 0; i < lastNode; i++)
|
||||
{
|
||||
#if __KD_TREE_ACTIVE_CELLS == 1
|
||||
if (nodes[i].value->active)
|
||||
#endif
|
||||
numActive++;
|
||||
}
|
||||
return numActive;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue