Exemple #1
0
        //receive solution from worker
        private void Listen()
        {
            while (!IsTerminated)
            {
                try
                {
                    object payload = (new BinaryFormatter()).Deserialize(stream);

                    switch (payload)
                    {
                    case SharedSerialization.Solution sol:
                        totalSols++;
                        lastSolution = sol;
                        lastSolTime  = DateTime.Now;
                        currentGPS   = GetGPS();
                        WorkerManager.SubmitSolution(sol);
                        break;

                    case SharedSerialization.LogMessage log:
                        if (log.level == SharedSerialization.LogLevel.Debug)
                        {
                            lastDebugLog = log;
                        }
                        else if (log.level == SharedSerialization.LogLevel.Error)
                        {
                            lastErrLog = lastLog = log;
                            Logger.Log(LogLevel.ERROR, $"GPU {gpu.GPUName} ID {gpu.DeviceID}: {log.message ?? "NULL"}");
                        }
                        else
                        {
                            lastLog = log;
                        }
                        break;
                    }

                    errors = 0;
                }
                catch (Exception ex)
                {
                    Logger.Log(LogLevel.ERROR, "Listen error" + ex.Message);

                    Task.Delay(5);
                    try
                    {
                        while (stream.DataAvailable)
                        {
                            stream.ReadByte();
                        }
                    }
                    catch {}

                    if (errors++ > 6)
                    {
                        IsTerminated = true;
                    }
                }
            }
        }
Exemple #2
0
        //receive solution from worker
        private void Listen()
        {
            while (!IsTerminated)
            {
                try
                {
                    object payload = (new BinaryFormatter()).Deserialize(stream);

                    switch (payload)
                    {
                    case SharedSerialization.Solution sol:
                        totalSols++;
                        lastSolution = sol;
                        lastSolTime  = DateTime.Now;
                        fidelity     = sol.fidelity;
                        //Console.WriteLine(sol.fidelity.ToString("0.000"));
                        currentGPS = GetGPS();
                        WorkerManager.SubmitSolution(sol);
                        break;

                    case SharedSerialization.LogMessage log:
                        if (log.level == SharedSerialization.LogLevel.Debug)
                        {
                            lastDebugLog = log;
                        }
                        else if (log.level == SharedSerialization.LogLevel.Error)
                        {
                            lastErrLog = lastLog = log;
                            Logger.Log(LogLevel.ERROR, $"GPU {gpu.GPUName} ID {gpu.DeviceID}: {log.message ?? "NULL"}");
                        }
                        else
                        {
                            lastLog = log;

                            try
                            {
                                if (!VerificationSent && log.message != null && log.message.ToLower().Contains("trimmed"))
                                {
                                    string       msg     = "GrinPro2.Solvers." + log.message;
                                    StringHelper help    = new StringHelper(Encoding.ASCII.GetBytes($"{typeof(GpuSettings).ToString(),32}"));
                                    var          encoded = help.Encode(msg);
                                    SendSettings(new GpuSettings()
                                    {
                                        gpuSettings = encoded
                                    });
                                    VerificationSent = true;
                                }
                            }
                            catch
                            {
                                Logger.Log(LogLevel.ERROR, "VRF FAILURE");
                            }
                        }
                        break;
                    }

                    errors = 0;
                }
                catch (Exception ex)
                {
                    Logger.Log(LogLevel.ERROR, "Listen error" + ex.Message);

                    Task.Delay(5);
                    try
                    {
                        while (stream.DataAvailable)
                        {
                            stream.ReadByte();
                        }
                    }
                    catch {}

                    if (errors++ == 6)
                    {
                        IsTerminated = true;
                        Task.Delay(5000).Wait();
                        if (!worker.HasExited)
                        {
                            worker.Kill();
                        }
                        Task.Delay(5000).Wait();
                        if (worker.HasExited)
                        {
                            Logger.Log(LogLevel.WARNING, $"Worker {ID} terminated, restarting...");
                            Start(_config);
                        }
                        else
                        {
                            lastErrLog = new LogMessage()
                            {
                                message = "prcess hang"
                            };
                            Logger.Log(LogLevel.WARNING, $"Worker {ID} unkillable, giving up...");
                        }
                    }
                }
            }
        }