Changes between Initial Version and Version 1 of WorkGeneration


Ignore:
Timestamp:
Apr 18, 2007, 1:58:11 PM (17 years ago)
Author:
davea
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WorkGeneration

    v1 v1  
     1As described earlier, a workunit represents the inputs to a computation. The steps in creating a workunit are:
     2
     3    * Write XML 'template files' that describe the workunit and its corresponding results. Generally the same templates will be used for a large number work of workunits.
     4    * Create the workunit's input file(s) and place them in the download directory.
     5    * Invoke a BOINC function or script that creates a database record for the workunit.
     6
     7Once this is done, BOINC takes over: it creates one or more results for the workunit, distributes them to client hosts, collects the output files, finds a canonical result, assimilates the canonical result, and deletes files.
     8
     9During the testing phase of a project, you can use the make_work daemon to replicate a given workunit as needed to maintain a constant supply of work. This is useful while testing and debugging the application.
     10Workunit and result template files
     11
     12A workunit template file has the form
     13{{{
     14<file_info>
     15    <number>0</number>
     16    [ <sticky/>, other attributes]
     17</file_info>
     18[ ... ]
     19<workunit>
     20    <file_ref>
     21        <file_number>0</file_number>
     22        <open_name>NAME</open_name>
     23    </file_ref>
     24    [ ... ]
     25    [ <command_line>-flags xyz</command_line> ]
     26    [ <rsc_fpops_est>x</rsc_fpops_est> ]
     27    [ <rsc_fpops_bound>x</rsc_fpops_bound> ]
     28    [ <rsc_memory_bound>x</rsc_memory_bound> ]
     29    [ <rsc_disk_bound>x</rsc_disk_bound> ]
     30    [ <delay_bound>x</delay_bound> ]
     31    [ <min_quorum>x</min_quorum> ]
     32    [ <target_nresults>x</target_nresults> ]
     33    [ <max_error_results>x</max_error_results> ]
     34    [ <max_total_results>x</max_total_results> ]
     35    [ <max_success_results>x</max_success_results> ]
     36    [ <credit>X</credit> ]
     37</workunit>
     38}}}
     39The components are:
     40
     41 <file_info>, <file_ref>::
     42
     43        Each pair describes an input file and the way it's referenced.
     44
     45 <command_line>::
     46
     47        The command-line arguments to be passed to the main program.
     48
     49 <credit>::
     50
     51        The amount of credit to be granted for successful completion of this workunit. Use this only if you know in advance how many FLOPs it will take. Your validator must use get_credit_from_wu() as its compute_granted_credit() function.
     52Other elements  Work unit attributes
     53
     54Workunit database records include a field, 'xml_doc', that is an XML-format description of the workunit's input files. This is derived from the workunit template as follows:
     55
     56    * Within a <file_info> element, <number>x</number> identifies the order of the file. It is replaced with elements giving the filename, download URL, MD5 checksum, and size.
     57    * Within a <file_ref> element, <file_number>x</file_number> is replaced with an element giving the filename.
     58
     59A result template file has the form
     60{{{
     61<file_info>
     62    <name><OUTFILE_0/></name>
     63    <generated_locally/>
     64    <upload_when_present/>
     65    <max_nbytes>32768</max_nbytes>
     66    <url><UPLOAD_URL/></url>
     67</file_info>
     68<result>
     69    <file_ref>
     70        <file_name><OUTFILE_0/></file_name>
     71        <open_name>result.sah</open_name>
     72    </file_ref>
     73</result>
     74}}}
     75Result database records include a field, 'xml_doc_in', that is an XML-format description of the result's output files. This is derived from the result template as follows:
     76
     77    * <OUTFILE_n> is replaced with a string of the form 'wuname_resultnum_n' where wuname is the workunit name and resultnum is the ordinal number of the result (0, 1, ...).
     78    * <UPLOAD_URL/> is replaced with the upload URL.
     79
     80Moving input files to the download directory
     81If you're using a flat download directory, just put input files in that directory. If you're using hierarchical upload/download directories, you must put each input file in the appropriate directory; the directory is determined by the file's name. To find this directory, call the C++ function
     82{{{
     83dir_hier_path(
     84    const char* filename,
     85    const char* root,       // root of download directory
     86    int fanout,             // from config.xml
     87    char* result,           // path of file in hierarchy
     88    bool create_dir=false   // create dir if it's not there
     89);
     90}}}
     91If you're using scripts, you can invoke the program
     92{{{
     93dir_hier_path filename
     94}}}
     95It prints the full pathname and creates the directory if needed. Run this in the project's root directory. For example:
     96{{{
     97cp test_workunits/12ja04aa `bin/dir_hier_path 12ja04aa`
     98}}}
     99copies an input file from the test_workunits directory to the download directory hierarchy.
     100Creating workunit records
     101
     102Workunits can be created using either a script (using the create_work program) or a program (using the create_work() function). The input files must already be in the download hierarchy.
     103
     104The utility program is
     105{{{
     106create_work
     107    -appname name                       // application name
     108    -wu_name name                       // workunit name
     109    -wu_template filename               // WU template filename
     110        // relative to project root; usually in templates/
     111    -result_template filename           // result template filename
     112        // relative to project root; usually in templates/
     113    [ -batch n ]
     114    [ -priority n ]
     115
     116    // The following may be passed in the WU template,
     117    // or as command-line arguments to create_work,
     118    // or not passed at all (defaults will be used)
     119
     120    [ -command_line "-flags foo" ]
     121    [ -rsc_fpops_est x ]
     122    [ -rsc_fpops_bound x ]
     123    [ -rsc_memory_bound x ]
     124    [ -rsc_disk_bound x ]
     125    [ -delay_bound x ]
     126    [ -min_quorum x ]
     127    [ -target_nresults x ]
     128    [ -max_error_results x ]
     129    [ -max_total_results x ]
     130    [ -max_success_results x ]
     131    [ -additional_xml 'x' ]
     132
     133    infile_1 ... infile_m           // input files
     134}}}
     135The program must be run in the project root directory. The workunit parameters are documented here. The -additional_xml argument can be used to supply, for example, <credit>12.4</credit>.
     136
     137BOINC's library (backend_lib.C,h) provides the functions:
     138{{{
     139int create_work(
     140    DB_WORKUNIT&,
     141    const char* wu_template,                  // contents, not path
     142    const char* result_template_filename,     // relative to project root
     143    const char* result_template_filepath,     // absolute or relative to current dir
     144    const char** infiles,                     // array of input file names
     145    int ninfiles
     146    SCHED_CONFIG&,
     147    const char* command_line = NULL,
     148    const char* additional_xml = NULL
     149);
     150}}}
     151create_work() creates a workunit. The arguments are similar to those of the utility program; some of the information is passed in the DB_WORKUNIT structure, namely the following fields:
     152
     153name
     154appid
     155
     156The following may be passed either in the DB_WORKUNIT structure or in the workunit template file:
     157
     158rsc_fpops_est
     159rsc_fpops_bound
     160rsc_memory_bound
     161rsc_disk_bound
     162batch
     163delay_bound
     164min_quorum
     165target_nresults
     166max_error_results
     167max_total_results
     168max_success_results
     169
     170Examples
     171Making one workunit
     172
     173Here's a program that generates one workunit (error-checking is omitted for clarity):
     174{{{
     175#include "backend_lib.h"
     176
     177main() {
     178    DB_APP app;
     179    DB_WORKUNIT wu;
     180    char wu_template[LARGE_BLOB_SIZE];
     181    char* infiles[] = {"infile"};
     182
     183    SCHED_CONFIG config;
     184    config.parse_file();
     185
     186    boinc_db.open(config.db_name, config.db_host, config.db_passwd);
     187    app.lookup("where name='myappname'");
     188
     189    wu.clear();     // zeroes all fields
     190    wu.appid = app.id;
     191    wu.min_quorum = 2;
     192    wu.target_nresults = 2;
     193    wu.max_error_results = 5;
     194    wu.max_total_results = 5;
     195    wu.max_success_results = 5;
     196    wu.rsc_fpops_est = 1e10;
     197    wu.rsc_fpops_bound = 1e11;
     198    wu.rsc_memory_bound = 1e8;
     199    wu.rsc_disk_bound = 1e8;
     200    wu.delay_bound = 7*86400;
     201    read_filename("templates/wu_template.xml", wu_template, sizeof(wu_template));
     202    create_work(
     203        wu,
     204        wu_template,
     205        "templates/results_template.xml",
     206        "templates/results_template.xml",
     207        infiles,
     208        1,
     209        config
     210    );
     211}
     212}}}
     213This program must be run in the project directory since it expects to find the config.xml file in the current directory.
     214Making lots of workunits
     215
     216If you're making lots of workunits (e.g. to do the various parts of a parallel computation) you'll want the workunits to differ either in their input files, their command-line arguments, or both.
     217
     218For example, let's say you want to run a program on ten input files 'file0', 'file1', ..., 'file9'. You might modify the above program with the following code:
     219{{{
     220    char filename[256];
     221    char* infiles[1];
     222    infiles[0] = filename;
     223    ...
     224    for (i=0; i<10; i++) {
     225        sprintf(filename, "file%d", i);
     226        create_work(
     227            wu,
     228            wu_template,
     229            "templates/results_template.xml",
     230            "templates/results_template.xml",
     231            infiles,
     232            1,
     233            config
     234        );
     235    }
     236}}}
     237Note that you only need one workunit template file and one result template file.
     238
     239Now suppose you want to run a program against a single input file, but with ten command lines, '-flag 0', '-flag 1', ..., '-flag 9'. You might modify the above program with the following code:
     240{{{
     241    char command_line[256];
     242    ...
     243    for (i=0; i<10; i++) {
     244        sprintf(command_line, "-flag %d", i);
     245        create_work(
     246            wu,
     247            wu_template,
     248            "templates/results_template.xml",
     249            "templates/results_template.xml",
     250            infiles,
     251            1,
     252            config,
     253            command_line
     254        );
     255    }
     256}}}
     257Again, you only need one workunit template file and one result template file.