www.pudn.com > ghs1.2.rar > mtsc.cpp
/* * Copyright (c) 2000-2003 Illinois Institute of Technology. * All rights reserved. * * This file is part of the GHS software package. For license * information, see the LICENSE file in the top level directory of the * GHS source distribution. * * Released Date: August 18 2005 * This is the GHS I release by the * SCS Group, * http://www.cs.iit.edu/~scs * Department of Computer Science, * Illinois Institute of Technology. * * This release has been tested under SUN OS 5.9. * * Supervisor * ---------- * Illiniois Institute of Technology: * -Dr. Xian-He Sun * * Author(s) * ----------------- * Illinois Institute of Technology: * -Ming Wu * -Xian-He Sun * */ #include#include #include #include #include #include #include "ghs.h" using namespace std; extern double GetParaMean(int numOfinte); extern double GetParaVari(double paramean, int numOfinte); extern void ReadTaskPara(const vector & ut, const vector & ar, const vector & ss, const vector & wo, int mNum); class MetaScheduler: public GHSScheduler { private: int gJobNum; static const int INVALIDTASK = -1; vector jobsList; // Grid Jobs workload array vector gJobWorkload; vector jobsQueue; vector mapTab; void PartitionWorkload(vector & machineArray, vector & jobArray, int jobNum); void PlanRecord(); double CalculateRuntime(vector & machineArray); public: void Initialize(); void GetTaskPara(char *configFile); void OutputSchedule(char *outputfile); }; /* read task parameters * task name, task workload */ void MetaScheduler::GetTaskPara(char *configFile) { fstream taskFile; taskFile.open(configFile, fstream::in); if (!taskFile.is_open()) { cout << "Error in open the task parameter file" << endl; exit(1); } totalWorkload = 0; int i = 0; float tmpWork; string line; string tmpName; while (getline(taskFile, line) && i < MAX_GJOB_NUM ) { stringstream oss; oss << line; oss >> tmpName >> tmpWork; taskName.push_back(tmpName); gJobWorkload.push_back(tmpWork); totalWorkload += tmpWork; i++; } if (i==MAX_GJOB_NUM) { cout << "the task number is beyond the maximum, we will not take the extra tasks into account" << endl; } gJobNum = i; taskFile.close(); } /* task partition for a group of independ tasks * each task has its own workload and can not be further partitioned * we use the mean-mean partition method */ void MetaScheduler::PartitionWorkload(vector & machineArray, vector & jobArray, int jobNum) { int i = 0, j = 0, k = 0; int bestJob, bestMachine, tmpMachine; vector jobTag; int firstJobCond; int firstMachCond; // the sum of (1-utilization)* speed double globalBestTime, tmpBestTime, finishTime; for (i = 0; i < wsNum; i++) currWorkload[i] = work_p[i]; for (i = 0; i < jobNum; i++) jobTag.push_back(0); for (i = 0; i < jobNum; i++) { firstJobCond = 0; for (k = 0; k < jobNum; k++) { if ( jobTag[k] == 0) { firstMachCond = 0; for (j = 0; j < wsNum; j++) { if (machineArray[j] != 0) { finishTime = (gJobWorkload[jobArray[k]] + currWorkload[j]) / ((1 - arri_p[j] * serv_p[j]) * speed_p[j]); if ( firstJobCond == 0) { tmpBestTime = finishTime; globalBestTime = tmpBestTime; bestJob = k; bestMachine = j; firstJobCond = 1; } if (firstMachCond == 0) { tmpBestTime = finishTime; tmpMachine = j; firstMachCond = 1; } if (tmpBestTime > finishTime) { tmpBestTime = finishTime; tmpMachine = j; } } // end if } // end for } // end if if (globalBestTime > tmpBestTime) { globalBestTime = tmpBestTime; bestJob = k; bestMachine = tmpMachine; } } jobTag[bestJob] = 1; currWorkload[bestMachine] += gJobWorkload[jobArray[bestJob]]; jobsQueue[bestMachine*jobNum + lastItemIndex[bestMachine]] = jobArray[bestJob]; lastItemIndex[bestMachine]++; } for (i = 0; i < wsNum; i++) { if (machineArray[i] != 0) { work_p[i] = currWorkload[i]; } } } /* record the current scheduling plan as the best scheduling plan * the map of tasks among machines is stored at mapTab[MAX_WS_NUM][MAX_GJOB_NUM] */ void MetaScheduler::PlanRecord() { int i,j; for (i = 0; i < wsNum; i++) { for (j = 0; j & machineArray) { int i = 0, j = 0; for (i = 0; i < wsNum; i++) work_p[i] = 0; for (i = 0; i < gJobNum; i++) jobsList[i] = i; for (i = 0; i < wsNum; i++) { firstItemIndex[i] = 0; lastItemIndex[i] = 0; for (j = 0; j