GetVirtualCoresCount() публичный статический Метод

public static GetVirtualCoresCount ( ) : int
Результат int
Пример #1
0
        private void StartupTimer_Tick(object sender, EventArgs e)
        {
            StartupTimer.Stop();
            StartupTimer = null;

            // get all CPUs
            int CPUs = CPUID.GetPhysicalProcessorCount();

            // get all cores (including virtual - HT can benefit mining)
            int ThreadsPerCPU = CPUID.GetVirtualCoresCount() / CPUs;

            if (!Helpers.InternalCheckIsWow64() && !Config.ConfigData.AutoStartMining)
            {
                MessageBox.Show("NiceHash Miner works only on 64 bit version of OS for CPU mining. CPU mining will be disabled.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CPUs = 0;
            }

            if (ThreadsPerCPU * CPUs > 64)
            {
                MessageBox.Show("NiceHash Miner does not support more than 64 virtual cores. CPU mining will be disabled.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CPUs = 0;
            }

            int ThreadsPerCPUMask = ThreadsPerCPU;

            ThreadsPerCPU -= Config.ConfigData.LessThreads;
            if (ThreadsPerCPU < 1)
            {
                MessageBox.Show("LessThreads greater than number of threads per CPU. CPU mining will be disabled.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CPUs = 0;
            }

            Miners = new Miner[CPUs + 4];

            if (CPUs == 1)
            {
                Miners[0] = new cpuminer(0, ThreadsPerCPU, 0);
            }
            else
            {
                for (int i = 0; i < CPUs; i++)
                {
                    Miners[i] = new cpuminer(i, ThreadsPerCPU, CPUID.CreateAffinityMask(i, ThreadsPerCPUMask));
                }
            }

            LoadingScreen.LoadText.Text = "Querying NVIDIA5.x devices...";
            IncreaseLoadCounter();

            Miners[CPUs] = new ccminer_sp();

            LoadingScreen.LoadText.Text = "Querying NVIDIA3.x devices...";
            IncreaseLoadCounter();

            Miners[CPUs + 1] = new ccminer_tpruvot();

            LoadingScreen.LoadText.Text = "Querying NVIDIA2.1 devices...";
            IncreaseLoadCounter();

            Miners[CPUs + 2] = new ccminer_tpruvot_sm21();

            LoadingScreen.LoadText.Text = "Querying AMD OpenCL devices...";
            IncreaseLoadCounter();

            Miners[CPUs + 3] = new sgminer();

            LoadingScreen.LoadText.Text = "Saving config...";
            IncreaseLoadCounter();

            for (int i = 0; i < Miners.Length; i++)
            {
                if (Config.ConfigData.Groups.Length > i)
                {
                    Miners[i].ExtraLaunchParameters = Config.ConfigData.Groups[i].ExtraLaunchParameters;
                    Miners[i].UsePassword           = Config.ConfigData.Groups[i].UsePassword;
                    if (Config.ConfigData.Groups[i].APIBindPort > 0)
                    {
                        Miners[i].APIPort = Config.ConfigData.Groups[i].APIBindPort;
                    }
                    for (int z = 0; z < Config.ConfigData.Groups[i].Algorithms.Length && z < Miners[i].SupportedAlgorithms.Length; z++)
                    {
                        Miners[i].SupportedAlgorithms[z].BenchmarkSpeed        = Config.ConfigData.Groups[i].Algorithms[z].BenchmarkSpeed;
                        Miners[i].SupportedAlgorithms[z].ExtraLaunchParameters = Config.ConfigData.Groups[i].Algorithms[z].ExtraLaunchParameters;
                        Miners[i].SupportedAlgorithms[z].UsePassword           = Config.ConfigData.Groups[i].Algorithms[z].UsePassword;
                        Miners[i].SupportedAlgorithms[z].Skip = Config.ConfigData.Groups[i].Algorithms[z].Skip;
                    }
                }
                for (int k = 0; k < Miners[i].CDevs.Count; k++)
                {
                    ComputeDevice D = Miners[i].CDevs[k];
                    if (Config.ConfigData.Groups.Length > i)
                    {
                        for (int z = 0; z < Config.ConfigData.Groups[i].DisabledDevices.Length; z++)
                        {
                            if (Config.ConfigData.Groups[i].DisabledDevices[z] == k)
                            {
                                D.Enabled = false;
                                break;
                            }
                        }
                    }
                    ListViewItem lvi = new ListViewItem();
                    lvi.SubItems.Add(D.Vendor);
                    lvi.SubItems.Add(D.Name);
                    lvi.Checked = D.Enabled;
                    lvi.Tag     = D;
                    listView1.Items.Add(lvi);
                }
            }

            Config.RebuildGroups();

            LoadingScreen.LoadText.Text = "Checking for latest version...";
            IncreaseLoadCounter();

            MinerStatsCheck          = new Timer();
            MinerStatsCheck.Tick    += MinerStatsCheck_Tick;
            MinerStatsCheck.Interval = Config.ConfigData.MinerAPIQueryInterval * 1000;

            SMAMinerCheck          = new Timer();
            SMAMinerCheck.Tick    += SMAMinerCheck_Tick;
            SMAMinerCheck.Interval = Config.ConfigData.SwitchMinSecondsFixed * 1000 + R.Next(Config.ConfigData.SwitchMinSecondsDynamic * 1000);

            UpdateCheck          = new Timer();
            UpdateCheck.Tick    += UpdateCheck_Tick;
            UpdateCheck.Interval = 1000 * 3600; // every 1 hour
            UpdateCheck.Start();
            UpdateCheck_Tick(null, null);

            LoadingScreen.LoadText.Text = "Getting NiceHash SMA information...";
            IncreaseLoadCounter();

            SMACheck          = new Timer();
            SMACheck.Tick    += SMACheck_Tick;
            SMACheck.Interval = 60 * 1000; // every 60 seconds
            SMACheck.Start();
            SMACheck_Tick(null, null);

            LoadingScreen.LoadText.Text = "Getting Bitcoin exchange rate...";
            IncreaseLoadCounter();

            BitcoinExchangeCheck          = new Timer();
            BitcoinExchangeCheck.Tick    += BitcoinExchangeCheck_Tick;
            BitcoinExchangeCheck.Interval = 1000 * 3601; // every 1 hour and 1 second
            BitcoinExchangeCheck.Start();
            BitcoinExchangeCheck_Tick(null, null);

            LoadingScreen.LoadText.Text = "Getting NiceHash balance...";
            IncreaseLoadCounter();

            BalanceCheck          = new Timer();
            BalanceCheck.Tick    += BalanceCheck_Tick;
            BalanceCheck.Interval = 61 * 1000; // every 61 seconds
            BalanceCheck.Start();
            BalanceCheck_Tick(null, null);

            LoadingScreen.LoadText.Text = "Setting environment variables...";
            IncreaseLoadCounter();

            SetEnvironmentVariables();

            IncreaseLoadCounter();
        }
Пример #2
0
        private void StartupTimer_Tick(object sender, EventArgs e)
        {
            StartupTimer.Stop();
            StartupTimer = null;

            // get all CPUs
            CPUs = CPUID.GetPhysicalProcessorCount();

            // get all cores (including virtual - HT can benefit mining)
            int ThreadsPerCPU = CPUID.GetVirtualCoresCount() / CPUs;

            if (!Helpers.InternalCheckIsWow64() && !Config.ConfigData.AutoStartMining)
            {
                MessageBox.Show(International.GetText("form1_msgbox_CPUMining64bitMsg"),
                                International.GetText("Warning_with_Exclamation"),
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CPUs = 0;
            }

            if (ThreadsPerCPU * CPUs > 64)
            {
                MessageBox.Show(International.GetText("form1_msgbox_CPUMining64CoresMsg"),
                                International.GetText("Warning_with_Exclamation"),
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CPUs = 0;
            }

            int ThreadsPerCPUMask = ThreadsPerCPU;

            ThreadsPerCPU -= Config.ConfigData.LessThreads;
            if (ThreadsPerCPU < 1)
            {
                MessageBox.Show(International.GetText("form1_msgbox_CPUMiningLessThreadMsg"),
                                International.GetText("Warning_with_Exclamation"),
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                CPUs = 0;
            }

            Globals.Miners = new Miner[CPUs + 4];

            if (CPUs == 1)
            {
                Globals.Miners[0] = new cpuminer(0, ThreadsPerCPU, 0);
            }
            else
            {
                for (int i = 0; i < CPUs; i++)
                {
                    Globals.Miners[i] = new cpuminer(i, ThreadsPerCPU, CPUID.CreateAffinityMask(i, ThreadsPerCPUMask));
                }
            }

            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_NVIDIA5X"));

            Globals.Miners[CPUs] = new ccminer_sp();

            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_NVIDIA3X"));

            Globals.Miners[CPUs + 1] = new ccminer_tpruvot();

            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_NVIDIA2X"));

            Globals.Miners[CPUs + 2] = new ccminer_tpruvot_sm21();

            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_AMD"));

            Globals.Miners[CPUs + 3] = new sgminer();

            // Auto uncheck CPU if any GPU is found
            for (int i = 0; i < CPUs; i++)
            {
                try
                {
                    if ((Globals.Miners[CPUs + 0].CDevs.Count > 0 || Globals.Miners[CPUs + 1].CDevs.Count > 0 || Globals.Miners[CPUs + 2].CDevs.Count > 0 || Globals.Miners[CPUs + 3].CDevs.Count > 0) && i < CPUs)
                    {
                        Globals.Miners[i].CDevs[0].Enabled = false;
                    }
                }
                catch { }
            }

            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_SaveConfig"));

            for (int i = 0; i < Globals.Miners.Length; i++)
            {
                if (Config.ConfigData.Groups.Length > i)
                {
                    Globals.Miners[i].ExtraLaunchParameters         = Config.ConfigData.Groups[i].ExtraLaunchParameters;
                    Globals.Miners[i].UsePassword                   = Config.ConfigData.Groups[i].UsePassword;
                    Globals.Miners[i].MinimumProfit                 = Config.ConfigData.Groups[i].MinimumProfit;
                    Globals.Miners[i].DaggerHashimotoGenerateDevice = Config.ConfigData.Groups[i].DaggerHashimotoGenerateDevice;
                    if (Config.ConfigData.Groups[i].APIBindPort > 0)
                    {
                        Globals.Miners[i].APIPort = Config.ConfigData.Groups[i].APIBindPort;
                    }
                    for (int z = 0; z < Config.ConfigData.Groups[i].Algorithms.Length && z < Globals.Miners[i].SupportedAlgorithms.Length; z++)
                    {
                        Globals.Miners[i].SupportedAlgorithms[z].BenchmarkSpeed        = Config.ConfigData.Groups[i].Algorithms[z].BenchmarkSpeed;
                        Globals.Miners[i].SupportedAlgorithms[z].ExtraLaunchParameters = Config.ConfigData.Groups[i].Algorithms[z].ExtraLaunchParameters;
                        Globals.Miners[i].SupportedAlgorithms[z].UsePassword           = Config.ConfigData.Groups[i].Algorithms[z].UsePassword;
                        Globals.Miners[i].SupportedAlgorithms[z].Skip = Config.ConfigData.Groups[i].Algorithms[z].Skip;

                        Globals.Miners[i].SupportedAlgorithms[z].DisabledDevice = new bool[Globals.Miners[i].CDevs.Count];
                        if (Config.ConfigData.Groups[i].Algorithms[z].DisabledDevices != null)
                        {
                            if (Config.ConfigData.Groups[i].Algorithms[z].DisabledDevices.Length < Globals.Miners[i].CDevs.Count)
                            {
                                for (int j = 0; j < Config.ConfigData.Groups[i].Algorithms[z].DisabledDevices.Length; j++)
                                {
                                    Globals.Miners[i].SupportedAlgorithms[z].DisabledDevice[j] = Config.ConfigData.Groups[i].Algorithms[z].DisabledDevices[j];
                                }
                                for (int j = Config.ConfigData.Groups[i].Algorithms[z].DisabledDevices.Length; j < Globals.Miners[i].CDevs.Count; j++)
                                {
                                    Globals.Miners[i].SupportedAlgorithms[z].DisabledDevice[j] = false;
                                }
                            }
                            else
                            {
                                for (int j = 0; j < Globals.Miners[i].CDevs.Count; j++)
                                {
                                    Globals.Miners[i].SupportedAlgorithms[z].DisabledDevice[j] = Config.ConfigData.Groups[i].Algorithms[z].DisabledDevices[j];
                                }
                            }
                        }
                        else
                        {
                            Globals.Miners[i].GetDisabledDevicePerAlgo();
                        }
                    }
                }
                else
                {
                    Globals.Miners[i].GetDisabledDevicePerAlgo();
                }
                for (int k = 0; k < Globals.Miners[i].CDevs.Count; k++)
                {
                    ComputeDevice D = Globals.Miners[i].CDevs[k];
                    if (Config.ConfigData.Groups.Length > i)
                    {
                        D.Enabled = true;
                        for (int z = 0; z < Config.ConfigData.Groups[i].DisabledDevices.Length; z++)
                        {
                            if (Config.ConfigData.Groups[i].DisabledDevices[z] == k)
                            {
                                D.Enabled = false;
                                break;
                            }
                        }
                    }
                    ListViewItem lvi = new ListViewItem();
                    lvi.SubItems.Add(D.Vendor);
                    lvi.SubItems.Add(D.Name);
                    lvi.Checked = D.Enabled;
                    lvi.Tag     = D;
                    listViewDevices.Items.Add(lvi);
                }
            }

            Config.RebuildGroups();


            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_CheckLatestVersion"));

            MinerStatsCheck          = new Timer();
            MinerStatsCheck.Tick    += MinerStatsCheck_Tick;
            MinerStatsCheck.Interval = Config.ConfigData.MinerAPIQueryInterval * 1000;

            SMAMinerCheck          = new Timer();
            SMAMinerCheck.Tick    += SMAMinerCheck_Tick;
            SMAMinerCheck.Interval = Config.ConfigData.SwitchMinSecondsFixed * 1000 + R.Next(Config.ConfigData.SwitchMinSecondsDynamic * 1000);
            if (Globals.Miners[CPUs + 3].CDevs.Count > 0)
            {
                SMAMinerCheck.Interval = (Config.ConfigData.SwitchMinSecondsAMD + Config.ConfigData.SwitchMinSecondsFixed) * 1000 + R.Next(Config.ConfigData.SwitchMinSecondsDynamic * 1000);
            }

            UpdateCheck          = new Timer();
            UpdateCheck.Tick    += UpdateCheck_Tick;
            UpdateCheck.Interval = 1000 * 3600; // every 1 hour
            UpdateCheck.Start();
            UpdateCheck_Tick(null, null);

            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_GetNiceHashSMA"));

            SMACheck          = new Timer();
            SMACheck.Tick    += SMACheck_Tick;
            SMACheck.Interval = 60 * 1000; // every 60 seconds
            SMACheck.Start();
            SMACheck_Tick(null, null);

            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_GetBTCRate"));

            BitcoinExchangeCheck          = new Timer();
            BitcoinExchangeCheck.Tick    += BitcoinExchangeCheck_Tick;
            BitcoinExchangeCheck.Interval = 1000 * 3601; // every 1 hour and 1 second
            BitcoinExchangeCheck.Start();
            BitcoinExchangeCheck_Tick(null, null);

            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_GetNiceHashBalance"));

            BalanceCheck          = new Timer();
            BalanceCheck.Tick    += BalanceCheck_Tick;
            BalanceCheck.Interval = 61 * 1000; // every 61 seconds
            BalanceCheck.Start();
            BalanceCheck_Tick(null, null);

            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_SetEnvironmentVariable"));

            SetEnvironmentVariables();

            LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("form1_loadtext_SetWindowsErrorReporting"));

            Helpers.DisableWindowsErrorReporting(Config.ConfigData.DisableWindowsErrorReporting);

            LoadingScreen.IncreaseLoadCounter();
            if (Config.ConfigData.NVIDIAP0State)
            {
                LoadingScreen.SetInfoMsg(International.GetText("form1_loadtext_NVIDIAP0State"));
                try
                {
                    ProcessStartInfo psi = new ProcessStartInfo();
                    psi.FileName        = "nvidiasetp0state.exe";
                    psi.Verb            = "runas";
                    psi.UseShellExecute = true;
                    psi.CreateNoWindow  = true;
                    Process p = Process.Start(psi);
                    p.WaitForExit();
                    if (p.ExitCode != 0)
                    {
                        Helpers.ConsolePrint("NICEHASH", "nvidiasetp0state returned error code: " + p.ExitCode.ToString());
                    }
                    else
                    {
                        Helpers.ConsolePrint("NICEHASH", "nvidiasetp0state all OK");
                    }
                }
                catch (Exception ex)
                {
                    Helpers.ConsolePrint("NICEHASH", "nvidiasetp0state error: " + ex.Message);
                }
            }

            LoadingScreen.IncreaseLoadCounter();
        }