void CWorkerDlg::OnEnKillfocusNumThread() { char buf[80]; unsigned int num_thread; c_num_thread.GetWindowText (buf, sizeof (buf)); num_thread = atoi (buf); if (num_thread < 1) num_thread = 1; if (num_thread > max_num_workers ()) num_thread = max_num_workers (); sprintf (buf, "%d", num_thread); c_num_thread.SetWindowText (buf); if (num_thread != m_num_thread) { m_num_thread = num_thread; InitComboBoxText (); // Might change thread_num if we reduced // number of worker threads } }
void CWorkerDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWorkerDlg) DDX_Control(pDX, IDC_THREAD_TEXT, c_num_thread_text); DDX_Control(pDX, IDC_THREAD, c_num_thread); DDX_Text(pDX, IDC_THREAD, m_num_thread); DDV_MinMaxUInt(pDX, m_num_thread, 1, max_num_workers ()); DDX_Text(pDX, IDC_PRIORITY, m_priority); DDV_MinMaxUInt(pDX, m_priority, 1, 10); DDX_Control(pDX, IDC_WORKGROUP, c_workgroup); DDX_Control(pDX, IDC_THREADNUM_TEXT, c_threadnum_text); DDX_Control(pDX, IDC_COMBO1, c_threadnum); DDX_Control(pDX, IDC_WORK_TYPE_TEXT, c_work_pref_text); DDX_Control(pDX, IDC_COMBO2, c_work_pref); DDX_Control(pDX, IDC_AFFINITY_TEXT, c_affinity_text); DDX_Control(pDX, IDC_COMBO3, c_affinity); DDX_Control(pDX, IDC_NUMCPUS_TEXT, c_numcpus_text); DDX_Control(pDX, IDC_NUMCPUS, c_numcpus); DDX_Control(pDX, IDC_WARN1, c_warn1_text); DDX_Control(pDX, IDC_WARN2, c_warn2_text); DDX_Control(pDX, IDC_WARN3, c_warn3_text); //}}AFX_DATA_MAP c_num_thread_text.EnableWindow (max_num_workers () > 1); c_num_thread.EnableWindow (max_num_workers () > 1); c_workgroup.EnableWindow (USE_PRIMENET || NUM_CPUS * CPU_HYPERTHREADS > 1); c_threadnum_text.EnableWindow (m_num_thread > 1); c_threadnum.EnableWindow (m_num_thread > 1); c_work_pref_text.EnableWindow (USE_PRIMENET); c_work_pref.EnableWindow (USE_PRIMENET); c_affinity_text.EnableWindow (NUM_CPUS * CPU_HYPERTHREADS > 1); c_affinity.EnableWindow (NUM_CPUS * CPU_HYPERTHREADS > 1); c_numcpus_text.EnableWindow (m_num_thread < NUM_CPUS * CPU_HYPERTHREADS || !AreAllTheSame (m_numcpus) || m_numcpus[0] != 1); c_numcpus.EnableWindow (m_num_thread < NUM_CPUS * CPU_HYPERTHREADS || !AreAllTheSame (m_numcpus) || m_numcpus[0] != 1); }
void test_worker_threads (void) { unsigned long m_num_thread, m_priority; unsigned long m_work_pref[MAX_NUM_WORKER_THREADS]; unsigned long m_affinity[MAX_NUM_WORKER_THREADS]; unsigned long m_numcpus[MAX_NUM_WORKER_THREADS]; int i; m_num_thread = NUM_WORKER_THREADS; m_priority = PRIORITY; for (i = 0; i < MAX_NUM_WORKER_THREADS; i++) { m_work_pref[i] = WORK_PREFERENCE[i]; m_affinity[i] = CPU_AFFINITY[i]; m_numcpus[i] = THREADS_PER_TEST[i]; } again: if (max_num_workers () > 1) askNum ("Number of workers to run", &m_num_thread, 1, max_num_workers ()); outputLongLine ("\nPick a priority between 1 and 10 where 1 is the lowest priority and 10 is the highest. It is strongly recommended that you use the default priority of 1. Your throughput will probably not improve by using a higher priority. The only time you should raise the priority is when another process, such as a screen saver, is stealing CPU cycles from this program.\n"); askNum ("Priority", &m_priority, 1, 10); if (USE_PRIMENET) { outputLongLine ("\nUse the following values to select a work type:\n 0 - Whatever makes the most sense\n 2 - Trial factoring\n 100 - First time primality tests\n 101 - Double-checking\n 102 - World record primality tests\n 4 - P-1 factoring\n 104 - 100 million digit primality tests\n 1 - Trial factoring to low limits\n 5 - ECM on small Mersenne numbers\n 6 - ECM on Fermat numbers\n"); } if (USE_PRIMENET || NUM_CPUS * user_configurable_hyperthreads () > 1) { for (i = 0; i < m_num_thread; i++) { if (m_num_thread > 1) printf ("\nOptions for worker #%d\n\n", i+1); else printf ("\n"); if (USE_PRIMENET) { askNum ("Type of work to get", &m_work_pref[i], 0, 150); if (m_numcpus[i] < min_cores_for_work_type (m_work_pref[i])) m_numcpus[i] = min_cores_for_work_type (m_work_pref[i]); } if (NUM_CPUS * user_configurable_hyperthreads () > 1) { char question[200]; unsigned long affinity; sprintf (question, "CPU affinity (1-%d=specific CPU, 99=any CPU, 100=smart assignment)", (int) (NUM_CPUS * CPU_HYPERTHREADS)); affinity = m_affinity[i]; if (affinity < 99) affinity++; askNum (question, &affinity, 1, 100); if (affinity < 99) affinity--; m_affinity[i] = affinity; } if (NUM_CPUS * user_configurable_hyperthreads () > 1) { int min_cores, max_cores; min_cores = min_cores_for_work_type (m_work_pref[i]); max_cores = NUM_CPUS * user_configurable_hyperthreads () - m_num_thread + 1; if (max_cores < min_cores) max_cores = min_cores; askNum ("CPUs to use (multithreading)", &m_numcpus[i], min_cores, max_cores); } else m_numcpus[i] = 1; } } /* Ask user if they are happy with their answers */ if (askOkCancel ()) { int restart = FALSE; int new_options = FALSE; unsigned long i, total_num_threads; /* If the user has allocated more threads than there are CPUs, raise a */ /* severe warning. */ total_num_threads = 0; for (i = 0; i < m_num_thread; i++) total_num_threads += m_numcpus[i]; if (total_num_threads > NUM_CPUS * user_configurable_hyperthreads ()) { outputLongLine (MSG_THREADS); if (askYesNo ('Y')) goto again; } /* If user is changing the number of worker threads, then make the */ /* necessary changes. Restart worker threads so that we are running */ /* the correct number of worker threads. */ if (m_num_thread != NUM_WORKER_THREADS) { //bug= do something with orphaned work units? //bug- tell server of the change? NUM_WORKER_THREADS = m_num_thread; IniWriteInt (LOCALINI_FILE, "WorkerThreads", NUM_WORKER_THREADS); restart = TRUE; } /* If user is changing the priority of worker threads, then change */ /* the INI file. Restart worker threads so that they are running at */ /* the new priority. */ if (PRIORITY != m_priority) { PRIORITY = m_priority; IniWriteInt (INI_FILE, "Priority", PRIORITY); new_options = TRUE; restart = TRUE; } /* If the user changes any of the work preferences record it in the INI file */ /* and tell the server */ if (AreAllTheSame (m_work_pref, m_num_thread)) { if (! PTOIsGlobalOption (WORK_PREFERENCE) || WORK_PREFERENCE[0] != m_work_pref[0]) { PTOSetAll (INI_FILE, "WorkPreference", NULL, WORK_PREFERENCE, m_work_pref[0]); new_options = TRUE; } } else { for (i = 0; i < (int) NUM_WORKER_THREADS; i++) { if (WORK_PREFERENCE[i] == m_work_pref[i]) continue; PTOSetOne (INI_FILE, "WorkPreference", NULL, WORK_PREFERENCE, i, m_work_pref[i]); new_options = TRUE; } } /* If the user changes any of the affinities record it in the INI file. */ if (AreAllTheSame (m_affinity, m_num_thread)) { PTOSetAll (LOCALINI_FILE, "Affinity", NULL, CPU_AFFINITY, m_affinity[0]); } else { for (i = 0; i < (int) NUM_WORKER_THREADS; i++) { PTOSetOne (LOCALINI_FILE, "Affinity", NULL, CPU_AFFINITY, i, m_affinity[i]); } } /* If the user changes any of the threads_per_test record it in the INI file */ if (AreAllTheSame (m_numcpus, m_num_thread)) { PTOSetAll (LOCALINI_FILE, "ThreadsPerTest", NULL, THREADS_PER_TEST, m_numcpus[0]); } else { for (i = 0; i < (int) NUM_WORKER_THREADS; i++) { PTOSetOne (LOCALINI_FILE, "ThreadsPerTest", NULL, THREADS_PER_TEST, i, m_numcpus[i]); } } /* Send new settings to the server */ if (new_options) spoolMessage (PRIMENET_PROGRAM_OPTIONS, NULL); /* Restart worker threads with new options */ if (restart) stop_workers_for_restart (); } else STARTUP_IN_PROGRESS = 0; }