Пример #1
0
        private static void Debug()
        {
            int i = 0;

            Console.WriteLine("processnum " + processnum);
            Console.WriteLine("meandevm " + meanDev);
            Console.WriteLine("standdev " + standardDev);

            int size = processVector.Count;

            for (i = 0; i < size; i++)
            {
                SProcess process = processVector[i];
                Console.WriteLine("process " + i + " " + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.numblocked);
            }

            Console.WriteLine("runtime " + runtime);
        }
Пример #2
0
        public static Results Run(int runtime, List <SProcess> processVector, Results result)
        {
            int    comptime        = 0;
            int    currentProcess  = 0;
            int    previousProcess = 0;
            int    size            = processVector.Count;
            int    completed       = 0;
            string resultsFile     = "Summary-Processes";

            result.schedulingType = "Preemptive";
            result.schedulingName = "Round-Robin Sheduling";

            try
            {
                //BufferedWriter out = new BufferedWriter(new FileWriter(resultsFile));
                //OutputStream out = new FileOutputStream(resultsFile);
                StreamWriter outStream = new StreamWriter(resultsFile);
                SProcess     process   = processVector[currentProcess];

                outStream.WriteLine("Process: " + currentProcess + " registered... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + ")");
                while (comptime < runtime)
                {
                    if (process.cpudone == process.cputime)
                    {
                        completed++;
                        outStream.WriteLine("Process: " + currentProcess + " completed... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + ")");
                        if (completed == size)
                        {
                            result.compuTime = comptime;
                            outStream.Close();
                            return(result);
                        }

                        currentProcess = NextProcess(processVector, currentProcess);

                        process = processVector[currentProcess];
                        outStream.WriteLine("Process: " + currentProcess + " registered... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + ")");
                    }
                    if (process.ioblocking == process.ionext)
                    {
                        outStream.WriteLine("Process: " + currentProcess + " I/O blocked... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + ")");
                        process.numblocked++;
                        process.ionext    = 0;
                        process.quantnext = 0;
                        previousProcess   = currentProcess;

                        currentProcess = NextProcess(processVector, currentProcess);

                        process = processVector[currentProcess];
                        outStream.WriteLine("Process: " + currentProcess + " registered... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + ")");
                    }
                    if (process.quant == process.quantnext)
                    {
                        outStream.WriteLine("Process: " + currentProcess + " Quant blocked... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + ")");
                        process.numblocked++;
                        process.quantnext = 0;
                        previousProcess   = currentProcess;

                        currentProcess = NextProcess(processVector, currentProcess);

                        process = processVector[currentProcess];
                        outStream.WriteLine("Process: " + currentProcess + " registered... (" + process.cputime + " " + process.ioblocking + " " + process.cpudone + ")");
                    }

                    if (process.ioblocking > 0)
                    {
                        process.ionext++;
                    }
                    process.cpudone++;
                    process.quantnext++;
                    comptime++;
                }
                outStream.Close();
            }
            catch (IOException e) { /* Handle exceptions */ }

            result.compuTime = comptime;

            return(result);
        }
Пример #3
0
        public static void Main(String[] args)
        {
            int i = 0;

            if (args.Length != 1)
            {
                Console.WriteLine("Usage: 'java Scheduling <INIT FILE>'");
                return;
            }

            FileStream f = new FileStream(args[0], FileMode.OpenOrCreate);

            if (!(File.Exists(args[0])))
            {
                Console.WriteLine("Scheduling: error, file '" + f.Name + "' does not exist.");
                return;
            }

            if (!(f.CanRead))
            {
                Console.WriteLine("Scheduling: error, read of " + f.Name + " failed.");
                return;
            }

            Console.WriteLine("Working...");

            Init(f);

            if (processVector.Count < processnum)
            {
                i = 0;
                while (processVector.Count < processnum)
                {
                    double X = Common.R1();

                    while (X == -1.0)
                    {
                        X = Common.R1();
                    }

                    X = X * standardDev;
                    int cputime = (int)X + meanDev;

                    processVector.Add(new SProcess(cputime, i * 100, 0, 0, 0, quant));

                    i++;
                }
            }
            result = SchedulingAlgorithm.Run(runtime, processVector, result);
            try
            {
                //BufferedWriter out = new BufferedWriter(new FileWriter(resultsFile));
                StreamWriter outStream = new StreamWriter(resultsFile);

                outStream.WriteLine("Scheduling Type: " + result.schedulingType);
                outStream.WriteLine("Scheduling Name: " + result.schedulingName);
                outStream.WriteLine("Simulation Run Time: " + result.compuTime);
                outStream.WriteLine("Mean: " + meanDev);
                outStream.WriteLine("Standard Deviation: " + standardDev);
                outStream.WriteLine("Quant: " + quant);
                outStream.WriteLine("Process #\tCPU Time\tIO Blocking\tCPU Completed\tCPU Blocked");

                for (i = 0; i < processVector.Count; i++)
                {
                    SProcess process = (SProcess)processVector[i];
                    outStream.Write(i);

                    if (i < 100)
                    {
                        outStream.Write("\t\t");
                    }
                    else
                    {
                        outStream.Write("\t");
                    }

                    outStream.Write(process.cputime);

                    if (process.cputime < 100)
                    {
                        outStream.Write(" (ms)\t\t");
                    }
                    else
                    {
                        outStream.Write(" (ms)\t");
                    }

                    outStream.Write(process.ioblocking);

                    if (process.ioblocking < 100)
                    {
                        outStream.Write(" (ms)\t\t");
                    }
                    else
                    {
                        outStream.Write(" (ms)\t");
                    }

                    outStream.Write(process.cpudone);

                    if (process.cpudone < 100)
                    {
                        outStream.Write(" (ms)\t\t");
                    }
                    else
                    {
                        outStream.Write(" (ms)\t");
                    }

                    outStream.WriteLine(process.numblocked + " times");
                }
                outStream.Close();
            }
            catch (IOException e) { /* Handle exceptions */ }

            Console.WriteLine("Completed.");

            Console.ReadKey();
        }