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)); }
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"); } }
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); } }
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)); }
internal void InitializeWithData(QSArray qsArray) { if (IsGroupManager) { SendSlicedArrayToAllSubProcesses(qsArray); } currentArray = ReceiveArrayPartFromManager(Tags.ArrayPart); }
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); }