Commit f0941d15 authored by thillux's avatar thillux
Browse files

removed unused multicore feature

parent a570466d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME           = "Topology Generator"
PROJECT_NAME           = "TopoGen (Topology Generator)"

# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
@@ -125,7 +125,7 @@ ABBREVIATE_BRIEF =
# description.
# The default value is: NO.

ALWAYS_DETAILED_SEC    = NO
ALWAYS_DETAILED_SEC    = YES

# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
# inherited members of a class in the documentation of that class as if those
@@ -421,7 +421,7 @@ EXTRACT_PRIVATE = YES
# scope will be included in the documentation.
# The default value is: NO.

EXTRACT_PACKAGE        = NO
EXTRACT_PACKAGE        = YES

# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be
# included in the documentation.
@@ -452,7 +452,7 @@ EXTRACT_LOCAL_METHODS = NO
# are hidden.
# The default value is: NO.

EXTRACT_ANON_NSPACES   = NO
EXTRACT_ANON_NSPACES   = YES

# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
# undocumented members inside documented classes or files. If set to NO these
@@ -525,7 +525,7 @@ SHOW_INCLUDE_FILES = YES
# which file to include in order to use the member.
# The default value is: NO.

SHOW_GROUPED_MEMB_INC  = NO
SHOW_GROUPED_MEMB_INC  = YES

# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include
# files with double quotes in the documentation rather than with sharp brackets.
+14 −115
Original line number Diff line number Diff line
@@ -28,8 +28,9 @@
 */

#include "BetaSkeletonFilter.hpp"
#include "config/PredefinedValues.hpp"

#include "config/Config.hpp"
#include "config/PredefinedValues.hpp"
#include "db/InternetUsageStatistics.hpp"
#include "geo/CityNode.hpp"
#include "geo/GeographicNode.hpp"
@@ -39,15 +40,12 @@
#include "util/Util.hpp"
#include <cassert>
#include <cmath>
#include <condition_variable>
#include <cstdlib>
#include <future>
#include <iostream>
#include <lemon/bfs.h>
#include <lemon/core.h>
#include <list>
#include <set>
#include <thread>

