2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2006-06-13 22:30:14 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2006-06-13 22:30:14 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC 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 3 of the License, or (at your option) any later version.
|
2006-06-13 22:30:14 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2006-06-13 22:30:14 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2006-06-13 22:30:14 +00:00
|
|
|
|
|
|
|
// worker - application without BOINC runtime system;
|
2006-11-25 02:54:25 +00:00
|
|
|
// used for testing wrapper.
|
|
|
|
// What this does:
|
|
|
|
//
|
|
|
|
// copies one line of stdin to stdout
|
|
|
|
// copies one line of "in" to "out"
|
|
|
|
// uses 10 sec of CPU time
|
|
|
|
// (or as specified by a command-line arg)
|
2006-09-11 18:33:37 +00:00
|
|
|
//
|
|
|
|
// THIS PROGRAM SHOULDN'T USE ANY BOINC CODE. That's the whole point.
|
2006-06-13 22:30:14 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2006-11-22 19:48:35 +00:00
|
|
|
#include <stdlib.h>
|
2006-06-13 22:30:14 +00:00
|
|
|
#include <time.h>
|
2006-09-11 18:33:37 +00:00
|
|
|
|
2008-07-01 22:37:19 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2006-11-25 00:49:09 +00:00
|
|
|
int main(int argc, char** argv) {
|
2006-06-13 22:30:14 +00:00
|
|
|
char buf[256];
|
2006-11-25 02:54:25 +00:00
|
|
|
FILE* in, *out;
|
2006-06-13 22:30:14 +00:00
|
|
|
|
2006-06-14 20:14:20 +00:00
|
|
|
fprintf(stderr, "worker starting\n");
|
2006-11-25 02:54:25 +00:00
|
|
|
in = fopen("in", "r");
|
2008-07-01 22:37:19 +00:00
|
|
|
if (!in) {
|
|
|
|
fprintf(stderr, "missing input file\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-11-25 02:54:25 +00:00
|
|
|
out = fopen("out", "w");
|
2008-07-01 22:37:19 +00:00
|
|
|
if (!out) {
|
|
|
|
fprintf(stderr, "can't open output file\n");
|
2006-11-25 02:54:25 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fgets(buf, 256, in);
|
|
|
|
fputs(buf, out);
|
|
|
|
|
2006-11-25 00:49:09 +00:00
|
|
|
fgets(buf, 256, stdin);
|
|
|
|
fputs(buf, stdout);
|
2006-11-25 02:54:25 +00:00
|
|
|
|
2006-06-13 22:30:14 +00:00
|
|
|
int start = time(0);
|
2006-11-25 00:55:49 +00:00
|
|
|
int nsec = 10;
|
|
|
|
if (argc > 1) nsec = atoi(argv[1]);
|
|
|
|
|
2008-07-01 22:37:19 +00:00
|
|
|
int i=0;
|
2006-11-25 00:55:49 +00:00
|
|
|
while (time(0) < start+nsec) {
|
2008-07-01 22:37:19 +00:00
|
|
|
do_a_giga_flop(i++);
|
2006-06-13 22:30:14 +00:00
|
|
|
}
|
2006-11-25 00:49:09 +00:00
|
|
|
fputs("done!\n", stdout);
|
2006-06-14 20:14:20 +00:00
|
|
|
return 0;
|
2006-06-13 22:30:14 +00:00
|
|
|
}
|
2006-06-13 23:12:36 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2006-11-22 19:53:59 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
// take a string containing some space separated words.
|
|
|
|
// return an array of pointers to the null-terminated words.
|
|
|
|
// Modifies the string arg.
|
|
|
|
// Returns argc
|
|
|
|
// TODO: use strtok here
|
|
|
|
|
|
|
|
#define NOT_IN_TOKEN 0
|
|
|
|
#define IN_SINGLE_QUOTED_TOKEN 1
|
|
|
|
#define IN_DOUBLE_QUOTED_TOKEN 2
|
|
|
|
#define IN_UNQUOTED_TOKEN 3
|
|
|
|
|
|
|
|
int parse_command_line(char* p, char** argv) {
|
|
|
|
int state = NOT_IN_TOKEN;
|
|
|
|
int argc=0;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
switch(state) {
|
|
|
|
case NOT_IN_TOKEN:
|
|
|
|
if (isspace(*p)) {
|
|
|
|
} else if (*p == '\'') {
|
|
|
|
p++;
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_SINGLE_QUOTED_TOKEN;
|
|
|
|
break;
|
|
|
|
} else if (*p == '\"') {
|
|
|
|
p++;
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_DOUBLE_QUOTED_TOKEN;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
argv[argc++] = p;
|
|
|
|
state = IN_UNQUOTED_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_SINGLE_QUOTED_TOKEN:
|
|
|
|
if (*p == '\'') {
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_DOUBLE_QUOTED_TOKEN:
|
|
|
|
if (*p == '\"') {
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IN_UNQUOTED_TOKEN:
|
|
|
|
if (isspace(*p)) {
|
|
|
|
*p = 0;
|
|
|
|
state = NOT_IN_TOKEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
argv[argc] = 0;
|
|
|
|
return argc;
|
|
|
|
}
|
|
|
|
|
2006-06-13 23:12:36 +00:00
|
|
|
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
|
|
|
|
LPSTR command_line;
|
|
|
|
char* argv[100];
|
|
|
|
int argc;
|
|
|
|
|
|
|
|
command_line = GetCommandLine();
|
|
|
|
argc = parse_command_line( command_line, argv );
|
|
|
|
return main(argc, argv);
|
|
|
|
}
|
|
|
|
#endif
|