コード例 #1
0
        //What happens when you press Map Reduce, number represents how many threads.
        private void map_reduce_button_Click(object sender, EventArgs e)
        {
            try
            {
                resultsTextBox.Text = "";                                             //Clear current text in text box.
                threads             = (int)threadsTextBox.Value;                      //Number of threads.

                var usageBytes0 = GC.GetTotalMemory(true);                            //Memory usage after GC and before processing.
                var watch       = System.Diagnostics.Stopwatch.StartNew();            //Start a timer for calculations.

                Results res = MapReduce.MainMapReduceThread(processingData, threads); //Activate MapReduce

                watch.Stop();                                                         //End timer for calculation
                var usageBytes = GC.GetTotalMemory(false) - usageBytes0;              //Memory usage after processing/before GC. Minus previous memory.
                var elapsedMs  = watch.ElapsedMilliseconds;                           //Get timer value

                resultsTextBox.Text  = DataFunc.ResultsText(res);                     //Push results into Textbox
                resultsTextBox.Text += "Overall run time: " + elapsedMs + " miliseconds. \n";
                resultsTextBox.Text += "Current memory usage: " + usageBytes / 1024 + " KB";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        //Maps the split data for the "computers" - our threads. Each thread has one table.
        public static void Map(DataTable dt, int threads)
        {
            finalRes = new Results[threads];
            thr      = new Thread[threads];
            DataTable[] splitDT = MapReduce.TableSplit(dt, threads);

            if (splitDT.Length == threads + 1) //**In a case where taking a bigger chunk isn't worth is (small table) merge the 2 last tables.
            {
                splitDT[threads - 1].Merge(splitDT[threads]);
            }

            for (int i = 0; i < threads; i++)
            {
                int temp = i;                                                           //Using Lambda function and return values in threads forces this temp variable.
                thr[i] = new Thread(() => finalRes[temp] = ProcessData(splitDT[temp])); //Whatever the thread returns, will return to finalRes.
            }
        }