Changes between Initial Version and Version 1 of BasicApi


Ignore:
Timestamp:
Apr 19, 2007, 9:55:57 PM (17 years ago)
Author:
KSMarksPsych
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BasicApi

    v1 v1  
     1= The BOINC application programming interface (API) =
     2       
     3
     4The 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. Unless otherwise specified, the functions return an integer error code; zero indicates success.
     5
     6BOINC applications may generate graphics, allowing them to provide a screensaver. This API is described [GraphicsApi here].
     7
     8BOINC applications may consist of several programs that are executed in sequence; these are called compound applications. This API is described [http://boinc.berkeley.edu/compound_app.php here].
     9
     10== Initialization and termination ==
     11
     12Applications should [http://boinc.berkeley.edu/diagnostics.php initialize diagnostics] before any other BOINC calls.
     13
     14Initialization for graphical and compound applications are described elsewhere (see links above). Other applications must call
     15
     16{{{
     17int boinc_init();
     18}}}
     19
     20before calling other BOINC functions or doing I/O.
     21
     22When the application has completed it must call
     23
     24{{{
     25int boinc_finish(int status);
     26}}}
     27
     28`status` is nonzero if an error was encountered. This call does not return.
     29
     30== Is your application running under the control of the BOINC client? ==
     31
     32BOINC applications can be run in "standalone" mode for testing, or under the control of the BOINC client. You might want your application to behave differently in the two cases. For example you might want to output debugging information if the application is running standalone. To determine if the application is running in standalone mode or under the control of the BOINC client, call
     33
     34{{{
     35int boinc_is_standalone(void);
     36}}}
     37
     38This returns non-zero (True) if the application is running standalone, and zero (False) if the application is running under the control of the BOINC client.
     39
     40== Resolving file names ==
     41
     42Applications that use named input or output files must call
     43
     44{{{
     45int boinc_resolve_filename(char *logical_name, char *physical_name, int len);
     46}}}
     47
     48or
     49
     50{{{
     51int boinc_resolve_filename_s(char *logical_name, std::string& physical_name);
     52}}}
     53
     54to convert logical file names to physical names. For example, instead of
     55
     56{{{
     57f = fopen("my_file", "r");
     58}}}
     59
     60the application might use
     61
     62{{{
     63string resolved_name;
     64retval = boinc_resolve_filename("my_file", resolved_name);
     65if (retval) fail("can't resolve filename");
     66f = fopen(resolved_name.c_str(), "r");
     67}}}
     68
     69`boinc_resolve_filename()` doesn't need to be used for temporary files.
     70
     71== I/O wrappers ==
     72
     73Applications should replace fopen() calls with
     74
     75{{{
     76boinc_fopen(char* path, char* mode);
     77}}}
     78
     79This 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; it also sets the 'close-on-exec' flag.
     80
     81== Checkpointing ==
     82
     83Computations 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 '''checkpointing'''. 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.
     84
     85Frequency of checkpointing is a user preference (e.g. laptop users might want to checkpoint infrequently). An application must call
     86
     87{{{
     88int boinc_time_to_checkpoint();
     89}}}
     90
     91whenever it reaches a point where it is able to checkpoint. If this returns nonzero (True) then the application should checkpoint immediately (i.e., write the state file and flush all output files), then call
     92
     93{{{
     94void boinc_checkpoint_completed();
     95}}}
     96
     97`boinc_time_to_checkpoint()` is fast, so it can be called frequently (hundreds or thousands of times a second).
     98
     99== Critical sections ==
     100
     101{{{
     102void boinc_begin_critical_section();
     103void boinc_end_critical_section();
     104}}}
     105
     106Call these around code segments during which you don't want to be suspended or killed by the core client. NOTE: this is done automatically while checkpointing.
     107
     108== Atomic file update ==
     109
     110To facilitate atomic checkpoint, an application can write to output and state files using the MFILE class.
     111
     112{{{
     113class MFILE {
     114public:
     115    int open(char* path, char* mode);
     116    int _putchar(char);
     117    int puts(char*);
     118    int printf(char* format, ...);
     119    size_t write(const void* buf, size_t size, size_t nitems);
     120    int close();
     121    int flush();
     122};
     123}}}
     124
     125MFILE buffers data in memory and writes to disk only on `flush()` or `close()`. This lets you write output files and state files more or less atomically.
     126
     127== Credit reporting ==
     128
     129By 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. 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.
     130
     131{{{
     132void boinc_ops_per_cpu_second(double floating_point_ops, double integer_ops);
     133}}}
     134
     135This reports the results of an application-specific benchmark, expressed as number of floating-point and integer operations per CPU second.
     136
     137{{{
     138void boinc_ops_cumulative(double floating_point_ops, double integer_ops);
     139}}}
     140
     141This reports the total number of floating-point and integer operations since the start of the result. It must be called just before boinc_finish(), and optionally at intermediate points.
     142
     143== Communicating with the core client ==
     144
     145The core client GUI displays the percent done of workunits in progress. To keep this display current, an application should periodically call
     146
     147{{{
     148boinc_fraction_done(double fraction_done);
     149}}}
     150
     151The `fraction_done` argument is an estimate of the workunit fraction complete (0 to 1). This function is fast and can be called frequently. The sequence of arguments in successive calls should be non-decreasing. An application should never 'reset' and start over if an error occurs; it should exit with an error code.
     152
     153{{{
     154double boinc_get_fraction_done();
     155}}}
     156
     157returns the last value set, or -1 if none has been set (this would typically be called from graphics code).
     158
     159The following functions get information from the core client; this information may be useful for graphics.
     160
     161{{{
     162int boinc_get_init_data_p(APP_INIT_DATA*);
     163int boinc_get_init_data(APP_INIT_DATA&);
     164
     165struct APP_INIT_DATA {
     166    int major_version;
     167    int minor_version;
     168    int release;
     169    int app_version;
     170    char app_name[256];
     171    char symstore[256];
     172    char acct_mgr_url[256];
     173    char* project_preferences;
     174    int userid;
     175    int teamid;
     176    int hostid;
     177    char user_name[256];
     178    char team_name[256];
     179    char project_dir[256];
     180    char boinc_dir[256];
     181    char wu_name[256];
     182    char authenticator[256];
     183    int slot;
     184    double user_total_credit;
     185    double user_expavg_credit;
     186    double host_total_credit;
     187    double host_expavg_credit;
     188    double resource_share_fraction;
     189    HOST_INFO host_info;
     190    PROXY_INFO proxy_info;  // in case app wants to use network
     191    GLOBAL_PREFS global_prefs;
     192
     193    // info about the WU
     194    double rsc_fpops_est;
     195    double rsc_fpops_bound;
     196    double rsc_memory_bound;
     197    double rsc_disk_bound;
     198
     199    // the following are used for compound apps,
     200    // where each stage of the computation is a fixed
     201    // fraction of the total.
     202    double fraction_done_start;
     203    double fraction_done_end;
     204};
     205}}}
     206
     207to get the following information:
     208
     209||'''core version'''||The version number of the core client||
     210||'''app_name'''||The application name (from the server's DB||
     211||'''project_preferences'''||An XML string containing the user's project-specific preferences.||
     212||'''user_name'''||The user's 'screen name' on this project.||
     213||'''team_name'''||The user's team name, if any.||
     214||'''project_dir'''||Absolute path of project directory||
     215||'''boinc_dir'''||Absolute path of BOINC root directory||
     216||'''wu_name'''||Name of workunit being processed||
     217||'''authenticator'''||User's authenticator for this project||
     218||'''slot'''||The number of the app's 'slot' (0, 1, ...)||
     219||'''user_total_credit'''||User's total work for this project.||
     220||'''user_expavg_credit'''||User's recent average work per day.||
     221||'''team_total_credit'''||Team's total work for this project.||
     222||'''team_expavg_credit'''||Team's recent average work per day.||
     223||'''host_info'''||A structure describing the host hardware and OS||
     224
     225An application may call
     226
     227{{{
     228int boinc_wu_cpu_time(double &cpu_time);
     229}}}
     230
     231to get its total CPU time (from the beginning of the work unit, not just since the last restart). This excludes CPU time used to render graphics.
     232
     233== Requesting network connection ==
     234
     235If it appears that there is no physical network connection (e.g. gethostbyname() fails for a valid name) then
     236
     237    * Call `boinc_need_network()`. This will alert the user that a network connection is needed.
     238    * Periodically call boinc_network_poll() until it returns zero.
     239    * Do whatever communication is needed.
     240    * When done, call `boinc_network_done()`. This enables that hangup of a modem connection, if needed.
     241
     242{{{
     243void boinc_need_network();
     244int boinc_network_poll();
     245void boinc_network_done();
     246}}}
     247
     248Note: this should be enclosed in `boinc_not_using_cpu() ... boinc_using_cpu()`.