static PyObject *boinc_boinc_time_to_checkpoint(PyObject *self, PyObject *args) { int isItTime; isItTime = boinc_time_to_checkpoint(); return Py_BuildValue("i", isItTime); }
static inline int nbodyTimeToCheckpoint(const NBodyCtx* ctx, NBodyState* st) { #if BOINC_APPLICATION return boinc_time_to_checkpoint(); #else time_t now; if (ctx->checkpointT < 0 || ((now = time(NULL)) - st->lastCheckpoint) < ctx->checkpointT) return FALSE; else { st->lastCheckpoint = now; return TRUE; } #endif /* BOINC_APPLICATION */ }
int main(int argc, char** argv) { int ret_val = boinc_init(); bool ignore_part_file_load = false; CHECK_FOR_FAIL_IN_MAIN(ret_val) //open input file //ret_val = open_input_file(); if (argc != 4) ret_val = BAD_CMD_LINE_PARAMS; CHECK_FOR_FAIL_IN_MAIN(ret_val) max_n = atoi(argv[1]); FAIL_IS_ZERO_IN_MAIN(max_n) k_reg = atoi(argv[2]); FAIL_IS_ZERO_IN_MAIN(k_reg) m = atoi(argv[3]); FAIL_IS_ZERO_IN_MAIN(m) //init p_vals with 0s p_vals = new short[max_n]; b_kvals = new short[max_n]; for (int i = 0; i < max_n; i++) { p_vals[i] = -1; b_kvals[i] = -1; } p_vals[0] = 1; p_vals[1] = 1; b_kvals[0] = 1; /*first check to see if the partition file has been written if it hasn't the checkpoint will have p_vals */ //we just ran finished the part file so no need to load it /*if the part file hasn't been written, the checkpoint will have b_kvals*/ if (!part_file_exists()) { //open checkpoint and load from there if it exists ret_val = open_part_checkpoint(); CHECK_FOR_FAIL_IN_MAIN(ret_val) for (; current_n < max_n; current_n++) { if (boinc_time_to_checkpoint() ) { do_checkpoint(p_vals, current_n); boinc_checkpoint_completed(); } #if _DEBUG && defined(CHECKPOINTS) if (current_n % 100 == 0) do_checkpoint(p_vals, current_n); #endif p(current_n); boinc_fraction_done((double)current_n/((double)max_n *2)); } //write finalresults ret_val = write_part_results(); CHECK_FOR_FAIL_IN_MAIN(ret_val); #if _DEBUG && defined(CHECKPOINTS) for (int i =0; i < 100; i++) { cout << i << " = " << (unsigned int) p_vals[i] << "\r\n"; } #endif //delete old checkpoint file delete_checkpoint(); current_n = 0; ignore_part_file_load = true; }
/* Each checkpoint we introduce more errors from summing the entire * buffer. If we didn't we would have checkpoints hundreds of * megabytes in size. Make sure at least 10% has progressed (limiting * to ~10 max checkpoints over the summation). This keeps the * introduced error below acceptable levels. Additionally this * checkpointing isn't exactly cheap (a checkpoint is taking nearly as * long as an entire step on the 5870 for me), so we really want to * avoid doing it too often.*/ int timeToCheckpointGPU(const EvaluationState* es, const IntegralArea* ia) { return (es->nu_step - es->lastCheckpointNuStep >= ia->nu_steps / 10) && boinc_time_to_checkpoint(); }
DC_ClientEvent *DC_checkClientEvent(void) { DC_ClientEvent *event; char *buf, *msg; int ret; /* Check for checkpoint requests */ if (boinc_time_to_checkpoint()) { DC_log(LOG_DEBUG, "Core client requested checkpoint"); return new_event(DC_CLIENT_CHECKPOINT); } /* Check for messages */ buf = (char *)malloc(MAX_MESSAGE_SIZE); if (!buf) /* Let's hope the error is transient and we can deliver the * message when DC_checkClientEvent() is called for the next time */ return NULL; /* Check for trickle-down messages and also handle internal * communication */ ret = boinc_receive_trickle_down(buf, MAX_MESSAGE_SIZE); if (ret) { msg = (char *)malloc(MAX_MESSAGE_SIZE); if (!msg) { free(buf); return NULL; } ret = parse_str(buf, "<message>", msg, MAX_MESSAGE_SIZE); if (!ret) { DC_log(LOG_WARNING, "Failed to parse message %s", buf); free(buf); free(msg); return NULL; } if (!strncmp(msg, DCAPI_MSG_PFX, strlen(DCAPI_MSG_PFX)) && msg[strlen(DCAPI_MSG_PFX)] == ':') { event = handle_special_msg(msg + strlen(DCAPI_MSG_PFX) + 1); free(msg); return event; } DC_log(LOG_DEBUG, "Received trickle message"); event = new_event(DC_CLIENT_MESSAGE); event->message = buf; return event; } free(buf); if (client_state == STATE_FINISH) return new_event(DC_CLIENT_FINISH); return NULL; }
void boinc_time_to_checkpoint_(int* result) { *result = boinc_time_to_checkpoint(); }
int checkpoint(BOOLEAN force_checkpoint) { int retval=0, i, l=xml_indent_level; xml_indent_level=0; char buf[2048]; std::string enc_field, str; // The user may have set preferences for a long time between // checkpoints to reduce disk access. if (!force_checkpoint) { if (!boinc_time_to_checkpoint()) return CHECKPOINT_SKIPPED; } fflush(stderr); /* should be in this place! * in the Android or non-glibc malloc it causes huge system mmap2 overhead */ MFILE state_file; // debug possible heap corruption -- jeffc #ifdef _WIN32 BOINCASSERT(_CrtCheckMemory()); #endif if (state_file.open(STATE_FILENAME, "wb")) SETIERROR(CANT_CREATE_FILE,"in checkpoint()"); retval = state_file.printf( "<ncfft>%d</ncfft>\n" "<cr>%e</cr>\n" "<fl>%d</fl>\n" "<prog>%.8f</prog>\n" "<potfreq>%d</potfreq>\n" "<potactivity>%d</potactivity>\n" "<signal_count>%d</signal_count>\n" "<flops>%f</flops>\n" "<spike_count>%d</spike_count>\n" "<pulse_count>%d</pulse_count>\n" "<gaussian_count>%d</gaussian_count>\n" "<triplet_count>%d</triplet_count>\n", analysis_state.icfft, ChirpFftPairs[analysis_state.icfft].ChirpRate, ChirpFftPairs[analysis_state.icfft].FftLen, std::min(progress,0.9999999), analysis_state.PoT_freq_bin, analysis_state.PoT_activity, signal_count, analysis_state.FLOP_counter, spike_count, pulse_count, gaussian_count, triplet_count ); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // checkpoint the best spike thus far (if any) if(best_spike->score) { retval = state_file.printf("<best_spike>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // the spike proper str = best_spike->s.print_xml(0,0,1); retval = (int)state_file.write(str.c_str(), str.size(), 1); // ancillary data retval = state_file.printf( "<bs_score>%f</bs_score>\n" "<bs_bin>%d</bs_bin>\n" "<bs_fft_ind>%d</bs_fft_ind>\n", best_spike->score, best_spike->bin, best_spike->fft_ind); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.printf("</best_spike>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); } // checkpoint the best gaussian thus far (if any) if(best_gauss->score) { retval = state_file.printf("<best_gaussian>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // the gaussian proper str = best_gauss->g.print_xml(0,0,1); retval = (int)state_file.write(str.c_str(), str.size(), 1); // ancillary data retval = state_file.printf( "<bg_score>%f</bg_score>\n" "<bg_display_power_thresh>%f</bg_display_power_thresh>\n" "<bg_bin>%d</bg_bin>\n" "<bg_fft_ind>%d</bg_fft_ind>\n", best_gauss->score, best_gauss->display_power_thresh, best_gauss->bin, best_gauss->fft_ind); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.printf("</best_gaussian>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); } // checkpoint the best pulse thus far (if any) // The check for len_prof is a kludge. if(best_pulse->score) { retval = state_file.printf("<best_pulse>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // the pulse proper str = best_pulse->p.print_xml(0,0,1); retval = (int)state_file.write(str.c_str(), str.size(), 1); // ancillary data retval = state_file.printf( "<bp_score>%f</bp_score>\n" "<bp_freq_bin>%d</bp_freq_bin>\n" "<bp_time_bin>%d</bp_time_bin>\n", best_pulse->score, best_pulse->freq_bin, best_pulse->time_bin); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.printf("</best_pulse>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); } // checkpoint the best triplet thus far (if any) if(best_triplet->score) { retval = state_file.printf("<best_triplet>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // the triplet proper str = best_triplet->t.print_xml(0,0,1); retval = (int)state_file.write(str.c_str(), str.size(), 1); // ancillary data retval = state_file.printf( "<bt_score>%f</bt_score>\n" "<bt_bperiod>%f</bt_bperiod>\n" "<bt_tpotind0_0>%d</bt_tpotind0_0>\n" "<bt_tpotind0_1>%d</bt_tpotind0_1>\n" "<bt_tpotind1_0>%d</bt_tpotind1_0>\n" "<bt_tpotind1_1>%d</bt_tpotind1_1>\n" "<bt_tpotind2_0>%d</bt_tpotind2_0>\n" "<bt_tpotind2_1>%d</bt_tpotind2_1>\n" "<bt_freq_bin>%d</bt_freq_bin>\n" "<bt_time_bin>%f</bt_time_bin>\n" "<bt_scale>%f</bt_scale>\n", best_triplet->score, best_triplet->bperiod, best_triplet->tpotind0_0, best_triplet->tpotind0_1, best_triplet->tpotind1_0, best_triplet->tpotind1_1, best_triplet->tpotind2_0, best_triplet->tpotind2_1, best_triplet->freq_bin, best_triplet->time_bin, best_triplet->scale); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // convert min PoT to chars, encode, and print for (i=0; i<swi.analysis_cfg.triplet_pot_length; i++) { buf[i] = (unsigned char)best_triplet->pot_min[i]; } enc_field=xml_encode_string(buf, swi.analysis_cfg.triplet_pot_length, _x_csv); retval = state_file.printf( "<bt_pot_min length=%d encoding=\"%s\">", enc_field.size(), xml_encoding_names[_x_csv] ); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); state_file.write(enc_field.c_str(), enc_field.size(), 1); retval = state_file.printf("</bt_pot_min>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); // convert max PoT to chars, encode, and print for (i=0; i<swi.analysis_cfg.triplet_pot_length; i++) { buf[i] = (unsigned char)best_triplet->pot_max[i]; } enc_field=xml_encode_string(buf, swi.analysis_cfg.triplet_pot_length, _x_csv); state_file.printf( "<bt_pot_max length=%d encoding=\"%s\">", enc_field.size(), xml_encoding_names[_x_csv] ); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); state_file.write(enc_field.c_str(), enc_field.size(), 1); retval = state_file.printf("</bt_pot_max>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.printf("</best_triplet>\n"); if (retval < 0) SETIERROR(WRITE_FAILED,"in checkpoint()"); } // The result (outfile) and state mfiles are now synchronized. // Flush them both. retval = outfile.flush(); if (retval) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.flush(); if (retval) SETIERROR(WRITE_FAILED,"in checkpoint()"); retval = state_file.close(); if (retval) SETIERROR(WRITE_FAILED,"in checkpoint()"); boinc_checkpoint_completed(); xml_indent_level=l; // debug possible heap corruption -- jeffc #ifdef _WIN32 BOINCASSERT(_CrtCheckMemory()); #endif return 0; }
int main() { int rc = boinc_init(); if (rc) { fprintf(stderr, "APP: boinc_init() failed. rc=%d\n", rc); exit(rc); } srand(time(NULL)); FILE *file_progress; unsigned long long int actual_iteration; int sleep_time; int read_checkpoint; read_checkpoint = checkpoint(&actual_iteration, 0); // Read checkpoint if(read_checkpoint == 1) { actual_iteration = 0; } for(actual_iteration; actual_iteration < ITERATIONS; actual_iteration++) { if (!(file_progress = fopen("progress", "wt"))) { fprintf(stderr,"ERROR: CANNOT OPEN FILE PROGRESS\n"); } else { if(actual_iteration == 0) { fprintf(file_progress, "0"); } else { fprintf(file_progress, "%lf", ((double) actual_iteration / (double) ITERATIONS ) ); } fclose(file_progress); } #if defined(_WIN32) || defined(_WIN64) sleep_time = (rand() % 7) + 1; sleep_time *= 1000; printf("ALX sleep...\n"); Sleep(sleep_time); printf("ALX woke up...\n"); #endif # ifdef __linux__ sleep_time = (rand() % 7) + 1; printf("ALX sleep...\n"); sleep(sleep_time); printf("ALX woke up...\n"); # else sleep_time = (rand() % 7) + 1; printf("ALX sleep...\n"); sleep(sleep_time); printf("ALX woke up...\n"); # endif # ifdef BOINC_VERSION if( boinc_time_to_checkpoint() ) { checkpoint(&actual_iteration, 1); // Save checkpoint boinc_checkpoint_completed(); } # else checkpoint(&actual_iteration, 1); // Save checkpoint # endif boinc_fraction_done( ((double) actual_iteration) / ((double) ITERATIONS) ); } // RESULTS FILE --------------------------------------- FILE *fp; if ((fp=fopen("result", "wt"))==NULL) { printf ("Error: No save result to the file!"); return 1; } fprintf(fp, "1"); fclose (fp); // RESULTS FILE --------------------------------------- boinc_fraction_done(1.0); boinc_finish(0); return 0; }