本文整理汇总了C++中MFILE::flush方法的典型用法代码示例。如果您正苦于以下问题:C++ MFILE::flush方法的具体用法?C++ MFILE::flush怎么用?C++ MFILE::flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MFILE
的用法示例。
在下文中一共展示了MFILE::flush方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_checkpoint
/* Save the computation state into checkpoint file */
int do_checkpoint(MFILE& mf, int n, REAL *h_idata, int dimension) {
int retval;
string resolved_name;
FILE* f = fopen("temp", "w");
if (!f) {
return 1;
}
fprintf(f, "%d", n); //write inversion number
fprintf(f, " ");
fprintf(f, "%d", dimension); //write dimension
fprintf(f, " ");
for (int i=0; i<dimension*dimension; ++i) {
fprintf(f, " ");
fprintf(f, "%f", h_idata[i]);
}
fclose(f);
retval = mf.flush();
if (retval) {
return retval;
}
boinc_resolve_filename_s(CHECKPOINT_FILE, resolved_name);
retval = boinc_rename("temp", resolved_name.c_str());
if (retval) {
return retval;
}
return 0; //return 0 to indicate success.
}
示例2: do_checkpoint
int do_checkpoint(MFILE& mf, int nchars) {
int retval;
string resolved_name;
FILE* f = fopen("temp", "w");
if (!f) return 1;
fprintf(f, "%d", nchars);
fclose(f);
retval = mf.flush();
if (retval) return retval;
boinc_resolve_filename_s(CHECKPOINT_FILE, resolved_name);
retval = boinc_rename("temp", resolved_name.c_str());
if (retval) return retval;
return 0;
}
示例3: do_checkpoint
/* Save the computation state into checkpoint file */
int do_checkpoint(MFILE& mf, int n, cl_float *input, int matrixSize) {
int retval;
string resolved_name;
FILE* f = fopen("temp", "w");
if (!f) return 1;
fprintf(f, "%d", n); //write inversion number
fprintf(f, " ");
fprintf(f, "%d", matrixSize); //write matrixSize
fprintf(f, " ");
for (int i=0;i<matrixSize*matrixSize;++i) {
fprintf(f, " ");
fprintf(f, "%f", input[i]);
}
fclose(f);
retval = mf.flush();
if (retval) return retval;
boinc_resolve_filename_s(CHECKPOINT_FILE, resolved_name);
retval = boinc_rename("temp", resolved_name.c_str());
if (retval) return retval;
return 0; //return 0 to indicate success.
}
示例4: main
//.........这里部分代码省略.........
for (int i=lastInversion+1;i<=NUM_ITERATIONS;++i) {
//the invert function will trigger kernel calls.
invert(input,output,matrixSize);
printf("Finish inversion #%d\n",i);
for (int j=0;j<matrixSize*matrixSize;++j) {
input[j]=output[j]; //change the input for the next iteration
}
if (run_slow) {
boinc_sleep(1.);
}
if (early_exit && i>30) {
exit(-10);
}
if (early_crash && i>30) {
boinc_crash();
}
if (early_sleep && i>30) {
g_sleep = true;
while (1) boinc_sleep(1);
}
if (boinc_time_to_checkpoint()) {
printf("Perform checkpointing at inversion # %d\n",i);
//we'll need to write the current matrix to the state file.
retval = do_checkpoint(out, i, input, matrixSize);
if (retval) {
fprintf(stderr,
"%s APP: matrix_inversion checkpoint failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
boinc_checkpoint_completed();
}
fd = i/NUM_ITERATIONS;
if (cpu_time) fd /= 2;
boinc_fraction_done(fd);
}
out.printf("\n\n----------------- Final inversion #%d ----------------\n\n",
NUM_ITERATIONS);
print_to_file(&out,output,matrixSize);
retval = out.flush(); //force the output file to be closed.
if (retval) {
fprintf(stderr,
"%s APP: matrix_inversion flush failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(1);
}
// Releases OpenCL resources
if (cleanup_cl()==1) {
printf("Error!");
return 1;
}
// Release host resources
cleanup_host();
// burn up some CPU time if needed
//
if (cpu_time) {
printf("\nBurning up some CPU time ... \n");
double start = dtime();
for (int i=0; ; i++) {
double e = dtime()-start;
if (e > cpu_time) break;
fd = .5 + .5*(e/cpu_time);
boinc_fraction_done(fd);
if (boinc_time_to_checkpoint()) {
retval = do_checkpoint(out, NUM_ITERATIONS, input, matrixSize);
if (retval) {
fprintf(stderr,
"%s APP: maxtrix_inversion checkpoint failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(1);
}
boinc_checkpoint_completed();
}
comp_result = do_a_giga_flop(i);
}
}
boinc_fraction_done(1);
#ifdef APP_GRAPHICS
update_shmem();
#endif
printf("\nDone! Please press ENTER to exit. ");
getchar();
boinc_finish(0);
}
示例5: main
//.........这里部分代码省略.........
boinc_msg_prefix(buf, sizeof(buf))
);
fprintf(stderr, "%s resolved name %s, retval %d\n",
boinc_msg_prefix(buf, sizeof(buf)), output_path, retval
);
perror("open");
exit(1);
}
#ifdef APP_GRAPHICS
// create shared mem segment for graphics, and arrange to update it
//
shmem = (UC_SHMEM*)boinc_graphics_make_shmem("uppercase", sizeof(UC_SHMEM));
if (!shmem) {
fprintf(stderr, "%s failed to create shared mem segment\n",
boinc_msg_prefix(buf, sizeof(buf))
);
}
update_shmem();
boinc_register_timer_callback(update_shmem);
#endif
// main loop - read characters, convert to UC, write
//
for (i=0; ; i++) {
c = fgetc(infile);
if (c == EOF) break;
c = toupper(c);
out._putchar(c);
nchars++;
if (run_slow) {
boinc_sleep(1.);
}
if (early_exit && i>30) {
exit(-10);
}
if (early_crash && i>30) {
boinc_crash();
}
if (early_sleep && i>30) {
g_sleep = true;
while (1) boinc_sleep(1);
}
if (boinc_time_to_checkpoint()) {
retval = do_checkpoint(out, nchars);
if (retval) {
fprintf(stderr, "%s APP: upper_case checkpoint failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
boinc_checkpoint_completed();
}
fd = nchars/fsize;
if (cpu_time) fd /= 2;
boinc_fraction_done(fd);
}
retval = out.flush();
if (retval) {
fprintf(stderr, "%s APP: upper_case flush failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(1);
}
// burn up some CPU time if needed
//
if (cpu_time) {
double start = dtime();
for (i=0; ; i++) {
double e = dtime()-start;
if (e > cpu_time) break;
fd = .5 + .5*(e/cpu_time);
boinc_fraction_done(fd);
if (boinc_time_to_checkpoint()) {
retval = do_checkpoint(out, nchars);
if (retval) {
fprintf(stderr, "%s APP: upper_case checkpoint failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(1);
}
boinc_checkpoint_completed();
}
comp_result = do_a_giga_flop(i);
}
}
boinc_fraction_done(1);
#ifdef APP_GRAPHICS
update_shmem();
#endif
boinc_finish(0);
}
示例6: main
//.........这里部分代码省略.........
if (c == EOF) break;
c = toupper(c);
out._putchar(c);
nchars++;
if (run_slow) {
boinc_sleep(1.);
}
if (early_exit && i>30) {
exit(-10);
}
if (early_crash && i>30) {
boinc_crash();
}
if (early_sleep && i>30) {
boinc_disable_timer_thread = true;
while (1) boinc_sleep(1);
}
if (boinc_time_to_checkpoint()) {
retval = do_checkpoint(out, nchars);
if (retval) {
fprintf(stderr, "%s APP: upper_case checkpoint failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
boinc_checkpoint_completed();
}
if (report_fraction_done) {
fd = nchars/fsize;
if (cpu_time) fd /= 2;
boinc_fraction_done(fd);
}
}
retval = out.flush();
if (retval) {
fprintf(stderr, "%s APP: upper_case flush failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(1);
}
if (trickle_up) {
boinc_send_trickle_up(
const_cast<char*>("example_app"),
const_cast<char*>("sample trickle message")
);
}
if (trickle_down) {
boinc_sleep(10);
retval = boinc_receive_trickle_down(buf, sizeof(buf));
if (!retval) {
fprintf(stderr, "Got trickle-down message: %s\n", buf);
}
}
// burn up some CPU time if needed
//
if (cpu_time) {
double start = dtime();
for (i=0; ; i++) {
double e = dtime()-start;
if (e > cpu_time) break;
if (report_fraction_done) {
fd = .5 + .5*(e/cpu_time);
boinc_fraction_done(fd);
}
if (boinc_time_to_checkpoint()) {
retval = do_checkpoint(out, nchars);
if (retval) {
fprintf(stderr, "%s APP: upper_case checkpoint failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(1);
}
boinc_checkpoint_completed();
}
if (critical_section) {
boinc_begin_critical_section();
}
comp_result = do_some_computing(i);
if (critical_section) {
boinc_end_critical_section();
}
}
}
boinc_fraction_done(1);
#ifdef APP_GRAPHICS
update_shmem();
#endif
boinc_finish(0);
}
示例7: main
//.........这里部分代码省略.........
if (!infile) {
fprintf(stderr,
"%s Couldn't find input file, resolved name %s.\n",
boinc_msg_prefix(buf, sizeof(buf)), input_path
);
exit(-1);
}
// get size of input file (used to compute fraction done)
//
file_size(input_path, fsize);
boinc_resolve_filename(OUTPUT_FILENAME, output_path, sizeof(output_path));
// See if there's a valid checkpoint file.
// If so seek input file and truncate output file
//
boinc_resolve_filename(CHECKPOINT_FILE, chkpt_path, sizeof(chkpt_path));
state = boinc_fopen(chkpt_path, "r");
if (state) {
n = fscanf(state, "%d", &nchars);
fclose(state);
}
if (state && n==1) {
fseek(infile, nchars, SEEK_SET);
boinc_truncate(output_path, nchars);
retval = out.open(output_path, "ab");
} else {
retval = out.open(output_path, "wb");
}
if (retval) {
fprintf(stderr, "%s APP: encrypt output open failed:\n",
boinc_msg_prefix(buf, sizeof(buf))
);
fprintf(stderr, "%s resolved name %s, retval %d\n",
boinc_msg_prefix(buf, sizeof(buf)), output_path, retval
);
perror("open");
exit(1);
}
for(i=0; ;i++){
c = fgetc(infile);
if(c==EOF) break;
sentence[i]=c;
}
sentence[i]='\0';
p=43;
q=3;
pq=p*q;
//e=19 d=31
strcpy(sentence,rsaencrypt(sentence,19,pq));
for (i=0;sentence[i]!='\0'; i++) {
c=sentence[i];
out._putchar(c);
nchars++;
if (run_slow) {
boinc_sleep(1.);
}
if (early_exit && i>30) {
exit(-10);
}
if (early_crash && i>30) {
boinc_crash();
}
if (early_sleep && i>30) {
boinc_disable_timer_thread = true;
while (1) boinc_sleep(1);
}
if (boinc_time_to_checkpoint()) {
retval = do_checkpoint(out, nchars);
if (retval) {
fprintf(stderr, "%s APP: encrypt checkpoint failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(retval);
}
boinc_checkpoint_completed();
}
fd = nchars/fsize;
if (cpu_time) fd /= 2;
boinc_fraction_done(fd);
}
retval = out.flush();
if (retval) {
fprintf(stderr, "%s APP: encrypt flush failed %d\n",
boinc_msg_prefix(buf, sizeof(buf)), retval
);
exit(1);
}
boinc_fraction_done(1);
boinc_finish(0);
}