Back to index

nordugrid-arc-nox  1.1.0~rc6
BenchmarkBroker.cpp
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006 
00007 #include <string.h>
00008 #include <algorithm>
00009 
00010 #include <arc/UserConfig.h>
00011 #include <arc/StringConv.h>
00012 #include <arc/client/ExecutionTarget.h>
00013 
00014 #include "BenchmarkBroker.h"
00015 
00016 namespace Arc {
00017 
00018   class cmp {
00019   public:
00020     cmp(const std::string benchmark)
00021       : benchmark(benchmark) {}
00022     bool ComparePerformance(const ExecutionTarget *T1,
00023                             const ExecutionTarget *T2);
00024   private:
00025     std::string benchmark;
00026   };
00027 
00028   bool cmp::ComparePerformance(const ExecutionTarget *T1,
00029                                const ExecutionTarget *T2) {
00030     double T1performance = 0;
00031     double T2performance = 0;
00032     std::map<std::string, double>::const_iterator iter;
00033 
00034     for (iter = T1->Benchmarks.begin(); iter != T1->Benchmarks.end(); iter++)
00035       if (lower(iter->first) == benchmark) {
00036         T1performance = iter->second;
00037         break;
00038       }
00039 
00040     for (iter = T2->Benchmarks.begin(); iter != T2->Benchmarks.end(); iter++)
00041       if (lower(iter->first) == benchmark) {
00042         T1performance = iter->second;
00043         break;
00044       }
00045 
00046     return T1performance > T2performance;
00047   }
00048 
00049   BenchmarkBroker::BenchmarkBroker(const UserConfig& usercfg)
00050     : Broker(usercfg) {
00051     benchmark = usercfg.Broker().second;
00052     if (benchmark.empty())
00053       benchmark = "specint2000";
00054   }
00055 
00056   BenchmarkBroker::~BenchmarkBroker() {}
00057 
00058   Plugin* BenchmarkBroker::Instance(PluginArgument *arg) {
00059     BrokerPluginArgument *brokerarg = dynamic_cast<BrokerPluginArgument*>(arg);
00060     if (!brokerarg)
00061       return NULL;
00062     return new BenchmarkBroker(*brokerarg);
00063   }
00064 
00065   void BenchmarkBroker::SortTargets() {
00066 
00067     //Remove clusters with incomplete information for target sorting
00068     std::list<ExecutionTarget*>::iterator iter = PossibleTargets.begin();
00069     while (iter != PossibleTargets.end()) {
00070       if (((*iter)->Benchmarks).empty()) {
00071         iter = PossibleTargets.erase(iter);
00072         continue;
00073       }
00074       else {
00075         std::map<std::string, double>::const_iterator iter2;
00076         bool ok = false;
00077         for (iter2 = (*iter)->Benchmarks.begin();
00078              iter2 != (*iter)->Benchmarks.end(); iter2++)
00079           if (lower(iter2->first) == benchmark) {
00080             ok = true;
00081             break;
00082           }
00083         if (!ok) {
00084           iter = PossibleTargets.erase(iter);
00085           continue;
00086         }
00087       }
00088       iter++;
00089     }
00090 
00091     logger.msg(VERBOSE, "Matching against job description,"
00092                "following targets possible for BenchmarkBroker: %d", PossibleTargets.size());
00093 
00094     iter = PossibleTargets.begin();
00095 
00096     for (int i = 1; iter != PossibleTargets.end(); iter++, i++)
00097       logger.msg(VERBOSE, "%d. Cluster: %s; Queue: %s", i, (*iter)->DomainName, (*iter)->ComputingShareName);
00098 
00099     cmp Cmp(benchmark);
00100 
00101     logger.msg(VERBOSE, "Cluster will be ranked according to the %s benchmark scenario", benchmark);
00102 
00103     PossibleTargets.sort(sigc::mem_fun(Cmp, &cmp::ComparePerformance));
00104 
00105     logger.msg(VERBOSE, "Best targets are: %d", PossibleTargets.size());
00106 
00107     iter = PossibleTargets.begin();
00108 
00109     for (int i = 1; iter != PossibleTargets.end(); iter++, i++)
00110       logger.msg(VERBOSE, "%d. Cluster: %s; Queue: %s", i, (*iter)->DomainName, (*iter)->ComputingShareName);
00111 
00112     TargetSortingDone = true;
00113 
00114   }
00115 
00116 } // namespace Arc