void advanced_quit (void) { if (!USE_PRIMENET) { outputLongLine (MANUAL_QUIT); if (askYesNo ('N')) { writeResults ("Quitting GIMPS.\n"); //bug - either delete file, or delete all work_units and write the file. //bug IniDeleteAllLines (WORKTODO_FILE); stop_workers_for_escape (); } } else { int res; outputLongLine (PRIMENET_QUIT); res = askYesNoCancel ('C'); if (res == 0) { OutputBoth (MAIN_THREAD_NUM, "Quitting GIMPS after current work completes.\n"); IniWriteInt (INI_FILE, "NoMoreWork", 1); askOK (); } if (res == 1) { OutputBoth (MAIN_THREAD_NUM, "Quitting GIMPS immediately.\n"); spoolMessage (MSG_QUIT_GIMPS, NULL); askOK (); } } }
/* Wird vor dem beenden ausgefuehrt, * fragt ob gespeichert werden soll, * sofern noch ungespeicherte Listen * offen sind */ static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data){ if(anyModifiedPhoneLists()){ if(askYesNo("noch Speichern?")){ writeAllLists(); } } return FALSE; }
/* Testet ob eine Liste geaendert wurde und * fragt ob diese gespeichert werden soll. * Bei Ja wird die Liste gespeichert. * Args: * filename .. Name der Liste * Ret: * Nichts * */ void checkModify(char *filename){ if(isPhoneListModified(filename)){ if(askYesNo("Liste geaendert, noch speichern?")){ // g_print ("Save\n"); savePhoneList(filename); } } }
bool askYesNo(const char *question) { llvm::outs() << question << " [y/n]: "; llvm::outs().flush(); char answer[16]; if (!fgets(answer, sizeof(answer), stdin)) return false; // Use strncmp here because the answer might contain a newline as // the last char. int yes = strncmp(answer, "y", 1); int no = strncmp(answer, "n", 1); return (yes == 0 || no == 0) ? yes == 0 : askYesNo(question); }
void DlgPropiedades::on_botBorrarCol_clicked() /// El gestor del botón borrar, para eliminar un campo { int numCampo = getOpcion( tablaColumnas ); if ( numCampo >= 0 ) { if ( askYesNo( *this, "Borrar columna", Glib::ustring( "¿Esta seguro?" ), "Todo el contenido (filas) de la columna va a ser eliminado" ) ) { if ( documento->eliminarCampo( numCampo ) ) { actualizaListadoCampos(); desactivarPropiedades(); } else ponMsgError( *this, "Lo siento, se trata de un campo vital" ); } } else ponMsgError( *this, "Debe seleccionar un campo primero" ); }
/* Laed ein neues Listenfile bzw. erzeugt * eine neue Liste. * Dazu wird ein Dateiauswahl-Dialog angezeigt, * dessen Ergebnis der Listenname ist. * Es wird auch ueberprueft ob die Datei bereits * geladen ist. * Args: * selectorTitle .. Der Titel der Dateiauswahl * existMsg .. Der Text der in dem Dialog * Angezeigt wird, der mitteilt, * das die Datei bereits geladen * ist und fragt ob sie neu geladen * werden soll. * type .. Legt Fest ob es ein "Oeffnen" Dialog * (zum oeffnen existierender Listen) * oder ein "Speichern" Dialog (zum * anlegen neuer Listen) sein soll. * Ret: * Nichts * */ void fetchNewListFile(char *selectorTitle, char *existMsg, int type){ GtkWidget *fileSel; char *filename; fileSel = gtk_file_chooser_dialog_new (selectorTitle, (GtkWindow*)main_app_window, type, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); if (gtk_dialog_run (GTK_DIALOG (fileSel)) == GTK_RESPONSE_ACCEPT){ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileSel)); if (getPhoneList(filename) == NULL){ if (type == GTK_FILE_CHOOSER_ACTION_SAVE){ newPhoneFile(filename); } if(pushPhoneList(readPhoneFile(filename), filename) == OK){ addPhoneModelList(filename); addListsListElm(filename); } } else { if(askYesNo(existMsg)){ closeListByName(filename, NULL); if(pushPhoneList(readPhoneFile(filename), filename) == OK){ addPhoneModelList(filename); addListsListElm(filename); } } } GtkTreeIter iter = getIterByFilename(filename); if(gtk_list_store_iter_is_valid(listsListStore, &iter)){ gtk_tree_selection_select_iter(listsListSel, &iter); } g_free (filename); } gtk_widget_destroy (fileSel); }
void test_continue_or_stop (void) { outputLongLine ("Do you want to start some workers? "); if (askYesNo ('Y')) test_continue (); else test_stop (); }
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; }