www.pudn.com > ghs1.2.rar > pgsc.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 ParaScheduler: public GHSScheduler
{
  private:
    vector optimalWorkload;
    void PartitionWorkload(vector& machineArray);
    void PlanRecord();
    double CalculateRuntime(vector& machineArray);
  public:
    void Initialize();
    void OutputSchedule(char *outputfile);
    void SetWorkload(double gworkload);
};

// task partition according to (1-utilization)* speed 
void 
ParaScheduler::PartitionWorkload(vector& machinearray)
{
  int i = 0, j = 0;
  // the sum of (1-utilization)* speed
  double utilspeed = 0;

  for (i = 0; i < wsNum; i++) 
  {
    if (machinearray[i] == 1) 
    {
      utilspeed += (1 - arri_p[i] * serv_p[i]) * speed_p[i];
    }
  }

  for (i = 0; i < wsNum; i++) 
  {
    if (machinearray[i] == 1) 
    {
      work_p[i] = totalWorkload * ((1 - arri_p[i] * serv_p[i]) * speed_p[i]) / utilspeed;
    }
  }
}

/* record the current scheduling plan as the best scheduling plan
 */
void 
ParaScheduler::PlanRecord()
{
  int i,j;

  for (i = 0; i < wsNum; i++) 
  {
    optimalWorkload[i] = work_p[i];
  }

}

void 
ParaScheduler::Initialize()
{

  for(int i = 0; i < wsNum; i++) {
    work_p.push_back(0);
    firstItemIndex.push_back(0);
    lastItemIndex.push_back(0);
    mUtil.push_back(0);
    mArri.push_back(0);
    mServSTD.push_back(0);
    mWork.push_back(0);
    machID.push_back(1);
    currWorkload.push_back(0);
    machsOrder.push_back(i);
    optimalWorkload.push_back(0);
  }

}

/* calcuate the mean+variance of the parallel task runtime
 * using model formulas 
 */
double 
ParaScheduler::CalculateRuntime(vector& machineArray)
{
  int i = 0, j = 0;

  for (i = 0; i < wsNum; i++) work_p[i] = 0;

  PartitionWorkload(machineArray);

  j = 0;
  for (i = 0; i < wsNum; i++) 
  {
    if (machineArray[i] == 1) 
    {
      mUtil[j] = arri_p[i] * serv_p[i];
      mArri[j] = arri_p[i];
      mServSTD[j] = servstd_p[i];
      mWork[j] = work_p[i] / speed_p[i];
      j++;
    }
  }

  float meanTmp, variTmp;
  double subtaskTime;

  ReadTaskPara(mUtil, mArri, mServSTD, mWork, j);
  meanTmp = GetParaMean(XNUM);
  //cout << "the meanTmp is " << meanTmp << endl;
  //variTmp = GetParaVari(meanTmp, XNUM);
  //return(meanTmp+variTmp);
  /* if ( meanTmp < 20)
  {
    for (i = 0; i < wsNum; i++) 
    {
      if (machineArray[i] == 1) 
      {
        subtaskTime = work_p[i] / speed_p[i];
        cout << "the machine is " << i <<" and subtaskTime is " << subtaskTime << endl;
      }
    }
    //cout << ".............." << endl;
  } */

  return(meanTmp);

}

/* write the task scheduling plan into a result file
 * which name is provided by argv[3]
 */

void 
ParaScheduler::OutputSchedule(char *outputfile)
{

  fstream outputFile;
  outputFile.open(outputfile, fstream::out);

  if (!outputFile.is_open()) 
  {
    cout << "Error in open output file " << endl;
    exit(1);
  }

  int i,j;
  double tmpWork;

  for (i = 0; i < wsNum; i++) 
  {
    outputFile << machName[i] << ": " << optimalWorkload[i] << endl;
  }

  outputFile.close();

}

void
ParaScheduler::SetWorkload(double gworkload)
{
  totalWorkload = gworkload;
} 

int 
main(int argc, char **argv)
{
  //double paraMean = 0.0, paraVari = 0.0;
  int i; 
  ParaScheduler myScheduler;

  if (argc != 5)
  {
    cout << "pgsc resopara.txt workload result.txt schetag(0/1) " << endl;
    exit(1);
  }

  myScheduler.GetResoPara(argv[1]);
  float wl = atof(argv[2]);
  myScheduler.Initialize();
  myScheduler.SetWorkload(wl);
  int scheTag = atoi(argv[4]);

  /* cout << "machine name: utilization, arrival-rate, service_std, relative speed \n");
  for (int i = 0; i