public DbScore ToDb() { return(new() { Count50 = Count50, Count100 = Count100, Count300 = Count300, CountGeki = CountGeki, CountKatu = CountKatu, CountMiss = CountMiss, FileChecksum = FileChecksum, PerformancePoints = PerformancePoints, Accuracy = Accuracy, MaxCombo = MaxCombo, Passed = Passed, Relaxing = Relaxing, AutoPiloting = Autopiloting, Mods = Mods, PlayMode = PlayMode, UserId = User.Id, Date = Date, ReplayChecksum = ReplayChecksum, TotalScore = TotalScore, Flags = Flags, OsuVersion = OsuVersion, Completed = Completed }); }
public override void main() { Console.WriteLine(this.PeerRank + ": HELLO ! I AM LEFT !"); //Thread.Sleep (10000); string s = this.PeerRank + " --- Hello from LEFT to RIGHT "; Console.WriteLine(this.PeerRank + "- BEGIN left sent " + s + " to <1," + this.PeerRank + ">"); /* // SEND ARRAY * this.Binding.Send<string> (new string[1]{s + " 0"}, new Tuple<int,int> (1, this.PeerRank), 0); * this.Binding.Send<string> (new string[1]{s + " 1"}, new Tuple<int,int> (1, this.PeerRank), 1); * * // SEND SINGLETON * this.Binding.Send<string> (s + " 2", new Tuple<int,int> (1, this.PeerRank), 2); * this.Binding.Send<string> (s + " 3", new Tuple<int,int> (1, this.PeerRank), 3); */ // SEND IMMEDIATE ARRAY Request r0 = this.Binding.ImmediateSend <string> (new string[1] { s + " 0 - immediate" }, new Tuple <int, int> (1, this.PeerRank), 44); Request r1 = this.Binding.ImmediateSend <string> (new string[1] { s + " 1 - immediate" }, new Tuple <int, int> (1, this.PeerRank), 55); // SEND IMMEDIATE SINGLETON Request r2 = this.Binding.ImmediateSend <string> (s + " 2 - immediate", new Tuple <int, int> (1, this.PeerRank), 66); Request r3 = this.Binding.ImmediateSend <string> (s + " 3 - immediate", new Tuple <int, int> (1, this.PeerRank), 77); CompletedStatus t0 = r0.Wait(); CompletedStatus t1 = r1.Wait(); CompletedStatus t2 = r2.Wait(); CompletedStatus t3 = r3.Wait(); Console.WriteLine(this.PeerRank + "- END left sent " + s + " to <1," + t0.Source + "/" + t0.Tag + "/" + t0.Cancelled + "/" + t0.Count() + "-" + t1.Source + "/" + t1.Tag + "/" + t0.Cancelled + "/" + t0.Count() + "-" + t2.Source + "/" + t2.Tag + "/" + t0.Cancelled + "/" + t0.Count() + "-" + t3.Source + "/" + t3.Tag + "/" + t0.Cancelled + "/" + t0.Count() + ">"); }
static void TestRequests(Intracommunicator comm, RequestList requestList) { int datum = comm.Rank; int expectedDatum = (comm.Rank + comm.Size - 1) % comm.Size; int[] intArraySendBuffer = new int[comm.Rank + 1]; string[] strArraySendBuffer = new string[comm.Rank + 1]; for (int i = 0; i <= comm.Rank; ++i) { intArraySendBuffer[i] = i; strArraySendBuffer[i] = i.ToString(); } int[] intArrayRecvBuffer = new int[expectedDatum + 1]; string[] strArrayRecvBuffer = new string[expectedDatum + 1]; Request[] requests = new Request[8]; requests[0] = comm.ImmediateReceive <int>(Communicator.anySource, 0); requests[1] = comm.ImmediateReceive <string>(Communicator.anySource, 1); requests[2] = comm.ImmediateReceive(Communicator.anySource, 2, intArrayRecvBuffer); requests[3] = comm.ImmediateReceive(Communicator.anySource, 3, strArrayRecvBuffer); requests[4] = comm.ImmediateSend(datum, (comm.Rank + 1) % comm.Size, 0); requests[5] = comm.ImmediateSend(datum.ToString(), (comm.Rank + 1) % comm.Size, 1); requests[6] = comm.ImmediateSend(intArraySendBuffer, (comm.Rank + 1) % comm.Size, 2); requests[7] = comm.ImmediateSend(strArraySendBuffer, (comm.Rank + 1) % comm.Size, 3); if (requestList == null) { // Complete all communications manually bool allDone = false; while (!allDone) { allDone = true; for (int i = 0; i < requests.Length; ++i) { allDone = allDone && requests[i].Test() != null; } } } else { // Use the request list to complete all communications for (int i = 0; i < requests.Length; ++i) { requestList.Add(requests[i]); } requestList.WaitAll(); } ReceiveRequest intRecv = (ReceiveRequest)requests[0]; CompletedStatus intStatus = intRecv.Wait(); if ((int)intRecv.GetValue() != expectedDatum || intStatus.Source != expectedDatum || intStatus.Tag != 0) { System.Console.Error.WriteLine("error in non-blocking receive of integer: got " + (int)intRecv.GetValue() + " from " + intStatus.Source + " on tag " + intStatus.Tag + ", expected " + expectedDatum); MPI.Environment.Abort(-1); } ReceiveRequest strRecv = (ReceiveRequest)requests[1]; CompletedStatus strStatus = strRecv.Wait(); if ((string)strRecv.GetValue() != expectedDatum.ToString() || strStatus.Source != expectedDatum || strStatus.Tag != 1) { System.Console.Error.WriteLine("error in non-blocking receive of string: got " + strRecv.GetValue() + " from " + strStatus.Source + " on tag " + strStatus.Tag + ", expected " + expectedDatum); MPI.Environment.Abort(-1); } ReceiveRequest intArrayRecv = (ReceiveRequest)requests[2]; CompletedStatus intArrayStatus = intArrayRecv.Wait(); if (intArrayRecv.GetValue() != intArrayRecvBuffer || intArrayStatus.Source != expectedDatum || intArrayStatus.Tag != 2) { System.Console.WriteLine("error: received into the wrong integer array"); MPI.Environment.Abort(-1); } for (int i = 0; i <= expectedDatum; ++i) { if (intArrayRecvBuffer[i] != i) { System.Console.WriteLine("error: intArrayRecv[" + i + "] is " + intArrayRecvBuffer[i] + ", expected " + i); MPI.Environment.Abort(-1); } } ReceiveRequest strArrayRecv = (ReceiveRequest)requests[3]; CompletedStatus strArrayStatus = strArrayRecv.Wait(); if (strArrayRecv.GetValue() != strArrayRecvBuffer || strArrayStatus.Source != expectedDatum || strArrayStatus.Tag != 3) { System.Console.WriteLine("error: received into the wrong string array"); MPI.Environment.Abort(-1); } for (int i = 0; i <= expectedDatum; ++i) { if (strArrayRecvBuffer[i] != i.ToString()) { System.Console.WriteLine("error: strArrayRecv[" + i + "] is " + strArrayRecvBuffer[i] + ", expected " + i.ToString()); MPI.Environment.Abort(-1); } } }
// Receive Array void Aliencommunicator.Receive <T> (Tuple <int, int> source, int tag, ref T[] values, out CompletedStatus status) { this.RootCommunicator.Send <AliencommunicatorOperation>(AliencommunicatorOperation.RECEIVE_ARRAY, 0, TAG_SEND_OPERATION + 0); alien_communicator.Receive <T> (source, tag, ref values, out status); }
public static void CommunicatorThread() { while (true) { waitForCommunicationHandle.WaitOne(); int[] msgArray = new int[4 + journal.processesNumber]; var request = comm.ImmediateReceive(Communicator.anySource, Communicator.anyTag, msgArray); waitForCommunicationHandle.Set(); CompletedStatus probeResult = null; while (probeResult == null) { waitForCommunicationHandle.WaitOne(); probeResult = request.Test(); waitForCommunicationHandle.Set(); Thread.Sleep(20); } waitForCommunicationHandle.WaitOne(); //Obsłużenie otrzymania zgody if (probeResult.Tag == MSG_ACCEPT) { AcceptMessage msg = MessageArrays.AcceptArrayToMsg(msgArray); journal.CompareTimestampsAndUpdate(msg.Timestamp); journal.IncrementTimestamp(); //Console.WriteLine($"Proces {journal.shipRank}: dostałem ACCEPT od procesu {msg.SenderRank}."); journal.Accepts.Add(msg); if (journal.RememberedClock < msg.LogicalClock) //sprawdzenie zegara i zapamiętanie danych z wiadomości, jeśli nowszy { journal.RememberedClock = msg.LogicalClock; journal.RememberedOccupancy = msg.CurrentOccupancy; journal.RememberedLeavingCounters = msg.LeavingCounters; //Console.WriteLine($"Proces {journal.shipRank}: Dostałem zgodę ze świeższym statusem, od procesu {msg.SenderRank}, według niego zajętość to {msg.CurrentOccupancy}."); } if (journal.Accepts.Count == journal.processesNumber - 1) //wszystkie zgody otrzymane { journal.CanalOfInterest.CompareClocksAndUpdate(journal.RememberedClock); journal.CanalOfInterest.CurrentOccupancy = journal.RememberedOccupancy; journal.CanalOfInterest.CurrentOccupancy++; //oznaczamy miejsca zwolnione przez procesy, o których wiemy, że wyszły z kanału, a wysyłający nam najświeższą zgodę nie zdążył się o tym dowiedzieć przed wysłaniem for (int i = 0; i < msg.LeavingCounters.Count; i++) { if (journal.CanalOfInterest.LeavingCounters[i] > journal.RememberedLeavingCounters[i]) { //Console.WriteLine($"Proces {journal.shipRank}: MUSZĘ ZAKTUALIZOWAĆ CURRENT OCCUPANCY! Według mnie leaving counter dla procesu {i} wynosi {journal.CanalOfInterest.LeavingCounters[i]}, a według drugiego procesu {journal.RememberedLeavingCounters[i]}."); journal.CanalOfInterest.CurrentOccupancy -= journal.CanalOfInterest.LeavingCounters[i] - journal.RememberedLeavingCounters[i]; } if (journal.CanalOfInterest.LeavingCounters[i] < journal.RememberedLeavingCounters[i]) { journal.CanalOfInterest.LeavingCounters[i] = journal.RememberedLeavingCounters[i]; } } journal.IsDemandingEntry = false; journal.CanalOfInterest.IncrementClock(); if (journal.CanalOfInterest.CurrentOccupancy == journal.CanalOfInterest.maxOccupancy) //jeśli jesteśmy ostatnim mieszczącym się w kanale procesem { //Console.WriteLine($"Proces {journal.shipRank}: kanał {journal.CanalOfInterest.ID} jest teraz pełny."); journal.IsBlockingCanalEntry = true; } else //jeśli uważamy, że jest jeszcze miejsce (nie jesteśmy ostatnim mieszczącym się procesem), wysyłamy zgody wszystkim, którzy czekają { int currentOccupancy = journal.CanalOfInterest.CurrentOccupancy; int logicalClock = journal.CanalOfInterest.LogicalClock; List <int> leavingCounters = journal.CanalOfInterest.LeavingCounters; journal.IncrementTimestamp(); AcceptMessage accept = new AcceptMessage(journal.shipRank, journal.Timestamp, currentOccupancy, logicalClock, leavingCounters); int[] acceptArray = MessageArrays.AcceptMsgToArray(accept); foreach (DemandMessage demand in journal.DemandsForSameDirection) { comm.Send(acceptArray, demand.SenderRank, MSG_ACCEPT); //Console.WriteLine($"Proces {journal.shipRank}: po moim wejściu kanał ma jeszcze miejsce, więc wysyłam ACCEPT do procesu {demand.SenderRank} do kanału {demand.Canal}."); } journal.DemandsForSameDirection.Clear(); } journal.Accepts.Clear(); waitForAcceptsHandle.Set(); //zwolnienie blokady } } //Obsłużenie otrzymania żądania if (probeResult.Tag == MSG_DEMAND) { DemandMessage msg = MessageArrays.DemandArrayToMsg(msgArray); journal.CompareTimestampsAndUpdate(msg.Timestamp); journal.IncrementTimestamp(); //Console.WriteLine($"Proces {journal.shipRank}: dostałem DEMAND od procesu {msg.SenderRank}."); bool accept = false; if (msg.Direction != journal.DirectionOfInterest) //jeśli żądany jest przeciwny kierunek do naszego { if (journal.CanalOfInterest == null || msg.Canal != journal.CanalOfInterest.ID) //jeśli żądany jest kanał, który nas nie obchodzi { accept = true; } else if (journal.IsDemandingEntry && (msg.Timestamp < journal.MyDemandTimestamp || (msg.Timestamp == journal.MyDemandTimestamp && msg.SenderRank > journal.shipRank))) //jeśli nie jesteśmy jeszcze w kanale, a konkurujący ma starsze żądanie (niższy timestamp) lub tak samo stare żądanie, lecz wyższą rangę { accept = true; } } else //jeśli żądany jest ten sam kierunek { if (journal.CanalOfInterest == null || msg.Canal != journal.CanalOfInterest.ID) //jeśli żądany jest kanał, który nas nie obchodzi { accept = true; } else if (journal.IsDemandingEntry && (msg.Timestamp < journal.MyDemandTimestamp || (msg.Timestamp == journal.MyDemandTimestamp && msg.SenderRank > journal.shipRank))) //jeśli nie jesteśmy jeszcze w kanale, a konkurujący ma starsze żądanie (niższy timestamp) lub tak samo stare żądanie, lecz wyższą rangę { accept = true; } else if (!journal.IsDemandingEntry && !journal.IsBlockingCanalEntry) //jeśli jesteśmy w kanale (nie ubiegamy się o dostęp), ale nie blokujemy dostępu do kanału { accept = true; } } if (accept) { Canal desiredCanal = journal.ExistingCanals[msg.Canal]; int currentOccupancy = desiredCanal.CurrentOccupancy; int logicalClock = desiredCanal.LogicalClock; List <int> leavingCounters = desiredCanal.LeavingCounters; journal.IncrementTimestamp(); //Console.WriteLine($"Proces {journal.shipRank}: Wysyłam zgodę procesowi {msg.SenderRank} do kanału {msg.Canal}, według mnie leaving counter żądającego w żądanym kanale to {leavingCounters[msg.SenderRank]}."); AcceptMessage acceptMessage = new AcceptMessage(journal.shipRank, journal.Timestamp, currentOccupancy, logicalClock, leavingCounters); int[] acceptArray = MessageArrays.AcceptMsgToArray(acceptMessage); string logString = $"Proces {journal.shipRank}: wysyłana zgoda ma następujące wartości pól - Ranga: {acceptMessage.SenderRank}, Zajętość: {acceptMessage.CurrentOccupancy}, Zegar: {acceptMessage.LogicalClock}, Leaving counters: "; foreach (int process in acceptMessage.LeavingCounters) { logString += $"{process} "; } //Console.WriteLine(logString); comm.Send(acceptArray, msg.SenderRank, MSG_ACCEPT); } else { if (msg.Direction == journal.DirectionOfInterest) { journal.DemandsForSameDirection.Add(msg); } else { journal.DemandsForOppositeDirection.Add(msg); } } } //Obsłużenie otrzymania wiadomości o wyjściu z kanału if (probeResult.Tag == MSG_LEAVE) { LeaveMessage msg = MessageArrays.LeaveArrayToMsg(msgArray); journal.CompareTimestampsAndUpdate(msg.Timestamp); journal.IncrementTimestamp(); Canal canal = journal.ExistingCanals[msg.Canal]; //Jeżeli jeszcze nie wiemy o tym wyjściu if (canal.LeavingCounters[msg.SenderRank] < msg.LeavingCounter) { //Console.WriteLine($"Proces {journal.shipRank}: dostałem LEAVE od procesu {msg.SenderRank} z kanału {msg.Canal}, jego leaving counter to {msg.LeavingCounter}, a mój {canal.LeavingCounters[msg.SenderRank]}."); //Aktualizacja licznika wyjść procesu z kanału canal.LeavingCounters[msg.SenderRank] = msg.LeavingCounter; //Jeśli jesteśmy blokującym procesem w tym kanale, zwalniamy miejsce i wysyłamy zgodę wszystkim na naszej liście oczekujących w tym samym kierunku canal.CurrentOccupancy--; if (journal.CanalOfInterest != null && journal.CanalOfInterest.ID == msg.Canal && journal.IsBlockingCanalEntry) { int currentOccupancy = canal.CurrentOccupancy; int logicalClock = canal.LogicalClock; List <int> leavingCounters = canal.LeavingCounters; journal.IncrementTimestamp(); AcceptMessage accept = new AcceptMessage(journal.shipRank, journal.Timestamp, currentOccupancy, logicalClock, leavingCounters); int[] acceptArray = MessageArrays.AcceptMsgToArray(accept); foreach (DemandMessage demand in journal.DemandsForSameDirection) { comm.Send(acceptArray, demand.SenderRank, MSG_ACCEPT); } journal.IsBlockingCanalEntry = false; journal.DemandsForSameDirection.Clear(); } } } waitForCommunicationHandle.Set(); } }
public override void main() { Console.WriteLine(this.PeerRank + ": HELLO ! I AM RIGHT !!!"); /* // RECEIVE ARRAY * Tuple<int,int> source0 = new Tuple<int,int> (0, this.PeerRank); * string[] s0 = new string[1]; this.Binding.Receive<string> (source0, 0, ref s0); * Console.WriteLine (this.PeerRank + "- RECEIVED right " + s0 + " from " + source0); * * Tuple<int,int> source1 = new Tuple<int,int> (0, this.PeerRank); * string[] s1 = new string[1]; this.Binding.Receive<string> (source1, 1, ref s1); * Console.WriteLine (this.PeerRank + "- RECEIVED right " + s1 + " from " + source1); * * // RECEIVE SINGLETON * Tuple<int,int> source2 = new Tuple<int,int> (0, this.PeerRank); * string s2 = this.Binding.Receive<string> (source2, 2); * Console.WriteLine (this.PeerRank + "- RECEIVED right " + s2 + " from " + source2); * * Tuple<int,int> source3 = new Tuple<int,int> (0, this.PeerRank); * string s3 = this.Binding.Receive<string> (source3, 3); * Console.WriteLine (this.PeerRank + "- RECEIVED right " + s3 + " from " + source3); */ // ------------------------------- // RECEIVE IMMEDIATE ARRAY string[] b0 = new string[1]; Tuple <int, int> source4 = new Tuple <int, int> (0, this.PeerRank); ReceiveRequest r0 = this.Binding.ImmediateReceive <string> (source4, 44, b0); string[] b1 = new string[1]; Tuple <int, int> source5 = new Tuple <int, int> (0, this.PeerRank); ReceiveRequest r1 = this.Binding.ImmediateReceive <string> (source5, 55, b1); // RECEIVE IMMEDIATE SINGLETON Tuple <int, int> source6 = new Tuple <int, int> (0, this.PeerRank); ReceiveRequest r2 = this.Binding.ImmediateReceive <string> (source6, 66); Tuple <int, int> source7 = new Tuple <int, int> (0, this.PeerRank); ReceiveRequest r3 = this.Binding.ImmediateReceive <string> (source7, 77); CompletedStatus t0 = r0.Wait(); string[] s4 = r0.GetValue() as string[]; Console.WriteLine(this.PeerRank + "- RECEIVED right " + b0[0] + " from " + t0.Source + " tag=" + t0.Tag + " cancelled=" + t0.Cancelled + " count=" + t0.Count()); CompletedStatus t1 = r1.Wait(); string[] s5 = r1.GetValue() as string[]; Console.WriteLine(this.PeerRank + "- RECEIVED right " + b1[0] + " from " + t1.Source + " tag=" + t1.Tag + " cancelled=" + t1.Cancelled + " count=" + t1.Count()); CompletedStatus t2 = r2.Wait(); string s6 = r2.GetValue() as string; Console.WriteLine(this.PeerRank + "- RECEIVED right " + s6 + " from " + t2.Source + " tag=" + t2.Tag + " cancelled=" + t2.Cancelled + " count=" + t2.Count()); CompletedStatus t3 = r3.Wait(); string s7 = r3.GetValue() as string; Console.WriteLine(this.PeerRank + "- RECEIVED right " + s7 + " from " + t3.Source + " tag=" + t3.Tag + " cancelled=" + t3.Cancelled + " count=" + t3.Count()); }