diff --git a/Makefile.am b/Makefile.am index a8ef0cd..9d3bf3b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -161,6 +161,7 @@ src_backend_libbackend_la_SOURCES = \ src/backend/global_preferences.cc \ src/backend/history.cc \ src/backend/history_observer.cc \ + src/backend/holt_graph.cc \ src/backend/invalid_plugin_exception.cc \ src/backend/key_file.cc \ src/backend/module.cc \ @@ -198,6 +199,7 @@ pkginclude_HEADERS += \ src/backend/global_preferences.hh \ src/backend/history.hh \ src/backend/history_observer.hh \ + src/backend/holt_graph.hh \ src/backend/invalid_plugin_exception.hh \ src/backend/key_file.hh \ src/backend/module.hh \ diff --git a/src/backend/holt_graph.cc b/src/backend/holt_graph.cc new file mode 100644 index 0000000..6e9b9f3 --- /dev/null +++ b/src/backend/holt_graph.cc @@ -0,0 +1,88 @@ +// src/backend/holt_graph.cc - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#include "holt_graph.hh" + +#include "history.hh" +#include "process.hh" +#include "thread.hh" + +using namespace sgpem; +using namespace std; + +void +HoltGraph::update(const History& changed_history) +{ + const Environment& env = changed_history.get_last_environment(); + const Environment::Processes& processes = env.get_processes(); + + _resources.clear(); + _active_threads.clear(); + _active_requests.clear(); + + for(unsigned int pi = 0; pi < processes.size(); ++pi) + { + vector threads = processes[pi]->get_threads(); + + for(unsigned int ti = 0; ti < threads.size(); ++ti) + { + vector requests = threads[ti]->get_requests(); + + for(unsigned int ri = 0; ri < requests.size(); ++ri) + { + Request& r = *requests[ri]; + + if(r.get_state() == Request::state_allocated) + { + _active_requests.push_back(&r); + _active_threads.insert(&r.get_thread()); + + vector subrequests = r.get_subrequests(); + + for(unsigned int sri = 0; sri < subrequests.size(); ++sri) + { + Environment::resource_key_t key = subrequests[sri]->get_resource_key(); + + _resources.insert(env.get_resources().find(key)->second); + } + } + } + } + } +} + +HoltGraph::Resources +HoltGraph::get_resources() const +{ + return Resources(_resources.begin(), _resources.end()); +} + +HoltGraph::Threads +HoltGraph::get_active_threads() const +{ + return Threads(_active_threads.begin(), _active_threads.end()); +} + +HoltGraph::Requests +HoltGraph::get_active_requests() const +{ + return _active_requests; +} + diff --git a/src/backend/holt_graph.hh b/src/backend/holt_graph.hh new file mode 100644 index 0000000..ce934ec --- /dev/null +++ b/src/backend/holt_graph.hh @@ -0,0 +1,64 @@ +// src/backend/holt_graph.hh - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#ifndef HOLT_GRAPH_HH +#define HOLT_GRAPH_HH 1 + +namespace sgpem +{ + class Resource; + class Thread; + class Request; +} + +#include "history_observer.hh" + +#include +#include + +namespace sgpem +{ + class HoltGraph; + + class SG_DLLEXPORT HoltGraph : public HistoryObserver + { + public: + typedef std::vector Resources; + typedef std::vector Threads; + typedef std::vector Requests; + + HoltGraph(); + + virtual void update(const History& changed_history); + + Resources get_resources() const; + Threads get_active_threads() const; + Requests get_active_requests() const; + + private: + std::set _resources; + std::set _active_threads; + Requests _active_requests; + }; // class HistoryObserver + +}//~ namespace sgpem + +#endif //HOLT_GRAPH_HH +