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 CWorkerDlg::OnEnKillfocusNumCpus() { char buf[80]; unsigned int num_cpus; int i; c_numcpus.GetWindowText (buf, sizeof (buf)); if (buf[0] >= '0' && buf[0] <= '9') { num_cpus = atoi (buf); if (num_cpus < 1) num_cpus = 1; if (num_cpus > NUM_CPUS * CPU_HYPERTHREADS) num_cpus = NUM_CPUS * CPU_HYPERTHREADS; sprintf (buf, "%d", num_cpus); c_numcpus.SetWindowText (buf); if (thread_num) m_numcpus[thread_num-1] = num_cpus; else for (i = 0; i < MAX_NUM_WORKER_THREADS; i++) m_numcpus[i] = num_cpus; } 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 CWorkerDlg::OnCbnKillfocusWorkType() { int sel, i, work_pref; sel = c_work_pref.GetCurSel (); if (thread_num) { work_pref = map_sel_to_work_pref (sel); if (work_pref != -1) m_work_pref[thread_num-1] = work_pref; } else if (AreAllTheSame (m_work_pref)) { work_pref = map_sel_to_work_pref (sel); if (work_pref != -1) for (i = 0; i < MAX_NUM_WORKER_THREADS; i++) m_work_pref[i] = work_pref; } else if (sel) { work_pref = map_sel_to_work_pref (sel-1); for (i = 0; i < MAX_NUM_WORKER_THREADS; i++) m_work_pref[i] = work_pref; } }
void CWorkerDlg::OnCbnKillfocusAffinity() { int sel, i, affinity; sel = c_affinity.GetCurSel (); if (thread_num) { if (m_num_thread > 1) affinity = (sel == 0) ? 99 : (sel == 1) ? 100 : sel - 2; else affinity = (sel >= 1) ? sel - 1 : (m_affinity[0] == 100) ? 100 : 99; m_affinity[thread_num-1] = affinity; } else if (AreAllTheSame (m_affinity)) { affinity = (sel == 0) ? 99 : (sel == 1) ? 100 : sel - 2; for (i = 0; i < MAX_NUM_WORKER_THREADS; i++) m_affinity[i] = affinity; } else if (sel) { affinity = (sel == 1) ? 99 : (sel == 2) ? 100 : sel - 3; for (i = 0; i < MAX_NUM_WORKER_THREADS; i++) m_affinity[i] = affinity; } }
void CWorkerDlg::InitComboBoxText (void) { int i, sel; char buf[80]; // Populate the thread number combo box c_threadnum_text.EnableWindow (m_num_thread > 1); c_threadnum.EnableWindow (m_num_thread > 1); c_threadnum.ResetContent (); if (m_num_thread == 1) { thread_num = 1; c_threadnum.AddString ("Worker #1"); c_threadnum.SetCurSel (0); } else { if (thread_num > (int) m_num_thread) thread_num = 0; c_threadnum.AddString ("All workers"); for (i = 1; i <= (int) m_num_thread; i++) { sprintf (buf, "Worker #%d", i); c_threadnum.AddString (buf); } c_threadnum.SetCurSel (thread_num); } // Populate the work type combo box c_work_pref.ResetContent (); if (thread_num) sel = map_work_pref_to_sel (m_work_pref[thread_num-1]); else if (AreAllTheSame (m_work_pref)) sel = map_work_pref_to_sel (m_work_pref[0]); else { c_work_pref.AddString ("Mixed Settings"); sel = 0; } c_work_pref.AddString ("Whatever makes the most sense"); c_work_pref.AddString ("World record sized numbers to test"); c_work_pref.AddString ("First time tests"); c_work_pref.AddString ("Double-check tests"); c_work_pref.AddString ("Trial factoring"); c_work_pref.AddString ("P-1 factoring"); c_work_pref.AddString ("Trial factoring to low limits"); c_work_pref.AddString ("ECM on small Mersenne numbers"); c_work_pref.AddString ("ECM on Fermat numbers"); c_work_pref.AddString ("100,000,000 digit numbers to test"); if (sel == 10) c_work_pref.AddString ("Other"); c_work_pref.SetCurSel (sel); // Populate the affinity combo box. If there is only one worker thread, // then smart affinity assignment is the same as run on any cpu. c_affinity.ResetContent (); if (thread_num) { sel = m_affinity[thread_num-1]; if (m_num_thread > 1) sel = (sel == 99) ? 0 : (sel == 100) ? 1 : sel + 2; else sel = (sel == 99 || sel == 100) ? 0 : sel + 1; } else if (AreAllTheSame (m_affinity)) { sel = m_affinity[0]; sel = (sel == 99) ? 0 : (sel == 100) ? 1 : sel + 2; } else { c_affinity.AddString ("Mixed Settings"); sel = 0; } c_affinity.AddString ("Run on any CPU"); if (m_num_thread > 1) c_affinity.AddString ("Smart assignment"); if (thread_num) { for (i = 1; i <= (int) (NUM_CPUS * CPU_HYPERTHREADS); i++) { sprintf (buf, "CPU #%d", i); c_affinity.AddString (buf); } } c_affinity.SetCurSel (sel); // Populate the num cpus edit box. if (thread_num) { sprintf (buf, "%d", m_numcpus[thread_num-1]); c_numcpus.SetWindowText (buf); } else if (AreAllTheSame (m_numcpus)) { sprintf (buf, "%d", m_numcpus[0]); c_numcpus.SetWindowText (buf); } else { c_numcpus.SetWindowText ("Mixed"); } 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; }