diff --git a/checkin_notes b/checkin_notes index 26b14ebee4..d6467c64d7 100644 --- a/checkin_notes +++ b/checkin_notes @@ -259,3 +259,11 @@ David 27 Dec 2006 uppercase/ upper_case.C + +David 11 Jan 2006 + - upper_case: if checkpoint found, + truncate the output file to the indicated size. + Otherwise a checkpoint/restart generally produces a bad result. + + uppercase/ + upper_case.C diff --git a/uppercase/Makefile b/uppercase/Makefile index c3c11a03f6..cc19a9557c 100644 --- a/uppercase/Makefile +++ b/uppercase/Makefile @@ -19,7 +19,7 @@ CXXFLAGS = -g \ -L. # the following should be freeglut; use nm to check -LIBGLUT = /usr/lib/libglut.a +LIBGLUT = /usr/local/lib/libglut.a LIBGLU = /usr/X11R6/lib/libGLU.a LIBJPEG = /usr/lib/libjpeg.a diff --git a/uppercase/upper_case.C b/uppercase/upper_case.C index 17b0386568..edfd67590f 100755 --- a/uppercase/upper_case.C +++ b/uppercase/upper_case.C @@ -105,43 +105,56 @@ int do_checkpoint(MFILE& mf, int nchars) { void worker() { - int c, nchars = 0, retval; + int c, nchars = 0, retval, n; double fsize; - char resolved_name[512]; + char input_path[512], output_path[512], chkpt_path[512]; MFILE out; FILE* state, *infile; - boinc_resolve_filename(INPUT_FILENAME, resolved_name, sizeof(resolved_name)); - infile = boinc_fopen(resolved_name, "r"); + // open the input file (resolve logical name first) + // + boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path)); + infile = boinc_fopen(input_path, "r"); if (!infile) { - fprintf( - stderr, - "Couldn't find input file, resolved name %s.\n", - resolved_name + fprintf(stderr, + "Couldn't find input file, resolved name %s.\n", input_path ); exit(-1); } - file_size(resolved_name, fsize); + // get size of input file (used to compute fraction done) + // + file_size(input_path, fsize); - boinc_resolve_filename(CHECKPOINT_FILE, resolved_name, sizeof(resolved_name)); - state = boinc_fopen(resolved_name, "r"); + // open output file + // + 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) { - fscanf(state, "%d", &nchars); + n = fscanf(state, "%d", &nchars); fclose(state); + } + if (state && n==1) { fseek(infile, nchars, SEEK_SET); - boinc_resolve_filename(OUTPUT_FILENAME, resolved_name, sizeof(resolved_name)); - retval = out.open(resolved_name, "a"); + boinc_truncate(output_path, nchars); + retval = out.open(output_path, "a"); } else { - boinc_resolve_filename(OUTPUT_FILENAME, resolved_name, sizeof(resolved_name)); - retval = out.open(resolved_name, "w"); + retval = out.open(output_path, "w"); } if (retval) { fprintf(stderr, "APP: upper_case output open failed:\n"); - fprintf(stderr, "resolved name %s, retval %d\n", resolved_name, retval); + fprintf(stderr, "resolved name %s, retval %d\n", output_path, retval); perror("open"); exit(1); } + + // main loop - read characters, convert to UC, write + // for (int i=0; ; i++) { c = fgetc(infile); @@ -180,11 +193,15 @@ void worker() { boinc_fraction_done(nchars/fsize); } + retval = out.flush(); if (retval) { fprintf(stderr, "APP: upper_case flush failed %d\n", retval); exit(1); } + + // burn up some CPU time if needed + // if (cpu_time) { double start = dtime(); while (1) {