diff --git a/checkin_notes b/checkin_notes index f850fec686..1daf03e365 100644 --- a/checkin_notes +++ b/checkin_notes @@ -334,3 +334,16 @@ David 22 May 2007 samples.sln uc2.vcproj (new) uc2_graphics.vcproj (new) + +David 23 May 2007 + - version 6 example app works on Win + + example_app/ + uc2.C + uc2.h (new) + uc2_graphics.C + win_build/ + libgraphics2.vcproj + samples.sln + uc2.vcproj + uc2_graphics.vcproj diff --git a/example_app/uc2.C b/example_app/uc2.C index 89781f2d34..6df71d913b 100755 --- a/example_app/uc2.C +++ b/example_app/uc2.C @@ -1,251 +1,261 @@ -// Berkeley Open Infrastructure for Network Computing -// http://boinc.berkeley.edu -// Copyright (C) 2005 University of California -// -// This is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; -// either version 2.1 of the License, or (at your option) any later version. -// -// This software is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU Lesser General Public License for more details. -// -// To view the GNU Lesser General Public License visit -// http://www.gnu.org/copyleft/lesser.html -// or write to the Free Software Foundation, Inc., -// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -// This is the primary sample BOINC application; -// it shows most of the features of the BOINC API. -// -// read "in", convert to upper case, write to "out" -// -// command line options (use for debugging various scenarios): -// -run_slow: sleep 1 second after each character; useful for debugging -// -cpu_time N: use about N CPU seconds after copying files -// -early_exit: exit(10) after 30 chars -// -early_crash: crash after 30 chars -// - -#ifdef _WIN32 -#include "boinc_win.h" -#else -#include "config.h" -#endif - -#ifndef _WIN32 -#include -#include -#include -#include -#include -#include -#include -#endif - -#include "str_util.h" -#include "util.h" -#include "filesys.h" -#include "boinc_api.h" -#include "mfile.h" - -using std::string; - -#define CHECKPOINT_FILE "upper_case_state" -#define INPUT_FILENAME "in" -#define OUTPUT_FILENAME "out" - -bool run_slow = false; -bool early_exit = false; -bool early_crash = false; -bool early_sleep = false; -double cpu_time = 20; - - -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; - } -} - -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); - - fprintf(stderr, "APP: upper_case checkpointing\n"); - - 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; - - //use_some_cpu(); - fprintf(stderr, "APP: upper_case checkpoint done\n"); - return 0; -} - - -void worker() { - int c, nchars = 0, retval, n; - double fsize; - char input_path[512], output_path[512], chkpt_path[512]; - MFILE out; - FILE* state, *infile; - - // 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", input_path - ); - exit(-1); - } - - // get size of input file (used to compute fraction done) - // - file_size(input_path, fsize); - - // 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) { - 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, "a"); - } else { - 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", output_path, retval); - perror("open"); - exit(1); - } - - // main loop - read characters, convert to UC, write - // - for (int 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) { -#ifdef _WIN32 - DebugBreak(); -#else - *(int*)0 = 0; -#endif - } - 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, "APP: upper_case checkpoint failed %d\n", retval); - exit(retval); - } - boinc_checkpoint_completed(); - } - - 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) { - double e = dtime()-start; - if (e > cpu_time) break; - boinc_fraction_done(e/cpu_time); - - if (boinc_time_to_checkpoint()) { - retval = do_checkpoint(out, nchars); - if (retval) { - fprintf(stderr, "APP: upper_case checkpoint failed %d\n", retval); - exit(1); - } - boinc_checkpoint_completed(); - } - - use_some_cpu(); - } - } - boinc_finish(0); -} - -int main(int argc, char **argv) { - int i; - int retval = 0; - - for (i=0; i +#include +#include +#include +#include +#include +#include +#endif + +#include "str_util.h" +#include "util.h" +#include "filesys.h" +#include "boinc_api.h" +#include "mfile.h" +#include "graphics2.h" +#include "uc2.h" + +using std::string; + +#define CHECKPOINT_FILE "upper_case_state" +#define INPUT_FILENAME "in" +#define OUTPUT_FILENAME "out" + +bool run_slow = false; +bool early_exit = false; +bool early_crash = false; +bool early_sleep = false; +double cpu_time = 20; +UC_SHMEM* shmem; + +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; + } +} + +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); + + fprintf(stderr, "APP: upper_case checkpointing\n"); + + 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; + + //use_some_cpu(); + fprintf(stderr, "APP: upper_case checkpoint done\n"); + return 0; +} + +void update_shmem(double fd) { + double cpu; + if (!shmem) return; + shmem->fraction_done = fd; + boinc_calling_thread_cpu_time(cpu); + shmem->cpu_time = cpu; + shmem->update_time = dtime(); +} + +void worker() { + int c, nchars = 0, retval, n; + double fsize, fd; + char input_path[512], output_path[512], chkpt_path[512]; + MFILE out; + FILE* state, *infile; + + shmem = (UC_SHMEM*)boinc_graphics_make_shmem("uppercase", sizeof(UC_SHMEM)); + + // 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", 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, "a"); + } else { + 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", output_path, retval); + perror("open"); + exit(1); + } + + // main loop - read characters, convert to UC, write + // + for (int 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, "APP: upper_case checkpoint failed %d\n", retval); + exit(retval); + } + boinc_checkpoint_completed(); + } + + fd = nchars/fsize; + if (cpu_time) fd /= 2; + boinc_fraction_done(fd); + update_shmem(fd); + } + + 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) { + double e = dtime()-start; + if (e > cpu_time) break; + fd = .5 + .5*(e/cpu_time); + boinc_fraction_done(fd); + update_shmem(fd); + + if (boinc_time_to_checkpoint()) { + retval = do_checkpoint(out, nchars); + if (retval) { + fprintf(stderr, "APP: upper_case checkpoint failed %d\n", retval); + exit(1); + } + boinc_checkpoint_completed(); + } + + use_some_cpu(); + } + } + update_shmem(1); + boinc_finish(0); +} + +int main(int argc, char **argv) { + int i; + int retval = 0; + + for (i=0; i .5) dx *= -1; if (y < 0 || y > .5) dy *= -1; + double fd = 0, cpu=0; + if (shmem) { + fd = shmem->fraction_done; + cpu = shmem->cpu_time; + } sprintf(buf, "User: %s", uc_aid.user_name); txf_render_string(.1, x, y, 0, 500, white, 0, buf); sprintf(buf, "Team: %s", uc_aid.team_name); txf_render_string(.1, x, y+.1, 0, 500, white, 0, buf); - sprintf(buf, "%% Done: %f", 100*boinc_get_fraction_done()); + sprintf(buf, "%% Done: %f", 100*fd); txf_render_string(.1, x, y+.2, 0, 500, white, 0, buf); + sprintf(buf, "CPU time: %f", cpu); + txf_render_string(.1, x, y+.3, 0, 500, white, 0, buf); } static void draw_3d_stuff() { @@ -221,8 +232,7 @@ void boinc_app_key_release(int, int){} } -extern void boinc_graphics(int, char**); - int main(int argc, char** argv) { - boinc_graphics(argc, argv); + shmem = (UC_SHMEM*)boinc_graphics_get_shmem("uppercase"); + boinc_graphics_loop(argc, argv); } diff --git a/win_build/libgraphics2.vcproj b/win_build/libgraphics2.vcproj index 7fc066d88d..2efdd37834 100644 --- a/win_build/libgraphics2.vcproj +++ b/win_build/libgraphics2.vcproj @@ -294,6 +294,10 @@ RelativePath="..\..\boinc\api\graphics2.C" > + + @@ -360,6 +364,10 @@ RelativePath="..\..\boinc\api\boinc_gl.h" > + + diff --git a/win_build/samples.sln b/win_build/samples.sln index 3191183e1e..b22cb26f32 100644 --- a/win_build/samples.sln +++ b/win_build/samples.sln @@ -12,23 +12,23 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glut", "glut.vcproj", "{C41 EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "upper_case", "upper_case.vcproj", "{8281D898-0E64-44EB-8356-4F0336F19A35}" ProjectSection(ProjectDependencies) = postProject - {D3D21F11-A7E7-4EA2-8518-E24695133BFF} = {D3D21F11-A7E7-4EA2-8518-E24695133BFF} - {C4165626-F68F-4F66-A126-3B82DDBB7480} = {C4165626-F68F-4F66-A126-3B82DDBB7480} - {0BC1DB36-030A-4321-B387-1CEE2611E329} = {0BC1DB36-030A-4321-B387-1CEE2611E329} - {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} = {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} {5F065EAC-B881-4E9A-9E34-7A21D7A01D98} = {5F065EAC-B881-4E9A-9E34-7A21D7A01D98} + {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} = {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} + {0BC1DB36-030A-4321-B387-1CEE2611E329} = {0BC1DB36-030A-4321-B387-1CEE2611E329} + {C4165626-F68F-4F66-A126-3B82DDBB7480} = {C4165626-F68F-4F66-A126-3B82DDBB7480} + {D3D21F11-A7E7-4EA2-8518-E24695133BFF} = {D3D21F11-A7E7-4EA2-8518-E24695133BFF} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wrapper", "wrapper.vcproj", "{F243B93C-73CB-44E7-9BDC-847BB95A27CA}" ProjectSection(ProjectDependencies) = postProject - {0BC1DB36-030A-4321-B387-1CEE2611E329} = {0BC1DB36-030A-4321-B387-1CEE2611E329} {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} = {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} + {0BC1DB36-030A-4321-B387-1CEE2611E329} = {0BC1DB36-030A-4321-B387-1CEE2611E329} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sleeper", "sleeper.vcproj", "{A9647CEA-644D-4C0A-8733-D916CD344859}" ProjectSection(ProjectDependencies) = postProject - {0BC1DB36-030A-4321-B387-1CEE2611E329} = {0BC1DB36-030A-4321-B387-1CEE2611E329} {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} = {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} + {0BC1DB36-030A-4321-B387-1CEE2611E329} = {0BC1DB36-030A-4321-B387-1CEE2611E329} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "worker", "worker.vcproj", "{F1BE6109-586D-448E-8C5B-D5C2CB874EA2}" @@ -38,17 +38,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "worker", "worker.vcproj", " EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "uc2", "uc2.vcproj", "{CCB9A37C-7AD8-4FC1-ABEC-1A6ED2268F83}" ProjectSection(ProjectDependencies) = postProject - {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} = {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} {0BC1DB36-030A-4321-B387-1CEE2611E329} = {0BC1DB36-030A-4321-B387-1CEE2611E329} + {814EBFD3-3CE6-4933-A580-C1FE3147ACB4} = {814EBFD3-3CE6-4933-A580-C1FE3147ACB4} + {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} = {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "uc2_graphics", "uc2_graphics.vcproj", "{3CF31288-A44D-4C78-A3AA-B05B6E32DF11}" ProjectSection(ProjectDependencies) = postProject - {5F065EAC-B881-4E9A-9E34-7A21D7A01D98} = {5F065EAC-B881-4E9A-9E34-7A21D7A01D98} {814EBFD3-3CE6-4933-A580-C1FE3147ACB4} = {814EBFD3-3CE6-4933-A580-C1FE3147ACB4} - {D3D21F11-A7E7-4EA2-8518-E24695133BFF} = {D3D21F11-A7E7-4EA2-8518-E24695133BFF} - {C4165626-F68F-4F66-A126-3B82DDBB7480} = {C4165626-F68F-4F66-A126-3B82DDBB7480} + {5F065EAC-B881-4E9A-9E34-7A21D7A01D98} = {5F065EAC-B881-4E9A-9E34-7A21D7A01D98} {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} = {E8F6BD7E-461A-4733-B7D8-37B09A099ED8} + {C4165626-F68F-4F66-A126-3B82DDBB7480} = {C4165626-F68F-4F66-A126-3B82DDBB7480} + {D3D21F11-A7E7-4EA2-8518-E24695133BFF} = {D3D21F11-A7E7-4EA2-8518-E24695133BFF} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libgraphics2", "libgraphics2.vcproj", "{814EBFD3-3CE6-4933-A580-C1FE3147ACB4}" diff --git a/win_build/uc2.vcproj b/win_build/uc2.vcproj index 0ecdb1ae42..8c8e886492 100644 --- a/win_build/uc2.vcproj +++ b/win_build/uc2.vcproj @@ -416,6 +416,10 @@ Name="Source Files" Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" > + + @@ -430,6 +434,10 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl" > + + diff --git a/win_build/uc2_graphics.vcproj b/win_build/uc2_graphics.vcproj index b10e684647..6fbbeb3a80 100644 --- a/win_build/uc2_graphics.vcproj +++ b/win_build/uc2_graphics.vcproj @@ -430,6 +430,10 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl" > + +