using GeometricHelpers::deg2rad;
using GeometricHelpers::rad2deg;
@@ -56,8 +54,7 @@ using GeometricHelpers::sphericalDist;
BetaSkeletonFilter::BetaSkeletonFilter(BaseTopology_Ptr baseTopo)
    : _baseTopo(baseTopo),
      _graph(_baseTopo->getGraph()),
      _nodeGeoNodeMap(_baseTopo->getNodeMap()),
      _workItems(new ConcurrentQueue<BetaFilterTask>) {
      _nodeGeoNodeMap(_baseTopo->getNodeMap()) {
}

BetaSkeletonFilter::~BetaSkeletonFilter() {
@@ -67,69 +64,12 @@ void BetaSkeletonFilter::generalGabrielFilter() {
    using namespace lemon;
    typedef std::list<Graph::Edge> Edgelist;
    Edgelist edges_to_delete;
    std::mutex edgesDeleteMtx;
    std::list<std::pair<Graph::Node, Graph::Node>> edges_to_add;
    std::mutex edgesAddMtx;

    std::vector<std::thread> threads;

    BetaFilterTask task;

    auto addTask = [this, &task](Graph::Node& n1, Graph::Node& n2) {
        task.n1 = n1;
        task.n2 = n2;
        task.beta = 1.0;
        _workItems->push(std::move(task));
    };

    // create gabriel graph

    // fill work queue
    for (Graph::EdgeIt edge(*_graph); edge != lemon::INVALID; ++edge) {
        Graph::Node n1 = _graph->u(edge);
        Graph::Node n2 = _graph->v(edge);
        assert(n1 != n2);
        addTask(n1, n2);
    }

    auto deleteEdge = [this, &edgesDeleteMtx, &edges_to_delete](Graph::Edge& edge) {
        edgesDeleteMtx.lock();
        if (edge != INVALID && !isBetaSkeletonEdgeGreaterEqualThanOne(edge, 1.0))
            edges_to_delete.push_back(edge);
        edgesDeleteMtx.unlock();
    };

    auto addEdge = [this, &edgesAddMtx, &edges_to_add](Graph::Node& n1, Graph::Node& n2) {
        edgesAddMtx.lock();
        edges_to_add.push_back(std::make_pair(n1, n2));
        edgesAddMtx.unlock();
    };

    // run
    for (int i = 0; i < Util::getNumberOfCores(); ++i) {
        threads.push_back(std::thread([this, &deleteEdge, &addEdge](void) {
            while (!_workItems->empty()) {
                BetaFilterTask task;
                bool popSucessfull = this->_workItems->try_pop(task);
                if (!popSucessfull)
                    break;

                Graph::Edge edge = findEdge(*(this->_graph), task.n1, task.n2);
                if (edge != INVALID && !isBetaSkeletonEdgeGreaterEqualThanOne(edge, task.beta))
                    deleteEdge(edge);
            }
        }));
    }

    // join
    for (auto& thread : threads) {
        thread.join();
    }

    // add edges
    for (auto pair : edges_to_add)
        _graph->addEdge(pair.first, pair.second);

    // erase edges
    for (Edgelist::iterator edge = edges_to_delete.begin(); edge != edges_to_delete.end(); ++edge)
        _graph->erase(*edge);
}
@@ -153,11 +93,7 @@ void BetaSkeletonFilter::perCountryBetaFilter() {
    // create work items
    typedef std::list<Graph::Edge> Edgelist;
    Edgelist edges_to_delete;
    std::mutex edgesDeleteMtx;
    std::list<std::pair<Graph::Node, Graph::Node>> edges_to_add;
    std::mutex edgesAddMtx;
    std::vector<std::thread> threads;
    BetaFilterTask task;

    std::unique_ptr<Config> config(new Config);
    double minBeta = config->get<double>("betaSkeleton.minBeta");
@@ -166,13 +102,6 @@ void BetaSkeletonFilter::perCountryBetaFilter() {
    assert(maxBeta > 0.0);
    assert(maxBeta < 2.0);

    auto addTask = [this, &task](Graph::Node& n1, Graph::Node& n2, double beta) {
        task.n1 = n1;
        task.n2 = n2;
        task.beta = beta;
        _workItems->push(std::move(task));
    };

    std::unique_ptr<InternetUsageStatistics> stat(new InternetUsageStatistics(PredefinedValues::dbFilePath()));

    // fill work queue
@@ -186,49 +115,18 @@ void BetaSkeletonFilter::perCountryBetaFilter() {
                if (nd1.second == nd2.second || nd1.second->id() > nd2.second->id())
                    continue;

                addTask(nd1.first, nd2.first, beta);
            }
    }

    auto deleteEdge = [this, &edgesDeleteMtx, &edges_to_delete](Graph::Edge& edge) {
        edgesDeleteMtx.lock();
                if (beta >= 1.0) {
                    Graph::Edge edge = findEdge(*_graph, nd1.first, nd2.first);
                    if (edge != INVALID && !isBetaSkeletonEdgeGreaterEqualThanOne(edge, beta))
                        edges_to_delete.push_back(edge);
        edgesDeleteMtx.unlock();
    };

    auto addEdge = [this, &edgesAddMtx, &edges_to_add](Graph::Node& n1, Graph::Node& n2) {
        edgesAddMtx.lock();
        edges_to_add.push_back(std::make_pair(n1, n2));
        edgesAddMtx.unlock();
    };

    // run
    for (int i = 0; i < Util::getNumberOfCores(); ++i) {
        threads.push_back(std::thread([this, &deleteEdge, &addEdge](void) {
            while (!_workItems->empty()) {
                BetaFilterTask task;
                bool popSucessfull = this->_workItems->try_pop(task);
                if (!popSucessfull)
                    break;

                if (task.beta >= 1.0) {
                    Graph::Edge edge = findEdge(*(this->_graph), task.n1, task.n2);
                    if (edge != INVALID && !isBetaSkeletonEdgeGreaterEqualThanOne(edge, task.beta))
                        deleteEdge(edge);
                } else if (isBetaSkeletonEdgeSmallerThanOne(task.n1, task.n2, task.beta))
                    addEdge(task.n1, task.n2);
                } else if (isBetaSkeletonEdgeSmallerThanOne(nd1.first, nd2.first, beta))
                    edges_to_add.push_back(std::make_pair(nd1.first, nd2.first));
                else {
                    Graph::Edge edge = findEdge(*(this->_graph), task.n1, task.n2);
                    Graph::Edge edge = findEdge(*_graph, nd1.first, nd2.first);
                    if (edge != INVALID)
                        deleteEdge(edge);
                }
                        edges_to_delete.push_back(edge);
                }
        }));
            }

    // join
    for (auto& thread : threads) {
        thread.join();
    }

    // add edges
@@ -345,6 +243,7 @@ bool BetaSkeletonFilter::testTheta(GeographicNode_Ptr& p, GeographicNode_Ptr& r,
    double b = sphericalDist(q, r);
    double c = sphericalDist(p, q);
    double C = Util::ihs((Util::hs(c) - Util::hs(a - b)) / (sin(a) * sin(b)));

    if (C >= theta)
        return false;
    else
+1 −13
Original line number Diff line number Diff line
@@ -40,15 +40,6 @@
#include <map>
#include <utility>

struct BetaFilterTask {
    BetaFilterTask() {}
    BetaFilterTask(Graph::Node n1, Graph::Node n2, double beta) : n1(n1), n2(n2), beta(beta) {}

    Graph::Node n1;
    Graph::Node n2;
    double beta;
};

class BetaSkeletonFilter {
   public:
    BetaSkeletonFilter(BaseTopology_Ptr baseTopo);
@@ -73,9 +64,6 @@ class BetaSkeletonFilter {
    BaseTopology_Ptr _baseTopo;
    Graph_Ptr _graph;
    NodeMap_Ptr _nodeGeoNodeMap;

    std::shared_ptr<ConcurrentQueue<BetaFilterTask>> _workItems;
    std::mutex _graphMtx;
};

#endif  // BETASKELETONFILTER_HPP
+2 −4
Original line number Diff line number Diff line
@@ -263,10 +263,8 @@ int main(int argc, char** argv) {
    /*
      GRAPH OUTPUT (JSON)
    */
    if (args->jsonOutputEnabled()) {
        std::string jsonFileNameCLI = args->jsonOutputFile();
        writeJSONGraph(baseTopo, config, jsonFileNameCLI);
    }
    if (args->jsonOutputEnabled())
        writeJSONGraph(baseTopo, config, args->jsonOutputFile());

    return EXIT_SUCCESS;
}
+0 −21
Original line number Diff line number Diff line
@@ -28,16 +28,7 @@
 */

#include "Util.hpp"
#include <unistd.h>
#include <cmath>
#include <unistd.h>
#include <cassert>
#include <fcntl.h>

int Util::getNumberOfCores(void) {
    // return sysconf(_SC_NPROCESSORS_ONLN);
    return 1;
}

double Util::hs(double theta) {
    double t = sin(theta / 2.0);
@@ -48,15 +39,3 @@ double Util::ihs(double theta) {
    return 2.0 * asin(sqrt(theta));
}
long Util::urandom() {
    int fd = open("/dev/urandom", O_RDONLY);
    assert(fd);

    long ret;
    int readBytes = read(fd, &ret, sizeof(ret));
    assert(readBytes == sizeof(ret));

    close(fd);

    return ret;
}
 No newline at end of file
Loading