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>
|
2002-07-31 05:59:43 +00:00
|
|
|
The BOINC API is a set of C++ functions.
|
|
|
|
Unless otherwise specified,
|
|
|
|
the functions return an integer error code; zero indicates success.
|
2003-06-15 20:28:30 +00:00
|
|
|
On an error return, the application should exit with that status.
|
2003-10-13 19:23:40 +00:00
|
|
|
The BOINC graphics API is described <a href=graphics.php>separately</a>.
|
2002-07-30 18:06:39 +00:00
|
|
|
|
|
|
|
<h3>Initialization and termination</h3>
|
2002-07-31 05:59:43 +00:00
|
|
|
The application must call
|
2002-07-30 18:06:39 +00:00
|
|
|
<pre>
|
2003-11-07 23:26:17 +00:00
|
|
|
int boinc_init(bool standalone=false);
|
2002-07-30 18:06:39 +00:00
|
|
|
</pre>
|
|
|
|
before calling other BOINC functions or doing I/O.
|
2003-11-07 23:26:17 +00:00
|
|
|
If <code>standalone</code> is true,
|
|
|
|
the application will function independently of the BOINC core client
|
|
|
|
(this is useful for testing).
|
2002-08-05 00:29:34 +00:00
|
|
|
<p>
|
|
|
|
When the application has completed it must call
|
2002-07-30 18:06:39 +00:00
|
|
|
<pre>
|
2002-08-05 00:29:34 +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
|
|
|
|
<pre>
|
|
|
|
int boinc_resolve_filename(char *logical_name, string& physical_name);
|
2002-07-30 18:06:39 +00:00
|
|
|
</pre>
|
|
|
|
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
|
|
|
|
<pre>
|
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\");
|
2002-07-30 18:06:39 +00:00
|
|
|
</pre>
|
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
|
|
|
|
|
|
|
<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>
|
|
|
|
bool boinc_time_to_checkpoint();
|
|
|
|
</pre>
|
|
|
|
whenever it reaches a point where it is able to checkpoint.
|
|
|
|
If this returns true,
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
<pre>
|
|
|
|
int boinc_get_init_data(APP_INIT_DATA&);
|
|
|
|
|
|
|
|
struct APP_INIT_DATA {
|
|
|
|
char project_preferences[4096];
|
|
|
|
char user_name[256];
|
|
|
|
char team_name[256];
|
|
|
|
double user_total_credit;
|
|
|
|
double user_expavg_credit;
|
|
|
|
double team_total_credit;
|
|
|
|
double team_expavg_credit;
|
|
|
|
};
|
|
|
|
</pre>
|
|
|
|
to get the following information:
|
|
|
|
";
|
|
|
|
list_start();
|
|
|
|
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.");
|
|
|
|
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.");
|
|
|
|
list_end();
|
|
|
|
echo "
|
|
|
|
<p>
|
2003-09-07 03:11:03 +00:00
|
|
|
An application may call
|
2003-09-05 21:26:21 +00:00
|
|
|
<pre>
|
2003-11-07 23:26:17 +00:00
|
|
|
int boinc_wu_cpu_time(double &cpu_time);
|
2003-09-05 21:26:21 +00:00
|
|
|
</pre>
|
|
|
|
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
|
|
|
|
2004-01-04 06:48:40 +00:00
|
|
|
<h3>Trickle messages</h3>
|
|
|
|
The application may send a <a href=trickle.php>trickle message</a> using
|
|
|
|
<pre>
|
|
|
|
int boinc_trickle(char* p);
|
|
|
|
</pre>
|
2002-07-30 18:06:39 +00:00
|
|
|
<h3>Multi-program applications</h3>
|
|
|
|
Some applications consist of multiple programs:
|
|
|
|
a <b>main program</b> that acts as coordinator,
|
|
|
|
and one or more subsidiary programs.
|
2002-08-05 00:29:34 +00:00
|
|
|
Each program should use the BOINC API as described above.
|
2002-07-30 18:06:39 +00:00
|
|
|
<p>
|
2002-08-05 00:29:34 +00:00
|
|
|
Each program should have its own state file;
|
2002-07-30 18:06:39 +00:00
|
|
|
the state file of the coordinator program records
|
|
|
|
which subsidiary program was last active.
|
|
|
|
<p>
|
2002-08-05 00:29:34 +00:00
|
|
|
To correctly implement fraction done,
|
2002-07-30 18:06:39 +00:00
|
|
|
the main program should pass information to subsidiary programs
|
2002-08-05 00:29:34 +00:00
|
|
|
(perhaps as command-line arguments) indicating the starting and ending
|
2002-07-30 18:06:39 +00:00
|
|
|
fractions for that program.
|
2002-07-31 05:59:43 +00:00
|
|
|
<p>
|
|
|
|
The coordinator must call
|
|
|
|
<pre>
|
2002-08-05 00:29:34 +00:00
|
|
|
void boinc_child_start();
|
2002-07-31 05:59:43 +00:00
|
|
|
</pre>
|
|
|
|
prior to forking a child process.
|
|
|
|
When the child is done, the coordinator
|
|
|
|
must get the child's CPU time, then call
|
|
|
|
<pre>
|
2002-08-05 00:29:34 +00:00
|
|
|
void boinc_child_done(double total_cpu);
|
2002-07-31 05:59:43 +00:00
|
|
|
</pre>
|
|
|
|
before forking the next child process.
|
2003-08-19 06:44:58 +00:00
|
|
|
";
|
|
|
|
page_tail();
|
|
|
|
?>
|