示例#1
0
        private async Task <double> ComputeSurvivalRate(List <RubisCell> cellList, int[] ready)
        {
            int coreCount = 12;
            List <Task <double> > tasks = new List <Task <double> >();
            int dividedLoad             = cellList.Count / coreCount;
            int remainder = cellList.Count % coreCount;

            int pos = 0;

            for (int i = 0; i < coreCount; i++)
            {
                int         actualLoad = dividedLoad + (i < remainder ? 1 : 0);
                RubisCell[] workLoad   = new RubisCell[actualLoad];
                Array.Copy(cellList.ToArray(), pos, workLoad, 0, actualLoad);
                WorkObject workObject = new WorkObject(workLoad, i, ready);
                pos += actualLoad;
                tasks.Add(ComputeSurvivalRateAsync(workObject));
            }

            await Task.WhenAll(tasks);

            double sum = 0.0;

            for (int i = 0; i < coreCount; i++)
            {
                sum += tasks[i].Result;
            }

            return(sum);
        }
 public RubisCell(RubisCell cell)
 {
     this.lat     = cell.lat;
     this.lon     = cell.lon;
     this.row     = cell.row;
     this.col     = cell.col;
     this.pdf     = cell.pdf;
     survivalRate = cell.survivalRate;
     stations     = new List <StationDistancePair>();
     foreach (StationDistancePair pair in cell.stations)
     {
         this.stations.Add(new StationDistancePair(pair.station, pair.distance));
     }
 }