我正在尝试优化以下代码和平 - 有多次迭代会消耗大量时间。查看了 Parallel.For 示例,但不明白如何在我的情况下使用它们,因为我在每个“for”循环中都有“double”变量。你能帮忙吗?谢谢
public void maximization ()
{
int ii = 0; // counter to alter file name
int jj = 0; // counter for all output strings
string[] calculation;
ArrayList array = new ArrayList(); // temporary array for optimized parameters
for (pr_lower1 = -0.02; pr_lower1 <= 0.0; pr_lower1 = pr_lower1 + 0.002) //11
{
for (pr_upper1 = 0.002; pr_upper1 <= 0.02; pr_upper1 = pr_upper1 + 0.002) //10
{
for (OI_lower1 = 0.02; OI_lower1 <= 0.1; OI_lower1 = OI_lower1 + 0.01) //9
{
for (pr_lower2 = -0.02; pr_lower2 <= 0.0; pr_lower2 = pr_lower2 + 0.002) //11
{
for (pr_upper2 = 0.002; pr_upper2 <= 0.02; pr_upper2 = pr_upper2 + 0.002) //10
{
for (OI_lower2 = -0.1; OI_lower2 <= 0.0; OI_lower2 = OI_lower2 + 0.01) //11
{
for (OI_upper2 = 0.01; OI_upper2 <= 0.1; OI_upper2 = OI_upper2 + 0.01) //10
{
for (stop = 0.05; stop <= 0.27; stop = stop + 0.02) //12
{
for (tp = 0.05; tp <= 0.27; tp = tp + 0.02) //12
{
this.run_algo_max();
jj++;
string output = ret + " " + jj;
array.Add(output);
}
}
}
}
}
}
}
}
ii++;
calculation = (String[])array.ToArray(typeof(string));
array.Clear();
File.WriteAllLines(Application.StartupPath + "\\results" + ii + ".txt", calculation);
}
}