From 9bce75fdf12e28bc23c4e835c3be5f0201ba018c Mon Sep 17 00:00:00 2001 From: Michael Gary Date: Thu, 25 Jul 2002 00:09:43 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=249 --- apps/Makefile.in | 5 +- apps/uc_cpu.C | 123 +++++++++++++++++++++++++++++++++++++++++++++ checkin_notes | 3 ++ test/init.inc | 10 ++-- test/test_time.php | 6 +-- 5 files changed, 140 insertions(+), 7 deletions(-) create mode 100644 apps/uc_cpu.C diff --git a/apps/Makefile.in b/apps/Makefile.in index 907a6bfd39..1c45987494 100644 --- a/apps/Makefile.in +++ b/apps/Makefile.in @@ -17,7 +17,7 @@ LIBS = ../api/api.o ../lib/parse.o CLIBS = @LIBS@ -APPS = upper_case concat uc_slow concat_slow 1sec +APPS = upper_case concat uc_slow concat_slow 1sec uc_cpu .C.o: $(CC) -c -o $*.o $< @@ -38,6 +38,9 @@ concat_slow: concat_slow.o uc_slow: uc_slow.o $(CC) uc_slow.o $(LIBS) -o uc_slow +uc_cpu: uc_cpu.o + $(CC) uc_cpu.o $(LIBS) -o uc_cpu + 1sec: 1sec.o $(CC) 1sec.o $(LIBS) -o 1sec diff --git a/apps/uc_cpu.C b/apps/uc_cpu.C new file mode 100644 index 0000000000..bb7871a7dd --- /dev/null +++ b/apps/uc_cpu.C @@ -0,0 +1,123 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.0 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is the Berkeley Open Infrastructure for Network Computing. +// +// The Initial Developer of the Original Code is the SETI@home project. +// Portions created by the SETI@home project are Copyright (C) 2002 +// University of California at Berkeley. All Rights Reserved. +// +// Contributor(s): +// + +// read "in", convert to UC, write to "out" +// +// This version does one char/second, +// and writes its state to disk every so often + +#include +#include +#include + +#include "api.h" + +#define CHECKPOINT_FILE "uc_slow_state" + +int do_checkpoint(MFILE& mf, int nchars) { + int retval; + char resolved_name[512],res_name2[512]; + + boinc_resolve_link( "temp", resolved_name ); + FILE* f = fopen(resolved_name, "w"); + if (!f) return 1; + fprintf(f, "%d", nchars); + fclose(f); + + fprintf(stderr, "APP: uc_slow checkpointing\n"); + + // hopefully atomic part starts here + retval = mf.flush(); + if (retval) return retval; + boinc_resolve_link( CHECKPOINT_FILE, res_name2 ); + retval = rename(resolved_name, res_name2); + if (retval) return retval; + // hopefully atomic part ends here + + return 0; +} + +int main() { + int c, nchars = 0, retval, n, i; + double j; + char resolved_name[512]; + MFILE out, time_file; + FILE* state, *in; + APP_IN ai; + APP_OUT ao; + + boinc_init( ai ); + + boinc_resolve_link( "in", resolved_name ); + in = fopen(resolved_name, "r"); + boinc_resolve_link( CHECKPOINT_FILE, resolved_name ); + state = fopen(resolved_name, "r"); + if (state) { + fscanf(state, "%d", &nchars); + printf("nchars %d\n", nchars); + fseek(in, nchars, SEEK_SET); + boinc_resolve_link( "out", resolved_name ); + retval = out.open(resolved_name, "a"); + } else { + boinc_resolve_link( "out", resolved_name ); + retval = out.open(resolved_name, "w"); + } + fprintf(stderr, "APP: uc_slow starting\n"); + if (retval) { + fprintf(stderr, "APP: uc_slow output open failed %d\n", retval); + exit(1); + } + time_file.open("../../time.xml", "w"); + while (1) { + c = fgetc(in); + if (c == EOF) break; + c = toupper(c); + out._putchar(c); + nchars++; + + n = 0; + j = 3.14159; + for(i=0; i<10000000; i++) { + n++; + j *= n+j-3.14159; + j /= (float)n; + } + + if (time_to_checkpoint()) { + retval = do_checkpoint(out, nchars); + if (retval) { + fprintf(stderr, "APP: uc_slow checkpoint failed %d\n", retval); + } + ao.percent_done = 1; + checkpoint_completed(ao); + } + } + retval = out.flush(); + if (retval) { + fprintf(stderr, "APP: uc_slow flush failed %d\n", retval); + exit(1); + } + fprintf(stderr, "APP: uc_slow ending, wrote %d chars\n", nchars); + ao.percent_done = 1; + app_completed(ao); + time_file.printf("%f\n", ao.cpu_time_at_checkpoint); + time_file.flush(); + time_file.close(); + return 0; +} diff --git a/checkin_notes b/checkin_notes index 15d4365071..8faa07eb28 100755 --- a/checkin_notes +++ b/checkin_notes @@ -1268,4 +1268,7 @@ Michael Gary 7/24/2002 init.inc apps/ uc_slow.C + uc_cpu.C (added) + Makefile.in + diff --git a/test/init.inc b/test/init.inc index 75063d83d1..9e1bd72d54 100644 --- a/test/init.inc +++ b/test/init.inc @@ -246,11 +246,15 @@ function clean_api() { } function compare_time() { - $db_time=mysql_query("select cpu_time from result where name = ucs_wu_0"); + $epsilon = 0.0001; + db_init(); + $data = mysql_query("select cpu_time from result where name = 'uccpu_wu_0'"); + $result = mysql_fetch_object($data); + $db_time = $result->cpu_time; $time_file = fopen("time.xml", "r"); fscanf($time_file, "%f", $app_time); - if($db_time != $app_time) { - printf("Time mismatch: app %d server %d\n", $app_time, $db_time); + if(abs($db_time - $app_time) > $epsilon) { + printf("Time mismatch: app %f server %f\n", $app_time, $db_time); } else printf("Times match\n"); fclose($time_file); diff --git a/test/test_time.php b/test/test_time.php index 337b09d57a..ee0e14bb62 100644 --- a/test/test_time.php +++ b/test/test_time.php @@ -14,10 +14,10 @@ add_platform(null); add_core_client(null); add_user("prefs.xml"); - add_app("uc_slow", null, null); - create_work("-appname uc_slow -wu_name ucs_wu -wu_template ucs_wu -result_template ucs_result -nresults 1 small_input"); + add_app("uc_cpu", null, null); + create_work("-appname uc_cpu -wu_name uccpu_wu -wu_template uccpu_wu -result_template uccpu_result -nresults 1 small_input"); start_feeder(); run_client("-exit_when_idle"); - compare_file("ucs_wu_0_0", "uc_small_correct_output"); + compare_file("uccpu_wu_0_0", "uc_small_correct_output"); compare_time(); ?>