Trying to make the balanced case work

This commit is contained in:
vasiloglou
2007-05-29 14:27:12 +00:00
parent 364383cf6f
commit bd7b5d66bd
7 changed files with 41 additions and 40 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ class BinaryDataset {
it.current_pos_+=i;
DEBUG_ASSERT_MSG(it.current_pos_<set_.get_num_of_points(),
"iterator out of bounds "LI">="LI"\n",
it.current_pos_, set_.get_num_of_points());
it.current_pos_, set_->get_num_of_points());
return it;
}
Iterator operator--() {
@@ -30,13 +30,13 @@ void MEMORY_MANAGER__::Init() {
fd = open ("/dev/zero", O_RDONLY);
cache_ = (char *)mmap (NULL, alloc_size_,
PROT_WRITE, MAP_PRIVATE, fd, 0);
if (mlock(cache_, alloc_size_) == -1) {
/* if (mlock(cache_, alloc_size_) == -1) {
NONFATAL("Could not lock memory manger's cache, error %s\n",
strerror(errno));
const char *temp="Memory manager proceeds with unlocked memory,"
"this may slow down performance\n" ;
NONFATAL(temp);
}
}*/
close(fd);
page_modified_ = new bool[num_of_pages_];
memset(page_modified_, false, num_of_pages_);
@@ -152,12 +152,12 @@ void MEMORY_MANAGER__::Load() {
// as write-only, initially.
fd = open ("/dev/zero", O_RDONLY);
cache_ = (char *)mmap (NULL, alloc_size_, PROT_WRITE, MAP_PRIVATE, fd, 0);
if (mlock(cache_, alloc_size_)==-1) {
/*if (mlock(cache_, alloc_size_)==-1) {
NONFATAL("Could not lock memory manager's cache, error %s\n",
strerror(errno));
NONFATAL("Memory manager proceeds with unlocked memory,"
"this may slow down performance\n");
}
}*/
close (fd);
page_modified_ = new bool[num_of_pages_];
memset(page_modified_, false, num_of_pages_);
@@ -210,11 +210,11 @@ void MEMORY_MANAGER__::Destruct() {
delete []cache_to_page_;
delete []page_locks_;
// delete cache
if (unlikely(munlock(cache_, alloc_size_)==-1)) {
/*if (unlikely(munlock(cache_, alloc_size_)==-1)) {
NONFATAL("Could not unlock memory manger's cache, error %s\n",
strerror(errno));
NONFATAL("Continue execution\n");
}
}*/
munmap(cache_, alloc_size_);
delete []page_modified_;
// Before closing the file we update the number of total ram pages
@@ -1,7 +1,14 @@
binrule(
name="memcomp",
name="memcomp1",
sources=["main.cc"],
linkables = ["fastlib:fastlib", "u/nvasil/mmanager:mmapmm",
"u/nvasil/mmanager_with_tpie:tpiemm",
"u/nvasil/tree:binarytree"]
deplibs = ["fastlib:fastlib", "u/nvasil/mmanager:mmapmm",
"u/nvasil/mmanager_with_tpie:tpiemm",
"u/nvasil/tree:binarytree"]
)
binrule(
name="memcomp2",
sources=["main.cc"],
deplibss = ["fastlib:fastlib", "u/nvasil/mmanager:mmapmm",
"u/nvasil/mmanager_with_tpie:tpiemm",
"u/nvasil/tree:binarytree"]
)
+5 -4
View File
@@ -209,11 +209,12 @@ void TREE__::NearestNeighbor(POINTTYPE test_point,
vector<pair<typename TREE__::Precision_t,
typename TREE__::Point_t> > *nearest_point,
NEIGHBORTYPE range) {
LOKI_STATIC_CHECK((NodeInitializerTrait<Node_t::SpecialId>::IsItGoodForRangeNN &&
Loki::TypeTraits<NEIGHBORTYPE>::isStdFloat==true) ||
Loki::TypeTraits<NEIGHBORTYPE>::isStdFloat==false,
You_are_using_the_wrong_node_probably_KnnNode_instead_of_Node);
LOKI_STATIC_CHECK((NodeInitializerTrait<Node_t::kSpecialId>::IsItGoodForRangeNN &&
Loki::TypeTraits<NEIGHBORTYPE>::isStdFloat==true) ||
Loki::TypeTraits<NEIGHBORTYPE>::isStdFloat==false,
You_are_using_the_wrong_node_probably_KnnNode_instead_of_Node);
bool found = false;
NearestNeighbor(parent_,
test_point,
+5 -2
View File
@@ -314,7 +314,10 @@ struct NodeParameters2 {
typedef NullStatistics<Loki::NullType> NodeCachedStatistics_t;
typedef SimpleDiscriminator PointIdDiscriminator_t;
};
struct TreeParameters2 {
typedef Node<NodeParameters2, false> Node_t;
typedef KdPivoter1<BasicTypes2, false> Pivot_t;
};
struct TreeParameters3 {
typedef Node<NodeParameters1, false> Node_t;
typedef KdPivoter2<BasicTypes1, false> Pivot_t;
@@ -328,7 +331,7 @@ struct TreeParameters4 {
typedef BinaryTreeTest<TreeParameters1, false> BinaryTreeTest1_t;
typedef BinaryTreeTest<TreeParameters2, false> BinaryTreeTest2_t;
typedef BinaryTreeTest<TreeParameters3, false> BinaryTreeTest3_t;
typedef BinaryTreeTest<TreeParameters4, false> BinaryTreeTest4_t;
//typedef BinaryTreeTest<TreeParameters4, false> BinaryTreeTest4_t;
int main(int argc, char *argv[]) {
BinaryTreeTest1_t test1;
+11 -21
View File
@@ -21,7 +21,7 @@
#include "fastlib/fastlib.h"
#include "u/nvasil/dataset/binary_dataset.h"
#include "hyper_rectangle.h"
#include "u/nvasil/tree/hyper_rectangle.h"
using namespace std;
template<typename TYPELIST, bool diagnostic>
class KdPivoter2 {
@@ -50,7 +50,7 @@ class KdPivoter2 {
}
bool operator()(const CompletePoint<Precision_t> &p1,
const CompletePoint<Precision_t> &p2) const {
return p1[pivot_dimension_]<p2[pivot_dimension_]'
return p1[pivot_dimension_]<p2[pivot_dimension_];
}
private:
index_t pivot_dimension_;
@@ -61,38 +61,28 @@ class KdPivoter2 {
pair<PivotInfo*, PivotInfo*> operator()(PivotInfo *pivot) {
int32 dimension = data_->get_dimension();
int32 max_range_dimension = pivot->box_.get_pivot_dimension();
index_t left_points = pivot->num_of_points_/2;
index_t right_points = pivot->num_of_points_ - left_points;
BinaryDataset<Precision_t>::Iterator it=data_.Begin()+left_points;
typename BinaryDataset<Precision_t>::Iterator it=
data_->Begin()+pivot_->start_+left_points;
Comparator comp;
comp.Init(pivot->box.get_pivot_dimension());
std::nth_element(data_->Begin(), it, data_->End(), comp);
hr_left.Init(dimension);
hr_right.Init(dimension);
comp.Init(pivot->box_.get_pivot_dimension());
std::nth_element(data_->Begin()+pivot->start_, it,
data_->Begin()+pivot->start_+pivot->num_of_points_, comp);
index_t left_start = pivot->start_;
index_t right_start = pivot->start_ + pivot->num_of_points_-1;
int32 dimension = data_->get_dimension();
int32 max_range_dimension = pivot->box_.get_pivot_dimension();
Precision_t pivot_value = pivot->box_.get_pivot_value();
Precision_t *point_left = data_->At(left_start);
Precision_t *point_right = data_->At(right_start);
index_t left_points=0;
index_t right_points=0;
HyperRectangle_t hr_left;
HyperRectangle_t hr_left;
HyperRectangle_t hr_right;
hr_left.Init(dimension);
hr_right.Init(dimension);
for(index_t i=0; i<left_points; i++) {
index_t left_start=pivot->start_;
for(index_t i=left_start; i<left_start+left_points; i++) {
UpdateHyperRectangle(data_->At(i), hr_left);
}
for(index_t i=left_points; i<num_of_points; i++) {
for(index_t i=left_start+left_points; i<left_start+pivot->num_of_points_; i++) {
UpdateHyperRectangle(data_->At(i), hr_right);
}
FindPivotDimensionValue(hr_left);
FindPivotDimensionValue(hr_right);
PivotInfo* pv_left = new PivotInfo();
pv_left->Init(left_start, left_points, hr_left);
PivotInfo* pv_right = new PivotInfo();
+2 -2
View File
@@ -50,12 +50,12 @@ TREE_PARAMETERS(MMAPMM,
false);
struct BasicTypes1 {
typedef float32 Precision_t;
typedef tpiemm::MemoryManager<false> Allocator_t;
typedef tpiemm::MemoryManager<falsei,65536> Allocator_t;
typedef EuclideanMetric<float32> Metric_t;
};
struct NodeParameters1 {
typedef float32 Precision_t;
typedef tpiemm::MemoryManager<false> Allocator_t;
typedef tpiemm::MemoryManager<false,65536> Allocator_t;
typedef EuclideanMetric<float32> Metric_t;
typedef HyperRectangle<BasicTypes1, false> BoundingBox_t;
typedef NullStatistics<Loki::NullType> NodeCachedStatistics_t;