private void CustomMessageHandler(object data, IRemoteXTMF client) { if (data is int) { Jobs.Add((int)data); } }
private void ClientDisconnected(IRemoteXTMF obj) { // Recover the lost data by putting it back on the processing Queue lock (this) { bool othersStillProcessing = false; var populationLength = this.Population.Length; for (int i = 0; i < populationLength; i++) { if (this.Population[i].ProcessedBy != obj && this.Population[i].Processing == true && this.Population[i].Processed == false) { othersStillProcessing = true; } if (this.Population[i].ProcessedBy == obj && this.Population[i].Processing == true && this.Population[i].Processed == false) { this.Population[i].ProcessedBy = null; this.Population[i].Processing = false; } } if (!othersStillProcessing) { this.StartGeneration.Add(new StartGenerationMessage()); } } }
private void UpdateTaskAssignments() { lock (Host) { for (int i = 0; i < PendingTasks.Count; i++) { if (AvailableClients.Count > 0) { var task = PendingTasks[0]; IRemoteXTMF previousHost = null; if (PreferPreviousClient && PreviousTaskAssignments.TryGetValue(task.TaskName, out previousHost) && AvailableClients.Contains(previousHost)) { RemoveClient(previousHost); task.Client = previousHost; } else { task.Client = AvailableClients.Pop(); } task.TaskNumber = GetTaskNumber(); PreviousTaskAssignments[task.TaskName] = task.Client; ExecutingTasks.Add(task); // clean up PendingTasks.RemoveAt(0); // fire the message to start processing task.Client.SendCustomMessage(task, DistributionDataChannel); } else { return; } } } }
/// <summary> /// </summary> /// <param name="o"></param> /// <param name="r"></param> /// <param name="s"></param> private void SendParametersToEvaluate(object o, IRemoteXTMF r, Stream s) { lock (this) { var message = (ResultMessage)o; var index = message.ProcessedIndex; var toProcess = Population[index]; var parameters = toProcess.Parameters; BinaryWriter writer = new BinaryWriter(s); writer.Write(CurrentIteration); writer.Write(index); int total = 0; for (int i = 0; i < parameters.Length; i++) { total += parameters[i].Names.Length; } writer.Write(total); for (int i = 0; i < parameters.Length; i++) { for (int j = 0; j < parameters[i].Names.Length; j++) { writer.Write(parameters[i].Names[j]); writer.Write(parameters[i].Current); } } writer.Flush(); } }
/// <summary> /// The calling method must have the Host lock! /// </summary> /// <param name="toRemove">The client to remove</param> private void RemoveClient(IRemoteXTMF toRemove) { AvailableClients = new Stack <IRemoteXTMF>( from client in AvailableClients where client != toRemove select client); }
private void ClientDisconnected(IRemoteXTMF obj) { // Recover the lost data by putting it back on the processing Queue lock (this) { Configuration.DeleteProgressReport(obj.UniqueID); bool othersStillProcessing = false; var populationLength = Population.Length; for (int i = 0; i < populationLength; i++) { if (Population[i].ProcessedBy != obj && Population[i].Processing && Population[i].Processed == false) { othersStillProcessing = true; } if (Population[i].ProcessedBy == obj && Population[i].Processing && Population[i].Processed == false) { Population[i].ProcessedBy = null; Population[i].Processing = false; } } if (!othersStillProcessing) { StartGeneration.Add(new StartGenerationMessage()); } } }
private void ProcessEvaluation(object evaluation, IRemoteXTMF r) { if (evaluation is ResultMessage message) { ResultQueue.Add(message); } }
private void NewClientConnected(IRemoteXTMF obj) { // Setup a new model system for them to execute var msCopy = this.ModelSystemToExecute.Clone() as IModelSystemStructure; this.FixParameters(msCopy); this.Host.ExecuteModelSystemAsync(msCopy); }
private void NewClientConnected(IRemoteXTMF obj) { // Setup a new model system for them to execute var msCopy = ModelSystemToExecute.Clone(); FixParameters(msCopy); Host.ExecuteModelSystemAsync(msCopy); }
void HostModule_NewClientConnected(IRemoteXTMF obj) { this.NoneConnected = false; this.Configuration.CreateProgressReport(obj.UniqueID == null ? "Remote Host" : obj.UniqueID, delegate() { return(obj.Progress); }, new Tuple <byte, byte, byte>(150, 50, 50)); }
private void ProcessEvaluation(object evaluation, IRemoteXTMF r) { var message = evaluation as ResultMessage; if (message != null) { this.ResultQueue.Add(message); } }
void Host_ClientRunComplete(IRemoteXTMF arg1, int arg2, string arg3) { lock (this) { System.Threading.Thread.MemoryBarrier(); this.Progress += 1.0f / this.Iterations; this.completed++; System.Threading.Thread.MemoryBarrier(); } }
private void Host_NewClientConnected(IRemoteXTMF obj) { lock (this) { ConnectedClients.Add(obj); } Configuration.CreateProgressReport(obj.UniqueID ?? "Remote Host", delegate { return(obj.Progress); }, new Tuple <byte, byte, byte>(150, 50, 50)); }
private void NewClientConnected(IRemoteXTMF obj) { // Setup a new model system for them to execute lock (this) { obj.SendModelSystem(ModelSystemToExecute); Configuration.CreateProgressReport(obj.UniqueID == null ? "Remote Host" : obj.UniqueID, delegate { return(obj.Progress); }, new Tuple <byte, byte, byte>(50, 50, 150)); } }
private void Host_ProgressUpdated(IRemoteXTMF arg1, float arg2) { var totalProgress = 0f; lock (this) { foreach (var client in this.ConnectedClients) { totalProgress += client.Progress; } } this.Progress = totalProgress / this.NumberOfChildren; }
private void SendNewJob(IRemoteXTMF client) { System.Threading.Thread.MemoryBarrier(); int i = IndexOfNextJob(); if (i >= 0) { CurrentJobs[i].Processing = true; CurrentJobs[i].ProcessedBy = client; System.Threading.Thread.MemoryBarrier(); client.SendCustomMessage(i, RequestJobChannel); } }
private void Host_ClientDisconnected(IRemoteXTMF disconnectingClient) { lock (Host) { var unfinishedTasks = ExecutingTasks.Where(task => task.Client == disconnectingClient && task.Complete == false); RemoveClient(disconnectingClient); foreach (var unfinishedTask in unfinishedTasks) { unfinishedTask.Client = null; unfinishedTask.Complete = false; unfinishedTask.TaskNumber = 0; PendingTasks.Add(unfinishedTask); } } UpdateTaskAssignments(); }
/// <summary> /// Process the custom message /// </summary> /// <param name="memory"></param> /// <param name="r"></param> /// <returns></returns> private object ReadEvaluation(Stream memory, IRemoteXTMF r) { BinaryReader reader = new BinaryReader(memory); ResultMessage ret = new ResultMessage(); var generation = reader.ReadInt32(); ret.ProcessedIndex = reader.ReadInt32(); if (ret.ProcessedIndex == -1) { SendNextParameter(r); return(null); } ret.ProcessedValue = reader.ReadSingle(); SendNextParameter(r); return(CurrentIteration == generation ? ret : null); }
/// <summary> /// </summary> /// <param name="o"></param> /// <param name="remote"></param> /// <param name="s"></param> private void SendParametersToEvaluate(object o, IRemoteXTMF remote, Stream s) { lock (this) { var message = (ResultMessage)o; var index = message.ProcessedIndex; var toProcess = Population[index]; var length = toProcess.Parameters.Length; BinaryWriter writer = new BinaryWriter(s); writer.Write(CurrentIteration); writer.Write(index); writer.Write(length); for (int i = 0; i < length; i++) { writer.Write(toProcess.Parameters[i].Current); } } }
private void SendNextParameter(IRemoteXTMF client) { ResultMessage msg = new ResultMessage(); lock (this) { // make sure we have the newest memory loaded up Thread.MemoryBarrier(); var populationLength = Population.Length; for (int i = 0; i < populationLength; i++) { if (Population[i].Processing == false) { Population[i].ProcessedBy = client; Population[i].Processing = true; msg.ProcessedIndex = i; client.SendCustomMessage(msg, 1); break; } } // make sure changes have gone through Thread.MemoryBarrier(); } }
private object ClientReady(Stream o, IRemoteXTMF client) { return(null); }
private object CustomMessageReceiver(Stream inputStream, IRemoteXTMF client) { return(null); }
void Host_ProgressUpdated(IRemoteXTMF origin, float progress) { // we don't need to monitor the progress since we will periodically poll the clients }
private object CustomMessageReceiver(System.IO.Stream inputStream, IRemoteXTMF client) { return null; }
void Host_ClientDisconnected(IRemoteXTMF obj) { this.NoneConnected = true; }
private void ClientWantsHouseholds2(object o, IRemoteXTMF client) { // Send the household data! client.SendCustomMessage(null, 2); }
private void CustomMessageHandler(object data, IRemoteXTMF client) { if ( data is int ) { this.Jobs.Add( (int)data ); } }
private void Host_ClientDisconnected(IRemoteXTMF disconnectingClient) { lock (Host) { var unfinishedTasks = ExecutingTasks.Where(task => task.Client == disconnectingClient && task.Complete == false); RemoveClient(disconnectingClient); Clients.Remove(disconnectingClient); foreach(var unfinishedTask in unfinishedTasks) { unfinishedTask.Client = null; unfinishedTask.Complete = false; unfinishedTask.TaskNumber = 0; PendingTasks.Add(unfinishedTask); } } UpdateTaskAssignments(); }
private void Host_NewClientConnected(IRemoteXTMF client) { // Handle a new client }
private void Host_ProgressUpdated(IRemoteXTMF client, float progress) { }
void HostModule_NewClientConnected(IRemoteXTMF obj) { this.NoneConnected = false; this.Configuration.CreateProgressReport(obj.UniqueID == null ? "Remote Host" : obj.UniqueID, delegate() { return obj.Progress; }, new Tuple<byte, byte, byte>(150, 50, 50)); }
private void Host_ClientDisconnected(IRemoteXTMF client) { }
private void CustomMessageSender(object data, IRemoteXTMF client, System.IO.Stream outputStream) { }
private void ClientReady2(object o, IRemoteXTMF client) { ConnectedClients.Add(client); SendNextParameter(client); }
private void SendHouseholds(object o, IRemoteXTMF r, Stream s) { s.Write(HouseholdData, 0, HouseholdData.Length); s.Flush(); }
private object ClientWantsHouseholds(Stream o, IRemoteXTMF client) { return(null); }
private void Host_ClientRunComplete(IRemoteXTMF arg1, int arg2, string arg3) { System.Threading.Interlocked.Increment( ref this.CompletedCount ); }
void Host_ClientRunComplete(IRemoteXTMF arg1, int arg2, string arg3) { lock (this) { System.Threading.Thread.MemoryBarrier(); this.Progress += 1.0f/this.Iterations; this.completed++; System.Threading.Thread.MemoryBarrier(); } }
private void Host_ProgressUpdated(IRemoteXTMF arg1, float arg2) { var totalProgress = 0f; lock ( this ) { foreach ( var client in this.ConnectedClients ) { totalProgress += client.Progress; } } this.Progress = totalProgress / this.NumberOfChildren; }
private void Host_NewClientConnected(IRemoteXTMF obj) { // fire off the model system to the client obj.SendModelSystem(ClientStructure); }
/// <summary> /// The calling method must have the Host lock! /// </summary> /// <param name="toRemove">The client to remove</param> private void RemoveClient(IRemoteXTMF toRemove) { AvailableClients = new Stack<IRemoteXTMF>( from client in AvailableClients where client != toRemove select client); }
private void Host_NewClientConnected(IRemoteXTMF obj) { lock ( this ) { this.ConnectedClients.Add( obj ); } this.Configuration.CreateProgressReport( obj.UniqueID == null ? "Remote Host" : obj.UniqueID, delegate() { return obj.Progress; }, new Tuple<byte, byte, byte>( 150, 50, 50 ) ); }
private void SendNewJob(IRemoteXTMF client) { System.Threading.Thread.MemoryBarrier(); int i = IndexOfNextJob(); if ( i >= 0 ) { this.CurrentJobs[i].Processing = true; this.CurrentJobs[i].ProcessedBy = client; System.Threading.Thread.MemoryBarrier(); client.SendCustomMessage( i, this.RequestJobChannel ); } }
private void Host_ClientRunComplete(IRemoteXTMF client, int existStatus, string message) { }