Beispiel #1
0
        /// <summary>
        /// Validate all the allocations in the taff file
        /// </summary>
        /// <param name="TaffFile">The taff file from where to get the allocations</param>
        /// <param name="CffFile"> the cff file which need for validation cff file</param>
        /// <returns> string containing calculated allocation value</returns>

        public string ValidationAllocations(TaskAllocation TaffFile, Configuration CffFile)
        {
            double progRuntime = 0;

            CffFile.Program.TryGetValue("DURATION", out progRuntime);
            string runTime;

            string[] limits;

            IDictionary <Allocation, double[]> allocations = new Dictionary <Allocation, double[]>();

            String print = "";

            foreach (Allocation allocation in TaffFile.allocations.allocations)
            {
                List <string> errors;
                string        line = "";

                if (allocation.Map == null)
                {
                    print += "<p style='color:red'>" + "INVALID MAPPING" + "</p>";
                }
                else if (allocation.Map.Length == 1)
                {
                    print += "<p style='color:red'>" + "SAME TASK HAS BEEN ASSIGNED TO MULTIPLE PROCESSOR FOR ALLOCATION ID: " + allocation.ID + "</p>";
                }
                else
                {
                    KeyValuePair <Allocation, double[]> allocationValue = validateAllocation(allocation, CffFile, out limits, out errors);



                    if (allocationValue.Value[int.Parse(Keywords.TOTALTIME)] > progRuntime)
                    {
                        runTime = "<span style='color:red'>" + String.Format("{0:0.##}", allocationValue.Value[int.Parse(Keywords.TOTALTIME)]) + "</span>";
                        errors.Add("THE ALLOCATION ID: " + allocation.ID + " HAS GREATER RUNTIME THAN PROGRAM RUNTIME");
                    }
                    else
                    {
                        runTime = String.Format("{0:0.##}", allocationValue.Value[int.Parse(Keywords.TOTALTIME)]);
                    }

                    if (errors.Count > 0)
                    {
                        foreach (string error in errors)
                        {
                            line += "<p style='color:red'>" + error + "</p>";
                        }
                    }



                    print += "ALLOCATION ID" + "=" + allocationValue.Key.ID.ToString() + "," + "&nbsp" + "Runtime" + "=" + runTime + "," + "&nbsp" + "Energy" + "=" + String.Format("{0:0.##}", allocationValue.Value[int.Parse(Keywords.TOTALENERGY)]) + "<br>" + PrintAllocationUnits(printAllocationMap(allocation), limits) + "<br><br>" + line + "<br><br>";
                }
            }

            return(print);
        }
