Esempio n. 1
0
        internal void Partition(int pivot, out QSArray low, out QSArray high)
        {
            int i = -1;
            int j = array.Count;

            while (true)
            {
                do
                {
                    i++;
                }while (array[i] < pivot);
                do
                {
                    j--;
                }while (array[j] > pivot);
                if (i >= j)
                {
                    break;
                }
                QuickSort.Swap(array, i, j);
            }
            j++;

            low  = new QSArray(array.GetRange(0, j));
            high = new QSArray(array.GetRange(j, array.Count - j));
        }
Esempio n. 2
0
        internal int[] MergeDataFromWorkers()
        {
            if (IsGlobalManager)
            {
                QSArray result = null;
                for (int process = 0; process < globalGroup.Total; process++)
                {
                    var array = ReceiveGlobalArrayFrom(process, Tags.Collect);

                    if (result == null)
                    {
                        result = array;
                    }
                    else
                    {
                        result = QSArray.Merge(result, array);
                    }
                }

                return(result.GetContent());
            }
            else
            {
                throw new InvalidOperationException($"Not Global Manager");
            }
        }
Esempio n. 3
0
 private void SendSlicedArrayToAllSubProcesses(QSArray qsArray)
 {
     for (int process = 0; process < globalGroup.Communicator.Size; process++)
     {
         var part    = qsArray.GetPart(process, globalGroup.Communicator.Size);
         var request = globalGroup.Communicator.ImmediateSend <int[]>(part.GetContent(), process, Tags.ArrayPart);
     }
 }
Esempio n. 4
0
        public static QSArray Merge(QSArray low, QSArray high)
        {
            var array = new List <int>();

            array.AddRange(low.GetContent());
            array.AddRange(high.GetContent());

            return(new QSArray(array));
        }
Esempio n. 5
0
        internal void InitializeWithData(QSArray qsArray)
        {
            if (IsGroupManager)
            {
                SendSlicedArrayToAllSubProcesses(qsArray);
            }

            currentArray = ReceiveArrayPartFromManager(Tags.ArrayPart);
        }
Esempio n. 6
0
        internal void PartitionAndPartsExchange()
        {
            currentArray.Partition(currentPivot, out QSArray low, out QSArray high);

            int partner = group.IsLeftHalf ?
                          group.Current + group.Total / 2 :
                          group.Current - group.Total / 2;

            if (group.IsLeftHalf)
            {
                group.Communicator.ImmediateSend <int[]>(high.GetContent(), partner, Tags.Exchange);
                high = ReceiveArrayFrom(partner, Tags.Exchange);
            }
            else
            {
                group.Communicator.ImmediateSend <int[]>(low.GetContent(), partner, Tags.Exchange);
                low = ReceiveArrayFrom(partner, Tags.Exchange);
            }

            currentArray = QSArray.Merge(low, high);
        }