2004-06-09 19:09:16 +00:00
|
|
|
<?php
|
2003-08-19 06:44:58 +00:00
|
|
|
require_once("docutil.php");
|
|
|
|
page_head("The BOINC application programming interface (API)");
|
|
|
|
echo "
|
2002-09-05 11:46:10 +00:00
|
|
|
<p>
|
2004-08-16 11:31:59 +00:00
|
|
|
The BOINC API is a set of C++ functions.
|
|
|
|
Most of the functions have a C interface,
|
|
|
|
so that they can be used from programs written in C and other languages.
|
2002-07-31 05:59:43 +00:00
|
|
|
Unless otherwise specified,
|
|
|
|
the functions return an integer error code; zero indicates success.
|
2004-08-04 17:16:18 +00:00
|
|
|
<p>
|
|
|
|
BOINC applications may generate graphics,
|
|
|
|
allowing them to provide a screensaver.
|
|
|
|
This API is described <a href=graphics.php>here</a>.
|
|
|
|
<p>
|
|
|
|
BOINC applications may consist of several programs that are
|
|
|
|
executed in sequence;
|
2004-10-28 20:42:44 +00:00
|
|
|
these are called <b>compound applications</b>.
|
|
|
|
This API is described <a href=compound_app.php>here</a>.
|
2004-08-04 17:16:18 +00:00
|
|
|
|
2002-07-30 18:06:39 +00:00
|
|
|
|
|
|
|
<h3>Initialization and termination</h3>
|
2004-10-28 20:42:44 +00:00
|
|
|
|
|
|
|
<p>
|
|
|
|
Applications should
|
|
|
|
<a href=diagnostics.php>initialize diagnostics</a>
|
|
|
|
before any other BOINC calls.
|
|
|
|
<p>
|
|
|
|
Initialization for graphical and compound applications
|
|
|
|
are described elsewhere (see links above).
|
|
|
|
Other applications must call
|
2002-07-30 18:06:39 +00:00
|
|
|
<pre>
|
2004-08-04 17:16:18 +00:00
|
|
|
int boinc_init();
|
2002-07-30 18:06:39 +00:00
|
|
|
</pre>
|
|
|
|
before calling other BOINC functions or doing I/O.
|
2004-10-28 20:42:44 +00:00
|
|
|
<p>
|
2002-08-05 00:29:34 +00:00
|
|
|
When the application has completed it must call
|
2002-07-30 18:06:39 +00:00
|
|
|
<pre>
|
2004-08-04 17:16:18 +00:00
|
|
|
int boinc_finish(int status);
|
2002-07-30 18:06:39 +00:00
|
|
|
</pre>
|
2003-11-07 23:26:17 +00:00
|
|
|
<code>status</code> is nonzero if an error was encountered.
|
2003-09-05 21:26:21 +00:00
|
|
|
This call does not return.
|
2002-07-30 18:06:39 +00:00
|
|
|
|
|
|
|
<h3>Resolving file names</h3>
|
|
|
|
Applications that use named input or output files must call
|
|
|
|
<pre>
|
2003-11-07 23:26:17 +00:00
|
|
|
int boinc_resolve_filename(char *logical_name, char *physical_name, int len);
|
|
|
|
</pre>
|
|
|
|
or
|
2004-04-20 05:05:52 +00:00
|
|
|
", html_text("
|
2003-11-07 23:26:17 +00:00
|
|
|
int boinc_resolve_filename(char *logical_name, string& physical_name);
|
2004-04-20 05:05:52 +00:00
|
|
|
"), "
|
2002-07-30 18:06:39 +00:00
|
|
|
to convert logical file names to physical names.
|
|
|
|
For example, instead of
|
|
|
|
<pre>
|
2003-08-19 06:44:58 +00:00
|
|
|
f = fopen(\"my_file\", \"r\");
|
2002-07-30 18:06:39 +00:00
|
|
|
</pre>
|
2002-07-29 19:01:38 +00:00
|
|
|
</p>
|
2002-07-30 18:06:39 +00:00
|
|
|
the application might use
|
2004-04-20 05:05:52 +00:00
|
|
|
", html_text("
|
2003-11-07 23:26:17 +00:00
|
|
|
string resolved_name;
|
2003-08-19 06:44:58 +00:00
|
|
|
retval = boinc_resolve_filename(\"my_file\", resolved_name);
|
|
|
|
if (retval) fail(\"can't resolve filename\");
|
2003-11-07 23:26:17 +00:00
|
|
|
f = fopen(resolved_name.c_str(), \"r\");
|
2004-04-20 05:05:52 +00:00
|
|
|
"), "
|
2003-11-07 23:26:17 +00:00
|
|
|
<code>boinc_resolve_filename()</code> doesn't need to be used for temporary files.
|
2002-07-30 18:06:39 +00:00
|
|
|
|
2004-04-23 22:51:28 +00:00
|
|
|
<h3>I/O wrappers</h3>
|
|
|
|
<p>
|
|
|
|
Applications should replace fopen() calls with
|
|
|
|
<pre>
|
|
|
|
boinc_fopen(char* path, char* mode);
|
|
|
|
</pre>
|
|
|
|
This deals with platform-specific problems.
|
|
|
|
On Windows, where security and indexing programs can briefly lock files,
|
|
|
|
boinc_fopen() does several retries at 1-second intervals.
|
|
|
|
On Unix, where signals can cause fopen() to fail with EINTR,
|
|
|
|
boinc_fopen checks for this and does a few retries.
|
|
|
|
|
2002-07-30 18:06:39 +00:00
|
|
|
<h3>Checkpointing</h3>
|
|
|
|
|
|
|
|
Computations that use a significant amount of time
|
|
|
|
per work unit may want to periodically write the current
|
|
|
|
state of the computation to disk.
|
|
|
|
This is known as <b>checkpointing</b>.
|
|
|
|
The state file must include everything required
|
|
|
|
to start the computation again at the same place it was checkpointed.
|
|
|
|
On startup, the application
|
|
|
|
reads the state file to determine where to begin computation.
|
|
|
|
If the BOINC client quits or exits,
|
|
|
|
the computation can be restarted from the most recent checkpoint.
|
2003-09-05 21:26:21 +00:00
|
|
|
<p>
|
|
|
|
Frequency of checkpointing is a user preference
|
|
|
|
(e.g. laptop users might want to checkpoint infrequently).
|
|
|
|
An application must call
|
|
|
|
<pre>
|
2004-12-22 15:02:03 +00:00
|
|
|
int boinc_time_to_checkpoint();
|
2003-09-05 21:26:21 +00:00
|
|
|
</pre>
|
|
|
|
whenever it reaches a point where it is able to checkpoint.
|
2004-12-22 15:02:03 +00:00
|
|
|
If this returns nonzero,
|
2003-09-05 21:26:21 +00:00
|
|
|
the application should write the state file and flush all output files,
|
|
|
|
then call
|
|
|
|
<pre>
|
|
|
|
void boinc_checkpoint_completed();
|
|
|
|
</pre>
|
2003-11-07 23:26:17 +00:00
|
|
|
<code>boinc_time_to_checkpoint()</code> is fast,
|
|
|
|
so it can be called frequently (hundreds or thousands of times a second).
|
2002-07-30 18:06:39 +00:00
|
|
|
|
2003-09-05 21:26:21 +00:00
|
|
|
<h3>Atomic file update</h3>
|
2002-07-30 18:06:39 +00:00
|
|
|
<p>
|
2003-09-05 21:26:21 +00:00
|
|
|
To facilitate atomic checkpoint, an application can write to output and
|
2003-11-07 23:26:17 +00:00
|
|
|
state files using the <code>MFILE</code> class.
|
2002-07-30 18:06:39 +00:00
|
|
|
<pre>
|
|
|
|
class MFILE {
|
|
|
|
public:
|
|
|
|
int open(char* path, char* mode);
|
|
|
|
int _putchar(char);
|
|
|
|
int puts(char*);
|
|
|
|
int printf(char* format, ...);
|
2002-08-05 00:29:34 +00:00
|
|
|
size_t write(const void* buf, size_t size, size_t nitems);
|
2002-07-30 18:06:39 +00:00
|
|
|
int close();
|
|
|
|
int flush();
|
|
|
|
};
|
|
|
|
</pre>
|
|
|
|
MFILE buffers data in memory
|
2003-11-07 23:26:17 +00:00
|
|
|
and writes to disk only on <code>flush()</code> or <code>close()</code>.
|
2003-09-30 18:09:58 +00:00
|
|
|
This lets you write output files and state files more or less atomically.
|
2002-07-30 18:06:39 +00:00
|
|
|
|
2005-06-24 08:12:11 +00:00
|
|
|
<a name=credit>
|
2005-06-24 04:34:45 +00:00
|
|
|
<h3>Credit reporting</h3>
|
|
|
|
<p>
|
2005-06-24 08:12:11 +00:00
|
|
|
By default, the claimed credit of a result is based on
|
|
|
|
the product of its total CPU time and the
|
|
|
|
benchmark values obtained by the core client.
|
2005-06-24 04:34:45 +00:00
|
|
|
This can produce results that are too low if
|
|
|
|
the application uses processor-specific optimizations
|
|
|
|
not present in the core client,
|
|
|
|
is compiled with different compiler settings,
|
|
|
|
or uses a GPU or other non-CPU computing resource.
|
|
|
|
To handle such cases, the following functions can be used.
|
|
|
|
<pre>
|
|
|
|
void boinc_fpops_per_cpu_second(double);
|
|
|
|
</pre>
|
|
|
|
This reports the results of an application-specific benchmark,
|
|
|
|
expressed as number of floating-point operations per CPU second.
|
|
|
|
<pre>
|
|
|
|
void boinc_fpops_cumulative(double);
|
|
|
|
</pre>
|
|
|
|
This reports the total number of floating-point operations
|
|
|
|
since the start of the result.
|
|
|
|
It must be called just before boinc_finish(),
|
|
|
|
and optionally at intermediate points.
|
|
|
|
|
2003-09-05 21:26:21 +00:00
|
|
|
<h3>Communicating with the core client</h3>
|
|
|
|
<p>
|
2002-07-30 18:06:39 +00:00
|
|
|
The core client GUI displays the percent done of workunits in progress.
|
2003-09-07 03:11:03 +00:00
|
|
|
To keep this display current, an application should periodically call
|
2002-07-30 18:06:39 +00:00
|
|
|
<pre>
|
2002-08-05 00:29:34 +00:00
|
|
|
boinc_fraction_done(double fraction_done);
|
2002-07-30 18:06:39 +00:00
|
|
|
</pre>
|
2003-11-07 23:26:17 +00:00
|
|
|
The <code>fraction_done</code> argument is a rough estimate of the
|
2002-07-31 05:59:43 +00:00
|
|
|
workunit fraction complete (0 to 1).
|
2003-09-07 03:11:03 +00:00
|
|
|
This function is fast and can be called frequently.
|
2002-07-30 18:06:39 +00:00
|
|
|
|
2003-09-05 21:26:21 +00:00
|
|
|
<p>
|
|
|
|
The following functions get information from the core client;
|
|
|
|
this information may be useful for graphics.
|
2004-04-20 05:05:52 +00:00
|
|
|
",
|
|
|
|
html_text("
|
2003-09-05 21:26:21 +00:00
|
|
|
int boinc_get_init_data(APP_INIT_DATA&);
|
|
|
|
|
|
|
|
struct APP_INIT_DATA {
|
2004-08-04 17:16:18 +00:00
|
|
|
int core_version;
|
|
|
|
char app_name[256];
|
|
|
|
char project_preferences[65536];
|
2003-09-05 21:26:21 +00:00
|
|
|
char user_name[256];
|
|
|
|
char team_name[256];
|
2004-04-23 23:01:04 +00:00
|
|
|
char project_dir[256];
|
|
|
|
char boinc_dir[256];
|
|
|
|
char wu_name[256];
|
|
|
|
char authenticator[256];
|
2004-08-04 17:16:18 +00:00
|
|
|
int slot;
|
2003-09-05 21:26:21 +00:00
|
|
|
double user_total_credit;
|
|
|
|
double user_expavg_credit;
|
|
|
|
double team_total_credit;
|
|
|
|
double team_expavg_credit;
|
2004-08-04 17:16:18 +00:00
|
|
|
HOST_INFO host_info;
|
2003-09-05 21:26:21 +00:00
|
|
|
};
|
2004-04-20 05:05:52 +00:00
|
|
|
"), "
|
2003-09-05 21:26:21 +00:00
|
|
|
to get the following information:
|
|
|
|
";
|
|
|
|
list_start();
|
2004-08-04 17:16:18 +00:00
|
|
|
list_item("core version", "The version number of the core client");
|
|
|
|
list_item("app_name", "The application name (from the server's DB)");
|
2003-09-05 21:26:21 +00:00
|
|
|
list_item("project_preferences", "An XML string containing
|
|
|
|
the user's project-specific preferences.");
|
|
|
|
list_item("user_name", " the user's 'screen name' on this project.");
|
|
|
|
list_item("team_name", " the user's team name, if any.");
|
2004-04-23 23:01:04 +00:00
|
|
|
list_item("project_dir", "absolute path of project directory");
|
|
|
|
list_item("boinc_dir", "absolute path of BOINC root directory");
|
|
|
|
list_item("wu_name", "name of workunit being processed");
|
|
|
|
list_item("authenticator", "user's authenticator for this project");
|
2004-08-04 17:16:18 +00:00
|
|
|
list_item("slot", "The number of the app's 'slot' (0, 1, ...)");
|
2003-09-05 21:26:21 +00:00
|
|
|
list_item("user_total_credit", " user's total work for this project.");
|
|
|
|
list_item("user_expavg_credit", " user's recent average work per day.");
|
|
|
|
list_item("team_total_credit", " team's total work for this project.");
|
|
|
|
list_item("team_expavg_credit", " team's recent average work per day.");
|
2004-08-04 17:16:18 +00:00
|
|
|
list_item("host_info", "A structure describing the host hardware and OS");
|
2003-09-05 21:26:21 +00:00
|
|
|
list_end();
|
|
|
|
echo "
|
|
|
|
<p>
|
2003-09-07 03:11:03 +00:00
|
|
|
An application may call
|
2004-04-20 05:05:52 +00:00
|
|
|
", html_text("
|
2003-11-07 23:26:17 +00:00
|
|
|
int boinc_wu_cpu_time(double &cpu_time);
|
2004-04-20 05:05:52 +00:00
|
|
|
"), "to get its total CPU time
|
2003-11-07 23:26:17 +00:00
|
|
|
(from the beginning of the work unit, not just since the last restart).
|
|
|
|
This excludes CPU time used to render graphics.
|
2003-09-05 21:26:21 +00:00
|
|
|
|
2003-08-19 06:44:58 +00:00
|
|
|
";
|
|
|
|
page_tail();
|
|
|
|
?>
|