mirror of https://github.com/BOINC/boinc.git
parent
d93114a51f
commit
55eca25ed5
|
@ -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
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "boinc_win.h"
|
||||
#include "win_util.h"
|
||||
#else
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "boinc_win.h"
|
||||
#include "win_util.h"
|
||||
#else
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue