- Rappture stuff

svn path=/trunk/boinc/; revision=22777
This commit is contained in:
David Anderson 2010-11-30 05:27:05 +00:00
parent d93114a51f
commit 55eca25ed5
6 changed files with 199 additions and 130 deletions

View File

@ -427,6 +427,8 @@ int dir_size(const char* dirpath, double& size, bool recurse) {
FILE* boinc_fopen(const char* path, const char* mode) {
printf("boinc_fopen: %s\n", path);
// if opening for read, and file isn't there,
// leave now (avoid 5-second delay!!)
//
@ -478,6 +480,7 @@ FILE* boinc_fopen(const char* path, const char* mode) {
int boinc_file_exists(const char* path) {
printf("boinc_file_exists: %s\n", path);
struct stat buf;
if (stat(path, &buf)) {
return false; // stat() returns zero on success

View File

@ -13,7 +13,7 @@ CXXFLAGS = -g \
-L$(BOINC_LIB_DIR) \
-L.
PROGS = wrappture_example
PROGS = wrappture_example fermi
all: $(PROGS)
@ -31,3 +31,6 @@ wrappture.o: wrappture.cpp
wrappture_example: wrappture.o wrappture_example.o libstdc++.a $(BOINC_LIB_DIR)/libboinc.a $(BOINC_API_DIR)/libboinc_api.a
g++ $(CXXFLAGS) -o wrappture_example wrappture_example.o wrappture.o libstdc++.a -pthread -lboinc_api -lboinc
fermi: fermi.cpp
g++ $(CSSFLAGS) -o fermi fermi.cpp

View File

@ -0,0 +1,39 @@
// fermi.cpp -- core calculation of Rappture example app-fermi
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
int main(int argc, char * argv[]) {
double T, Ef, E, dE, kT, Emin, Emax, f;
FILE *fo = fopen("fermi_out.dat", "w");
if (!fo) {
fprintf(stderr, "Failed to open output file\n");
exit(-1);
}
// Check args
if (3 != argc) {
fprintf(stderr, "Usage: %s T Ef\n", argv[0]);
exit(-1);
}
T = atof(argv[1]); // in K
Ef = atof(argv[2]); // in eV
kT = 8.61734e-5 * T;
Emin = Ef - 10.0*kT;
Emax = Ef + 10.0*kT;
E = Emin;
dE = 0.005*(Emax-Emin);
while (E < Emax) {
f = 1.0/(1.0 + exp((E - Ef)/kT));
fprintf(fo, "%f %f\n",f, E);
fprintf(stdout, "=RAPPTURE-PROGRESS=>%d\n", (int)((E-Emin)/(Emax-Emin)*100));
E = E + dE;
}
fclose(fo);
return 0;
}

View File

@ -406,9 +406,17 @@ void send_status_message(
#ifdef _WIN32
DWORD WINAPI parse_app_stdout(void*) {
#else
void* parse_app_stdout(void*) {
static void block_sigalrm() {
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGALRM);
pthread_sigmask(SIG_BLOCK, &mask, NULL);
}
static void* parse_app_stdout(void*) {
block_sigalrm();
#endif
char buf[8192];
char buf[1024];
FILE* f = boinc_fopen("rappture_stdout.txt", "r");
while (1) {
@ -454,7 +462,6 @@ int boinc_run_rappture_app(const char* program, const char* cmdline) {
options.handle_process_control = true;
boinc_init_options(&options);
memset(&task, 0, sizeof(task));
task.application = program;
task.command_line = cmdline;
task.stdout_filename = "rappture_stdout.txt";

View File

@ -23,11 +23,13 @@
#include "error_numbers.h"
#include "boinc_api.h"
#include "str_util.h"
#include "filesys.h"
#include "wrappture.h"
#define RPLIB_OVERWRITE 0
#define RPLIB_APPEND 0
struct RpLibrary{};
RpLibrary* rpLibrary(char*){return NULL;}
RpLibrary* rpLibrary(char*){return new RpLibrary;}
void rpGetString(RpLibrary*, const char*, const char**){}
double rpConvertDbl(const char*, const char*, int*){return 0;}
void rpPutString (RpLibrary*, const char*, const char*, int){}
@ -38,7 +40,6 @@ int main(int argc, char * argv[]) {
RpLibrary* lib = NULL;
const char* data = NULL;
//char line[100];
double T = 0.0;
double Ef = 0.0;
@ -100,13 +101,29 @@ int main(int argc, char * argv[]) {
"eV",
RPLIB_OVERWRITE );
int retval = boinc_run_rappture_app("foobar.exe", "-kT 4.3");
if (retval == 0) {
boinc_finish(0);
rpResult(lib);
} else {
// Run core simulator
char buf[256];
sprintf(buf, "%g %g", T, Ef);
int retval = boinc_run_rappture_app("fermi", buf);
if (retval) {
fprintf(stderr, "boinc_run_rappture_app(): %d\n", retval);
boinc_finish(EXIT_CHILD_FAILED);
}
// Read resulting output file
FILE* file;
if (!(file = boinc_fopen("fermi_out.dat", "r"))) {
fprintf(stderr, "Unable to open data file\n");
exit(-1);
}
while (fgets(buf, sizeof(buf), file)) {
rpPutString(lib, "output.curve(f12).component.xy", buf, RPLIB_APPEND);
}
fclose(file);
// Finish
rpResult(lib);
boinc_finish(0);
}
#ifdef _WIN32