From 2f5d5ece47f203a8cd12a2291567bba841be3b0b Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 30 Jun 2019 00:28:08 +0200 Subject: [PATCH] Threading test added --- Descriptor.h | 1 - DescriptorManager.cpp | 26 +++++++++++++++++++++++++- DescriptorManager.h | 9 ++++----- Makefile | 4 ++-- main.cpp | 14 +++++++++++++- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/Descriptor.h b/Descriptor.h index 77da5d1..d82b352 100644 --- a/Descriptor.h +++ b/Descriptor.h @@ -140,7 +140,6 @@ public: for (ssize_t i = 0; i < n; i++) { retval <<= 1; if (q[0] > intensity) - //retval |= uint64_t(1); retval++; q = q + local_image->channels(); } diff --git a/DescriptorManager.cpp b/DescriptorManager.cpp index 4577b27..1befc0c 100644 --- a/DescriptorManager.cpp +++ b/DescriptorManager.cpp @@ -253,6 +253,30 @@ void DescriptorManager::runExperiments() { } } +//Test post please ignore +void DescriptorManager::test() { + const uint64_t n = 1000000000; + //string insert = "constant"; //assuming string value doesn't matter. + int method = 2; + { + + high_resolution_clock::time_point t1 = high_resolution_clock::now(); + int target_distance = 5; + uint64_t better_count = 0; + map::iterator it = features[method].begin(); + for (uint64_t i = 0; i < n; i++) { + uint64_t a = (it++->second); + uint64_t b = (it++->second); + if(descriptor_types[method]->distance(a, b) <= target_distance) better_count++; + if(it == features[method].end()) it = features[method].begin(); + } + high_resolution_clock::time_point t2 = high_resolution_clock::now(); + duration time_span = duration_cast>(t2 - t1); + cout << "It took me " << time_span.count() << " seconds to sort " << n << " big numbers." << endl; + } + +} + //outputs the gathered data to iostream //Tries to do some nice formatting and grouping of bits. void DescriptorManager::outputMap(int a) { @@ -300,4 +324,4 @@ void DescriptorManager::generatePreviews(string imagename) { for (int i = 0; i < numDescriptors; i++) { descriptor_types[i]->preview(img); } -} +} \ No newline at end of file diff --git a/DescriptorManager.h b/DescriptorManager.h index 560db92..15bb26f 100644 --- a/DescriptorManager.h +++ b/DescriptorManager.h @@ -5,20 +5,17 @@ #include #include #include +#include + #include #include #include -//Boost serialization test: #include #include #include #include #include -//YAS Serialization: -//#include -//#include - #include //Debug, for measuring execution times #include @@ -51,6 +48,7 @@ public: void rankImages(string image_name, int method); multiset> rankMutations(string image_name, int method); void runExperiments(); + void test(); void generatePreviews(string imagename); void outputMap(int a); void outputMap(); @@ -65,6 +63,7 @@ private: Mutation* mutators[numMutations]; Image* current_image = NULL; //for caching purposes + //TODO: Are maps the best container for us? Logarithmic random access is bad, but otherwise it might be fine? map features[numDescriptors]; //array of maps that will hold the descriptors map mutatedFeatures[numDescriptors][numMutations]; multiset > distances; //multiset that stores the distances diff --git a/Makefile b/Makefile index a320751..cd71b2b 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ CXX = g++ CC = $(CXX) -CPPFLAGS = -O2 `Magick++-config --cppflags` +CPPFLAGS = -O3 `Magick++-config --cppflags` BOOST_LIBS = -lboost_system -lboost_filesystem -lboost_serialization -LDFLAGS = `Magick++-config --ldflags` $(BOOST_LIBS) +LDFLAGS = `Magick++-config --ldflags` $(BOOST_LIBS) -lpthread SOURCES = DescriptorManager.cpp main.cpp OBJECTS = $(SOURCES:.cpp=.o) diff --git a/main.cpp b/main.cpp index bb30417..7878728 100644 --- a/main.cpp +++ b/main.cpp @@ -27,8 +27,20 @@ int main(int argc, char **argv) { } InitializeMagick(*argv); DescriptorManager* manager = new DescriptorManager("test"); - manager->Init(); + manager->Init();/* manager->rankImages(imagename, method); manager->outputRank(imagename, method); + manager->outputMap(method);*/ + cout << endl; + + cout << "Starting first compute thread.." << endl; + thread first(&DescriptorManager::test, manager); + cout << "Starting second computer thread.." << endl; + thread second(&DescriptorManager::test, manager); + first.join(); + + second.join(); + cout << "we done." << endl; + //manager->test(); return 0; }