From c4a02dc9c94988059fb18d413e40b57b7f8984ca Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 14 May 2008 20:32:40 +0000 Subject: [PATCH] - uppercase: borrow CPU-burning routine from multithread (won't be optimized out) svn path=/trunk/boinc_samples/; revision=15203 --- checkin_notes | 7 +++++++ example_app/uc2.C | 28 ++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/checkin_notes b/checkin_notes index 37940f18ec..becfd45c0b 100644 --- a/checkin_notes +++ b/checkin_notes @@ -707,3 +707,10 @@ David 8 May 2008 example_app/ uc2_graphics.C uc2.C + +David 14 May 2008 + - uppercase: borrow CPU-burning routine from multithread + (won't be optimized out) + + example_app/ + uc2.C diff --git a/example_app/uc2.C b/example_app/uc2.C index c09a66642c..ee7e2906d5 100755 --- a/example_app/uc2.C +++ b/example_app/uc2.C @@ -72,16 +72,21 @@ bool run_slow = false; bool early_exit = false; bool early_crash = false; bool early_sleep = false; -double cpu_time = 20; +double cpu_time = 20, comp_result; -static void use_some_cpu() { - double j = 3.14159; - int i, n = 0; - for (i=0; i<20000000; i++) { - n++; - j *= n+j-3.14159; - j /= (float)n; - } +// do a billion floating-point ops +// (note: I needed to add an arg to this; +// otherwise the MS C++ compiler optimizes away +// all but the first call to it!) +// +static double do_a_giga_flop(int foo) { + double x = 3.14159*foo; + int i; + for (i=0; i<500000000; i++) { + x += 5.12313123; + x *= 0.5398394834; + } + return x; } int do_checkpoint(MFILE& mf, int nchars) { @@ -236,7 +241,7 @@ int main(int argc, char **argv) { // if (cpu_time) { double start = dtime(); - while (1) { + for (int i=0; ; i++) { double e = dtime()-start; if (e > cpu_time) break; fd = .5 + .5*(e/cpu_time); @@ -250,8 +255,7 @@ int main(int argc, char **argv) { } boinc_checkpoint_completed(); } - - use_some_cpu(); + comp_result = do_a_giga_flop(i); } } boinc_fraction_done(1);