mirror of https://github.com/BOINC/boinc.git
parent
d13c08e67c
commit
2c18c2f209
139
apps/uc_cpu.C
139
apps/uc_cpu.C
|
@ -1,139 +0,0 @@
|
|||
// 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 <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "filesys.h"
|
||||
#include "boinc_api.h"
|
||||
|
||||
#define CHECKPOINT_FILE "uc_slow_state"
|
||||
|
||||
time_t my_start_time;
|
||||
|
||||
int do_checkpoint(MFILE& mf, int nchars) {
|
||||
int retval;
|
||||
char resolved_name[512],res_name2[512];
|
||||
FILE *app_time = fopen("../../app.time", "w"),
|
||||
*client_time = fopen("../../client.time", "w");
|
||||
APP_INIT_DATA aid;
|
||||
|
||||
boinc_get_init_data(aid);
|
||||
boinc_resolve_filename( "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_filename( CHECKPOINT_FILE, res_name2 );
|
||||
retval = boinc_rename(resolved_name, res_name2);
|
||||
if (retval) return retval;
|
||||
// hopefully atomic part ends here
|
||||
|
||||
// print our own information about cpu time
|
||||
fprintf(app_time, "%f\n", difftime(time(0), my_start_time));
|
||||
fflush(app_time);
|
||||
fclose(app_time);
|
||||
|
||||
// print what the client thinks is our cpu time
|
||||
fprintf(client_time, "%f\n", aid.wu_cpu_time + boinc_cpu_time());
|
||||
fflush(client_time);
|
||||
fclose(client_time);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int c, nchars = 0, retval, n;
|
||||
unsigned long int i;
|
||||
double j;
|
||||
char resolved_name[512];
|
||||
MFILE out, time_file;
|
||||
FILE* state, *in;
|
||||
|
||||
my_start_time = time(0);
|
||||
|
||||
boinc_init();
|
||||
|
||||
boinc_resolve_filename( "in", resolved_name );
|
||||
in = fopen(resolved_name, "r");
|
||||
boinc_resolve_filename( 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_filename( "out", resolved_name );
|
||||
retval = out.open(resolved_name, "a");
|
||||
} else {
|
||||
boinc_resolve_filename( "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<200000000; i++) {
|
||||
n++;
|
||||
j *= n+j-3.14159;
|
||||
j /= (float)n;
|
||||
}
|
||||
|
||||
if (boinc_time_to_checkpoint()) {
|
||||
retval = do_checkpoint(out, nchars);
|
||||
if (retval) {
|
||||
fprintf(stderr, "APP: uc_slow checkpoint failed %d\n", retval);
|
||||
}
|
||||
boinc_checkpoint_completed();
|
||||
}
|
||||
}
|
||||
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);
|
||||
time_file.printf("%f\n", boinc_cpu_time());
|
||||
time_file.flush();
|
||||
time_file.close();
|
||||
boinc_finish(0);
|
||||
return 0;
|
||||
}
|
114
apps/uc_slow.C
114
apps/uc_slow.C
|
@ -1,114 +0,0 @@
|
|||
// 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 <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "filesys.h"
|
||||
#include "boinc_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_filename( "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_filename( CHECKPOINT_FILE, res_name2 );
|
||||
retval = boinc_rename(resolved_name, res_name2);
|
||||
if (retval) return retval;
|
||||
// hopefully atomic part ends here
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int c, nchars = 0, retval, n;
|
||||
char resolved_name[512];
|
||||
MFILE out, time_file;
|
||||
FILE* state, *in;
|
||||
|
||||
boinc_init();
|
||||
|
||||
boinc_resolve_filename( "in", resolved_name );
|
||||
in = fopen(resolved_name, "r");
|
||||
boinc_resolve_filename( 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_filename( "out", resolved_name );
|
||||
retval = out.open(resolved_name, "a");
|
||||
} else {
|
||||
boinc_resolve_filename( "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++;
|
||||
|
||||
sleep(1);
|
||||
|
||||
if (boinc_time_to_checkpoint()) {
|
||||
retval = do_checkpoint(out, nchars);
|
||||
if (retval) {
|
||||
fprintf(stderr, "APP: uc_slow checkpoint failed %d\n", retval);
|
||||
exit(1);
|
||||
}
|
||||
boinc_checkpoint_completed();
|
||||
}
|
||||
}
|
||||
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);
|
||||
time_file.printf("%f\n", boinc_cpu_time());
|
||||
time_file.flush();
|
||||
time_file.close();
|
||||
boinc_finish(0);
|
||||
return 0;
|
||||
}
|
|
@ -17,37 +17,168 @@
|
|||
// Contributor(s):
|
||||
//
|
||||
|
||||
// read stdin, convert to UC, write to stdout
|
||||
// read "in", convert to UC, write to "out"
|
||||
// command line options:
|
||||
// -run_slow: app will sleep 1 second after each character, useful for
|
||||
// debugging
|
||||
// -cpu_time: app will chew up some CPU cycles after each character,
|
||||
// used for testing CPU time reporting
|
||||
//
|
||||
// This version does one char/second,
|
||||
// and writes its state to disk every so often
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "filesys.h"
|
||||
#include "boinc_api.h"
|
||||
|
||||
#define CHECKPOINT_FILE "upper_case_state"
|
||||
|
||||
int run_slow=0,cpu_time=0;
|
||||
time_t my_start_time;
|
||||
|
||||
int do_checkpoint(MFILE& mf, int nchars) {
|
||||
int retval;
|
||||
char resolved_name[512],res_name2[512];
|
||||
FILE *app_time, *client_time;
|
||||
APP_INIT_DATA aid;
|
||||
|
||||
if (cpu_time) {
|
||||
app_time = fopen("../../app.time", "w"),
|
||||
client_time = fopen("../../client.time", "w");
|
||||
boinc_get_init_data(aid);
|
||||
}
|
||||
boinc_resolve_filename( "temp", resolved_name );
|
||||
FILE* f = fopen(resolved_name, "w");
|
||||
if (!f) return 1;
|
||||
fprintf(f, "%d", nchars);
|
||||
fclose(f);
|
||||
|
||||
fprintf(stderr, "APP: upper_case checkpointing\n");
|
||||
|
||||
// hopefully atomic part starts here
|
||||
retval = mf.flush();
|
||||
if (retval) return retval;
|
||||
boinc_resolve_filename( CHECKPOINT_FILE, res_name2 );
|
||||
retval = boinc_rename(resolved_name, res_name2);
|
||||
if (retval) return retval;
|
||||
// hopefully atomic part ends here
|
||||
|
||||
if (cpu_time) {
|
||||
// print our own information about cpu time
|
||||
fprintf(app_time, "%f\n", difftime(time(0), my_start_time));
|
||||
fflush(app_time);
|
||||
fclose(app_time);
|
||||
|
||||
// print what the client thinks is our cpu time
|
||||
fprintf(client_time, "%f\n", aid.wu_cpu_time + boinc_cpu_time());
|
||||
fflush(client_time);
|
||||
fclose(client_time);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
|
||||
#else
|
||||
int main() {
|
||||
LPWSTR command_line;
|
||||
LPWSTR *args;
|
||||
char* argv[100];
|
||||
int i, argc;
|
||||
|
||||
command_line = GetCommandLineW();
|
||||
args = CommandLineToArgvW(command_line, &argc);
|
||||
|
||||
// uh, why did MS have to "improve" on char*?
|
||||
|
||||
for (i=0; i<argc; i++) {
|
||||
argv[i] = (char*)args[i];
|
||||
}
|
||||
return main(argc, argv);
|
||||
}
|
||||
#endif
|
||||
int c, n=0, retval;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int c, nchars = 0, retval, i, n;
|
||||
double j;
|
||||
char resolved_name[512];
|
||||
MFILE out, time_file;
|
||||
FILE* state, *in;
|
||||
|
||||
my_start_time = time(0);
|
||||
|
||||
retval = boinc_init();
|
||||
if (retval) exit(retval);
|
||||
fprintf(stderr, "APP: upper_case starting\n");
|
||||
fflush(stderr);
|
||||
|
||||
boinc_resolve_filename( "in", resolved_name );
|
||||
fprintf( stderr, "APP: upper_case: starting, argc %d\n", argc );
|
||||
for (i=0; i<argc; i++) {
|
||||
fprintf(stderr, "APP: upper_case: argv[%d] is %s\n", i, argv[i]);
|
||||
if (!strcmp(argv[i], "-run_slow")) run_slow = 1;
|
||||
if (!strcmp(argv[i], "-cpu_time")) cpu_time = 1;
|
||||
}
|
||||
in = fopen(resolved_name, "r");
|
||||
boinc_resolve_filename( 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_filename( "out", resolved_name );
|
||||
retval = out.open(resolved_name, "a");
|
||||
} else {
|
||||
boinc_resolve_filename( "out", resolved_name );
|
||||
retval = out.open(resolved_name, "w");
|
||||
}
|
||||
if (retval) {
|
||||
fprintf(stderr, "APP: upper_case output open failed %d\n", retval);
|
||||
exit(1);
|
||||
}
|
||||
time_file.open("../../time.xml", "w");
|
||||
while (1) {
|
||||
c = getchar();
|
||||
c = fgetc(in);
|
||||
if (c == EOF) break;
|
||||
c = toupper(c);
|
||||
putchar(c);
|
||||
n++;
|
||||
out._putchar(c);
|
||||
nchars++;
|
||||
|
||||
if (cpu_time) {
|
||||
n = 0;
|
||||
j = 3.14159;
|
||||
for(i=0; i<200000000; i++) {
|
||||
n++;
|
||||
j *= n+j-3.14159;
|
||||
j /= (float)n;
|
||||
}
|
||||
|
||||
if (n==j) n = 0;
|
||||
}
|
||||
|
||||
if (run_slow) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
if (boinc_time_to_checkpoint()) {
|
||||
fflush(stdout);
|
||||
retval = do_checkpoint(out, nchars);
|
||||
if (retval) {
|
||||
fprintf(stderr, "APP: upper_case checkpoint failed %d\n", retval);
|
||||
exit(1);
|
||||
}
|
||||
boinc_checkpoint_completed();
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "APP: upper_case ending, wrote %d chars\n", n);
|
||||
retval = out.flush();
|
||||
if (retval) {
|
||||
fprintf(stderr, "APP: upper_case flush failed %d\n", retval);
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stderr, "APP: upper_case ending, wrote %d chars\n", nchars);
|
||||
time_file.printf("%f\n", boinc_cpu_time());
|
||||
time_file.flush();
|
||||
time_file.close();
|
||||
boinc_finish(0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1824,3 +1824,20 @@ David August 30 2002
|
|||
error_numbers.h
|
||||
filesys.C
|
||||
md5_file.C
|
||||
|
||||
Eric September 4, 2002
|
||||
- condensed uc_slow, uc_cpu into upper_case, using command line arguments
|
||||
- changed test_uc to use files rather than stdin/stdout
|
||||
|
||||
apps/
|
||||
uc_slow.C (removed)
|
||||
uc_cpu.C (removed)
|
||||
upper_case.C
|
||||
lib/
|
||||
error_numbers.h
|
||||
test/
|
||||
test_uc_slow.php
|
||||
uc_result
|
||||
uc_wu
|
||||
ucs_wu
|
||||
|
||||
|
|
|
@ -47,4 +47,4 @@
|
|||
#define ERR_RSA_FAILED -119
|
||||
#define ERR_OPEN -120
|
||||
#define ERR_DUP2 -121
|
||||
#define ERR_NO_SIGNATURE -22
|
||||
#define ERR_NO_SIGNATURE -122
|
||||
|
|
|
@ -8,15 +8,21 @@
|
|||
|
||||
check_env_vars();
|
||||
clear_db();
|
||||
clear_data_dirs();
|
||||
create_keys();
|
||||
if (true) {
|
||||
clear_server_dirs(false);
|
||||
} else {
|
||||
clear_server_dirs(true);
|
||||
create_keys();
|
||||
}
|
||||
clear_client_dirs();
|
||||
init_client_dirs("prefs1.xml");
|
||||
copy_to_download_dir("small_input");
|
||||
add_project("Test Project");
|
||||
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("upper_case", null, null);
|
||||
add_core_client(null);
|
||||
create_work("-appname upper_case -wu_name ucs_wu -wu_template ucs_wu -result_template ucs_result -nresults 1 small_input");
|
||||
echo "Now run the client manually; start and stop it a few times.\n";
|
||||
start_feeder();
|
||||
//run_client();
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
<wu_name><WU_NAME/></wu_name>
|
||||
<file_ref>
|
||||
<file_name><OUTFILE_0/></file_name>
|
||||
<fd>1</fd>
|
||||
<open_name>out</open_name>
|
||||
</file_ref>
|
||||
</result>
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
<app_name>upper_case</app_name>
|
||||
<file_ref>
|
||||
<file_name><INFILE_0/></file_name>
|
||||
<fd>0</fd>
|
||||
<open_name>in</open_name>
|
||||
</file_ref>
|
||||
</workunit>
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
</file_info>
|
||||
<workunit>
|
||||
<name><WU_NAME/></name>
|
||||
<app_name>uc_slow</app_name>
|
||||
<app_name>upper_case</app_name>
|
||||
<file_ref>
|
||||
<file_name><INFILE_0/></file_name>
|
||||
<open_name>in</open_name>
|
||||
</file_ref>
|
||||
<command_line>-run_slow</command_line>
|
||||
</workunit>
|
||||
|
|
Loading…
Reference in New Issue