Beispiel #2
0
        public IDictionary <Allocation, double[]> valid(TaskAllocation TaffFile, Configuration CffFile)
        {
            double energy;

            double[] times;
            double   time;

            double[] energies;

            Processor[] sortedProcessor = CffFile.Processors.OrderBy(x => x.ID).ToArray();

            Task[] sortedtasks = CffFile.Tasks.OrderBy(x => x.ID).ToArray();



            IDictionary <Allocation, double[]> allocations = new Dictionary <Allocation, double[]>();



            foreach (Allocation allocation in TaffFile.allocations.allocations)
            {
                times    = new double[allocation.Map.GetLength(0)];
                energies = new double[allocation.Map.GetLength(0)];

                for (int i = 0; i < allocation.Map.GetLength(0); i++)
                {
                    time = 0d;

                    energy = 0d;

                    for (int j = 0; j < allocation.Map.GetLength(1); j++)
                    {
                        if (allocation.Map[i, j].Equals(1))
                        {
                            time += sortedProcessor[i].CalcTime(sortedtasks[j]);

                            energy += sortedProcessor[i].CalcEnergy(sortedtasks[j]);
                        }
                    }


                    times[i]    = time;
                    energies[i] = energy;
                }

                Array.Sort(times);
                double   totalEnergy = energies.Sum();
                double[] val         = new double[] { times[times.Length - 1], totalEnergy };

                allocations.Add(new KeyValuePair <Allocation, double[]>(allocation, val));
            }


            return(allocations);
        }
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // OPEN A TASK ALLOCATION FILE
            CffFile    cff        = new CffFile();
            FileReader fileReader = new FileReader();

            errorWindow = new Errors();
            string logFile;


            List <string> errorsTaff = new List <string>();
            List <string> errorsCff  = new List <string>();
            List <string> ErrorList  = new List <string>();


            DialogResult result = filedialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                taffFilename = filedialog.FileName;

                MessageBox.Show(taffFilename);

                String taffData = fileReader.ReadTaff(taffFilename, out errorsTaff);

                taskAllocation = new TaskAllocation();

                webBrowser1.DocumentText = taffData;


                if (taskAllocation.getCffFilename(taffFilename))
                {
                    cffFilename = taskAllocation.cffFilename;

                    MessageBox.Show(taskAllocation.cffFilename);

                    configuration = new Configuration(cffFilename);

                    if (File.Exists(cffFilename))
                    {
                        String CffData = fileReader.Readcff(cffFilename, out errorsCff);

                        cff.CffBrowser.DocumentText = CffData;
                        cff.Show();


                        ErrorList = errorsTaff.Concat(errorsCff).ToList();

                        if (configuration.Validate())
                        {
                            logFile = configuration.Logfile;
                            string line = "";


                            if (ErrorList.Count == 0)
                            {
                                configuration.Validate();
                                configuration.GetConfigurations();
                                taskAllocation.GetAllocations(taffFilename);


                                if (configuration.Errors.Count.Equals(0))
                                {
                                    allocationsToolStripMenuItem.Enabled = true;

                                    if (File.Exists(logFile))
                                    {
                                        File.Delete(logFile);
                                    }
                                    using (StreamWriter sw = File.CreateText(logFile))
                                    {
                                        foreach (string error in configuration.Errors)
                                        {
                                            line += "<p>" + error + "</p>";
                                            sw.WriteLine(error);
                                        }
                                    }
                                }

                                else
                                {
                                    if (File.Exists(logFile))
                                    {
                                        File.Delete(logFile);
                                    }

                                    using (StreamWriter sw = File.CreateText(logFile))
                                    {
                                        foreach (string error in configuration.Errors)
                                        {
                                            line += "<p>" + error + "</p>";
                                            sw.WriteLine(error);
                                        }
                                    }

                                    errorWindow.getBrowser.DocumentText = line;
                                    errorWindow.Show();
                                }
                            }
                            else
                            {
                                if (File.Exists(logFile))
                                {
                                    File.Delete(logFile);
                                }

                                using (StreamWriter sw = File.CreateText(logFile))
                                {
                                    foreach (string error in ErrorList)
                                    {
                                        line += "<p>" + error + "</p>";
                                        sw.WriteLine(error);
                                    }
                                }

                                errorWindow.getBrowser.DocumentText = line;
                            }
                        }
                        else
                        {
                            string line = "<p>INVALID LOG FILE NAME</p>";
                            foreach (string error in ErrorList)
                            {
                                line += "<p>" + error + "</p>";
                            }


                            errorWindow.getBrowser.DocumentText = line;
                            errorWindow.Show();
                        }
                    }
                    else
                    {
                        string line = "<p>NO CONFIGURATION FILE FOUND </p>";
                        foreach (string error in errorsTaff)
                        {
                            line += "<p>" + error + "</p>";
                        }


                        errorWindow.getBrowser.DocumentText = line;
                        errorWindow.Show();
                    }
                }
                else
                {
                    string line = "<p>NO CONFIGURATION DATA FOUND </p>";
                    foreach (string error in errorsTaff)
                    {
                        line += "<p>" + error + "</p>";
                    }


                    errorWindow.getBrowser.DocumentText = line;
                    errorWindow.Show();
                }
            }
        }