Ejemplo n.º 1
0
        private void btnStop_Click(object sender, EventArgs e)
        {
            int    sum = 0;
            string msg = "";

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); //引用stopwatch物件
            sw.Reset();                                                           //碼表歸零
            sw.Start();                                                           //碼表開始計時
            object sync = new object();

            Parallel.For(1, 11, (i, LoopState) =>
            {
                if (i == 5)
                {
                    LoopState.Stop();
                }
                lock (sync) //若沒有Lock則會因競爭而有資料遺失
                {
                    sum = sum + i;
                }
                string buf = String.Format("i={0},sum={1}\n", i, sum);
                msg        = msg + buf;
            });
            sw.Stop();//碼錶停止
            string ParallelForResult = sw.Elapsed.TotalMilliseconds.ToString();

            rtxtResult.Text = string.Format("Stop執行結束:{0}毫秒。\n{1}", ParallelForResult, msg);
        }
Ejemplo n.º 2
0
        public void ReadHigh(string FolderPath, string[] StationNumber, string OutputFilePath)//给出大目录和所有站号,求出含有所有站号的文件
        {
            string HighPath = FolderPath;

            string[] dic = new string[] { " " };
            try
            {
                dic = System.IO.Directory.GetDirectories(@HighPath, "high*", SearchOption.AllDirectories);//获取子目录下所有对应的目录
            }
            catch
            {
                //output("error!");
            }
            Parallel.For(0, StationNumber.Count(), (si, LoopState) =>
            {
                if (si >= StationNumber.Count())
                {
                    LoopState.Stop();
                }
                string outfilename = OutputFilePath + @"\" + StationNumber[si] + @"high.txt";

                for (int i = 0; i < dic.Count(); i++)
                {
                    string[] result_line = HighFolder(dic[i], StationNumber[si]);
                    for (int rl = 0; rl < result_line.Count(); rl++)
                    {
                        System.IO.File.AppendAllText(outfilename, result_line[rl], Encoding.GetEncoding("GB2312"));
                    }
                }
            });
        }
Ejemplo n.º 3
0
        public static double[,] Subsititution(Data.Condition condition, int dpi, ref int iterate, double omega = 0, double[,] grid = null, double conv = 0)
        {
            if (grid == null)
            {
                grid = new double[condition.X_LMax * dpi, condition.Y_LMax *dpi];
            }

            double[,] temp = new double[condition.X_LMax * dpi, condition.Y_LMax *dpi];
            int cnt = 0;

            Parallel.For(0, iterate, (i, LoopState) =>
            {
                double max = 0;
                for (int x = 1; x + 1 < condition.X_LMax * dpi; x++)
                {
                    for (int y = 1; y + 1 < condition.Y_LMax * dpi; y++)
                    {
                        if (x >= condition.X_Pos * dpi && y >= condition.Y_Pos * dpi)
                        {
                            if (x <= (condition.X_LMax - condition.X_Pos) * dpi && y <= (condition.Y_LMax - condition.Y_Pos) * dpi)
                            {
                                grid[x, y] = 1;
                                continue;
                            }
                        }
                        double data = grid[x, y];
                        if (omega == 0)
                        {
                            temp[x, y] = 0.25 * (grid[x + 1, y] + grid[x - 1, y] + grid[x, y + 1] + grid[x, y - 1]);
                            max        = Math.Abs(data - temp[x, y]) > max ? Math.Abs(data - temp[x, y]) : max;
                            continue;
                        }
                        temp[x, y] = grid[x, y] + omega * (0.25 * (grid[x + 1, y] + grid[x - 1, y] + grid[x, y + 1] + grid[x, y - 1]) - grid[x, y]);
                        max        = Math.Abs(data - temp[x, y]) > max ? Math.Abs(data - temp[x, y]) : max;
                    }
                }
                grid = temp;

                if (conv != 0)
                {
                    if (max < conv)
                    {
                        LoopState.Stop();
                    }
                }
                //cnt = i;
                lock ((object)cnt)
                {
                    cnt++;
                }
            });
            iterate = cnt;
            return(grid);
        }
Ejemplo n.º 4
0
        public string[] SurfaceFolder(string SurferPath, string StationNumber)//给出地面文件具体路径和单个站号,返回字符串数组
        {
            string FilePath = SurferPath + @"\plot\";

            string[]      name          = new string[] { " " };
            List <string> StationString = new List <string>();

            name = System.IO.Directory.GetFiles(@FilePath, "*.000");
            Parallel.For(0, name.Count(), (i, LoopState) =>
            {
                if (i >= name.Count())
                {
                    LoopState.Stop();
                }
                StationString.Add(CheckMiacaps1(name[i], StationNumber));
            });
            return(StationString.ToArray());
        }
Ejemplo n.º 5
0
        public string[] HighFolder(string HighPath, string StationNumber)//给出高空文件具体路径和单个站号,返回字符串数组
        {
            string[]      height        = { "100", "150", "200", "250", "300", "400", "500", "700", "850", "925", "1000" };
            List <string> StationString = new List <string>();

            StationString.Clear();
            for (int ii = 0; ii < height.Count(); ii++)
            {
                string   FilePath = HighPath + @"\plot\" + height[ii] + "\\";
                string[] name     = new string[] { " " };
                name = System.IO.Directory.GetFiles(@FilePath, "*.000");
                Parallel.For(0, name.Count(), (i, LoopState) =>
                {
                    if (i >= name.Count())
                    {
                        LoopState.Stop();
                    }
                    StationString.Add(CheckMiacaps2(name[i], StationNumber));
                });
            }
            return(StationString.ToArray());
        }