From 55eca25ed50c693911291f7e2697bd43257f8849 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 30 Nov 2010 05:27:05 +0000 Subject: [PATCH] - Rappture stuff svn path=/trunk/boinc/; revision=22777 --- lib/filesys.cpp | 25 +-- samples/vboxwrapper/vbox_win.cpp | 192 ++++++++++++------------ samples/wrappture/Makefile | 5 +- samples/wrappture/fermi.cpp | 39 +++++ samples/wrappture/wrappture.cpp | 13 +- samples/wrappture/wrappture_example.cpp | 55 ++++--- 6 files changed, 199 insertions(+), 130 deletions(-) create mode 100644 samples/wrappture/fermi.cpp diff --git a/lib/filesys.cpp b/lib/filesys.cpp index 75ef22b8d2..d6bad9d5bc 100644 --- a/lib/filesys.cpp +++ b/lib/filesys.cpp @@ -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,25 +480,26 @@ FILE* boinc_fopen(const char* path, const char* mode) { int boinc_file_exists(const char* path) { - struct stat buf; - if (stat(path, &buf)) { - return false; // stat() returns zero on success - } - return true; + printf("boinc_file_exists: %s\n", path); + struct stat buf; + if (stat(path, &buf)) { + return false; // stat() returns zero on success + } + return true; } // same, but doesn't traverse symlinks // int boinc_file_or_symlink_exists(const char* path) { - struct stat buf; + struct stat buf; #ifdef _WIN32 - if (stat(path, &buf)) { + if (stat(path, &buf)) { #else - if (lstat(path, &buf)) { + if (lstat(path, &buf)) { #endif - return false; // stat() returns zero on success - } - return true; + return false; // stat() returns zero on success + } + return true; } // returns zero on success, nonzero if didn't touch file diff --git a/samples/vboxwrapper/vbox_win.cpp b/samples/vboxwrapper/vbox_win.cpp index 63944bdeab..b44a82b581 100644 --- a/samples/vboxwrapper/vbox_win.cpp +++ b/samples/vboxwrapper/vbox_win.cpp @@ -1,82 +1,82 @@ -// This file is part of BOINC. -// http://boinc.berkeley.edu -// Copyright (C) 2010 University of California -// -// 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. -// -// BOINC 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. -// -// You should have received a copy of the GNU Lesser General Public License -// along with BOINC. If not, see . - -#ifdef _WIN32 -#include "boinc_win.h" -#include "win_util.h" -#else -#include -#include -#include -#include -#include -#include -#include -#endif - -#include "diagnostics.h" -#include "filesys.h" -#include "parse.h" -#include "str_util.h" -#include "str_replace.h" -#include "util.h" -#include "error_numbers.h" -#include "procinfo.h" -#include "boinc_api.h" -#include "vbox.h" -#include "mscom/VirtualBox.h" - - -IVirtualBox* pVirtualBox; -ISession* pSession; -IMachine* pMachine; - - -int virtualbox_initialize() { - HRESULT rc; - - // Initialize the COM subsystem. - CoInitialize(NULL); - - // Instantiate the VirtualBox root object. - rc = CoCreateInstance(CLSID_VirtualBox, /* the VirtualBox base object */ - NULL, /* no aggregation */ - CLSCTX_LOCAL_SERVER, /* the object lives in a server process on this machine */ - IID_IVirtualBox, /* IID of the interface */ - (void**)&pVirtualBox); - - if (!SUCCEEDED(rc)) - { - fprintf(stderr, "Error creating VirtualBox instance! rc = 0x%x\n", rc); - return rc; - } - - return 0; -} - -int virtualbox_cleanup() { - - // Cleanup. +// This file is part of BOINC. +// http://boinc.berkeley.edu +// Copyright (C) 2010 University of California +// +// 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. +// +// BOINC 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. +// +// You should have received a copy of the GNU Lesser General Public License +// along with BOINC. If not, see . + +#ifdef _WIN32 +#include "boinc_win.h" +#include "win_util.h" +#else +#include +#include +#include +#include +#include +#include +#include +#endif + +#include "diagnostics.h" +#include "filesys.h" +#include "parse.h" +#include "str_util.h" +#include "str_replace.h" +#include "util.h" +#include "error_numbers.h" +#include "procinfo.h" +#include "boinc_api.h" +#include "vbox.h" +#include "mscom/VirtualBox.h" + + +IVirtualBox* pVirtualBox; +ISession* pSession; +IMachine* pMachine; + + +int virtualbox_initialize() { + HRESULT rc; + + // Initialize the COM subsystem. + CoInitialize(NULL); + + // Instantiate the VirtualBox root object. + rc = CoCreateInstance(CLSID_VirtualBox, /* the VirtualBox base object */ + NULL, /* no aggregation */ + CLSCTX_LOCAL_SERVER, /* the object lives in a server process on this machine */ + IID_IVirtualBox, /* IID of the interface */ + (void**)&pVirtualBox); + + if (!SUCCEEDED(rc)) + { + fprintf(stderr, "Error creating VirtualBox instance! rc = 0x%x\n", rc); + return rc; + } + + return 0; +} + +int virtualbox_cleanup() { + + // Cleanup. CoUninitialize(); - - return 0; -} - -int virtualbox_enumeratevms() { + + return 0; +} + +int virtualbox_enumeratevms() { HRESULT rc; SAFEARRAY *machinesArray = NULL; @@ -106,21 +106,21 @@ int virtualbox_enumeratevms() { SafeArrayDestroy (machinesArray); } - return 0; -} - -int virtualbox_startvm() { - return 1; -} - -int virtualbox_stopvm() { - return 0; -} - -int virtualbox_pausevm() { - return 0; -} - -int virtualbox_resumevm() { - return 0; -} + return 0; +} + +int virtualbox_startvm() { + return 1; +} + +int virtualbox_stopvm() { + return 0; +} + +int virtualbox_pausevm() { + return 0; +} + +int virtualbox_resumevm() { + return 0; +} diff --git a/samples/wrappture/Makefile b/samples/wrappture/Makefile index 48cdc54a36..a0e7167086 100644 --- a/samples/wrappture/Makefile +++ b/samples/wrappture/Makefile @@ -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 diff --git a/samples/wrappture/fermi.cpp b/samples/wrappture/fermi.cpp new file mode 100644 index 0000000000..87ac1029d3 --- /dev/null +++ b/samples/wrappture/fermi.cpp @@ -0,0 +1,39 @@ +// fermi.cpp -- core calculation of Rappture example app-fermi + +#include +#include +#include +#include + +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; +} diff --git a/samples/wrappture/wrappture.cpp b/samples/wrappture/wrappture.cpp index 25173c0605..fa928e6556 100644 --- a/samples/wrappture/wrappture.cpp +++ b/samples/wrappture/wrappture.cpp @@ -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"; diff --git a/samples/wrappture/wrappture_example.cpp b/samples/wrappture/wrappture_example.cpp index 34fb012b6c..f4263b71cb 100644 --- a/samples/wrappture/wrappture_example.cpp +++ b/samples/wrappture/wrappture_example.cpp @@ -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,24 +101,40 @@ 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 - -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 +#ifdef _WIN32 + +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