void DC_checkpointMade(const char *filename) { FILE *f; if (!filename) { /* No file name - reset the checkpoint logic */ if (active_ckpt[0]) unlink(active_ckpt); active_ckpt[0] = '\0'; if (last_complete_ckpt) { unlink(last_complete_ckpt); free(last_complete_ckpt); last_complete_ckpt = NULL; } boinc_checkpoint_completed(); return; } if (strcmp(filename, active_ckpt)) { DC_log(LOG_ERR, "DC_checkpointMade: bad checkpoint file %s " "(expected %s)", filename, active_ckpt); boinc_checkpoint_completed(); return; } DC_log(LOG_INFO, "Completed checkpoint %s", filename); /* Remember which was the last completed checkpoint */ f = boinc_fopen(LAST_CKPT_FILE, "w"); if (f) { fprintf(f, "%s", filename); fclose(f); } if (last_complete_ckpt) { unlink(last_complete_ckpt); free(last_complete_ckpt); } last_complete_ckpt = strdup(filename); /* Reset the active checkpoint */ active_ckpt[0] = '\0'; boinc_checkpoint_completed(); if (client_state == STATE_SUSPEND) client_state = STATE_FINISH; }
static PyObject *boinc_boinc_checkpoint_completed(PyObject *self, PyObject *args) { boinc_checkpoint_completed(); Py_INCREF(Py_None); return Py_None; }
static CALresult checkpointCAL(SeparationCALMem* cm, const IntegralArea* ia, EvaluationState* es) { CALresult err; readResults(cm, ia, es); err = writeCheckpoint(es) ? CAL_RESULT_ERROR : CAL_RESULT_OK; #if BOINC_APPLICATION boinc_checkpoint_completed(); #endif return err; }
static inline void nbodyCheckpoint(const NBodyCtx* ctx, NBodyState* st) { if (nbodyTimeToCheckpoint(ctx, st)) { if (writeCheckpoint(ctx, st)) fail("Failed to write checkpoint\n"); #if BOINC_APPLICATION boinc_checkpoint_completed(); #endif /* BOINC_APPLICATION */ } #if BOINC_APPLICATION boinc_fraction_done(st->tnow / ctx->timeEvolve); #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; }
void boinc_checkpoint_completed_() { boinc_checkpoint_completed(); }
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; }