Exemplo n.º 1
0
 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());
                }
            }
        }
Exemplo n.º 3
0
 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;
             }
         }
     }
 }
Exemplo n.º 4
0
 ///  <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();
     }
 }
Exemplo n.º 5
0
 /// <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);
 }
Exemplo n.º 6
0
        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());
                }
            }
        }
Exemplo n.º 7
0
 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);
        }
Exemplo n.º 9
0
        private void NewClientConnected(IRemoteXTMF obj)
        {
            // Setup a new model system for them to execute
            var msCopy = ModelSystemToExecute.Clone();

            FixParameters(msCopy);
            Host.ExecuteModelSystemAsync(msCopy);
        }
Exemplo n.º 10
0
 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));
 }
Exemplo n.º 11
0
        private void ProcessEvaluation(object evaluation, IRemoteXTMF r)
        {
            var message = evaluation as ResultMessage;

            if (message != null)
            {
                this.ResultQueue.Add(message);
            }
        }
Exemplo n.º 12
0
 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();
     }
 }
Exemplo n.º 13
0
 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));
 }
Exemplo n.º 14
0
 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));
     }
 }
Exemplo n.º 15
0
        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;
        }
Exemplo n.º 16
0
        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);
            }
        }
Exemplo n.º 17
0
 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();
 }
Exemplo n.º 18
0
        /// <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);
        }
Exemplo n.º 19
0
 ///  <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);
         }
     }
 }
Exemplo n.º 20
0
        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();
            }
        }
Exemplo n.º 21
0
 private object ClientReady(Stream o, IRemoteXTMF client)
 {
     return(null);
 }
Exemplo n.º 22
0
 private object CustomMessageReceiver(Stream inputStream, IRemoteXTMF client)
 {
     return(null);
 }
Exemplo n.º 23
0
 void Host_ProgressUpdated(IRemoteXTMF origin, float progress)
 {
     // we don't need to monitor the progress since we will periodically poll the clients
 }
Exemplo n.º 24
0
 private object CustomMessageReceiver(System.IO.Stream inputStream, IRemoteXTMF client)
 {
     return null;
 }
Exemplo n.º 25
0
 void Host_ClientDisconnected(IRemoteXTMF obj)
 {
     this.NoneConnected = true;
 }
Exemplo n.º 26
0
 private void ClientWantsHouseholds2(object o, IRemoteXTMF client)
 {
     // Send the household data!
     client.SendCustomMessage(null, 2);
 }
Exemplo n.º 27
0
 void Host_ClientDisconnected(IRemoteXTMF obj)
 {
     this.NoneConnected = true;
 }
Exemplo n.º 28
0
 private void CustomMessageHandler(object data, IRemoteXTMF client)
 {
     if ( data is int )
     {
         this.Jobs.Add( (int)data );
     }
 }
Exemplo n.º 29
0
 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();
 }
Exemplo n.º 30
0
 private void Host_NewClientConnected(IRemoteXTMF client)
 {
     // Handle a new client
 }
Exemplo n.º 31
0
 private void Host_ProgressUpdated(IRemoteXTMF client, float progress)
 {
 }
Exemplo n.º 32
0
 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));
 }
Exemplo n.º 33
0
 private void Host_ClientDisconnected(IRemoteXTMF client)
 {
 }
Exemplo n.º 34
0
 private void CustomMessageSender(object data, IRemoteXTMF client, System.IO.Stream outputStream)
 {
 }
Exemplo n.º 35
0
 private void ClientReady2(object o, IRemoteXTMF client)
 {
     ConnectedClients.Add(client);
     SendNextParameter(client);
 }
Exemplo n.º 36
0
 private void SendHouseholds(object o, IRemoteXTMF r, Stream s)
 {
     s.Write(HouseholdData, 0, HouseholdData.Length);
     s.Flush();
 }
Exemplo n.º 37
0
 private object ClientWantsHouseholds(Stream o, IRemoteXTMF client)
 {
     return(null);
 }
Exemplo n.º 38
0
 private void Host_ClientRunComplete(IRemoteXTMF arg1, int arg2, string arg3)
 {
     System.Threading.Interlocked.Increment( ref this.CompletedCount );
 }
Exemplo n.º 39
0
 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();
     }
 }
Exemplo n.º 40
0
 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;
 }
Exemplo n.º 41
0
 private void Host_NewClientConnected(IRemoteXTMF obj)
 {
     // fire off the model system to the client
     obj.SendModelSystem(ClientStructure);
 }
Exemplo n.º 42
0
 private void Host_ProgressUpdated(IRemoteXTMF client, float progress)
 {
 }
Exemplo n.º 43
0
 /// <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);
 }
Exemplo n.º 44
0
 private void Host_NewClientConnected(IRemoteXTMF client)
 {
     // Handle a new client
 }
Exemplo n.º 45
0
 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 ) );
 }
Exemplo n.º 46
0
 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 );
     }
 }
Exemplo n.º 47
0
 private void Host_ClientRunComplete(IRemoteXTMF client, int existStatus, string message)
 {
 }
Exemplo n.º 48
0
 void Host_ProgressUpdated(IRemoteXTMF origin, float progress)
 {
     // we don't need to monitor the progress since we will periodically poll the clients
 }