How To: create your own work generator script (part 2)
The first part of this How To described the header of my modified work generator. This part will address the make_job() function used in the script to generate one job. This function is called from the main_loop() function.
The code starts with:
// create one new job
int make_job(const char* filename) {
DB_WORKUNIT wu;
char wu_name[256], dst_path[256], src_path[256];
const char* infiles[1];
int retval;
// make a unique name and move input file into download dir
sprintf(wu_name, "ostools_app_%d_%d", start_time, seqno++); // TODO: change this if you want to generate the jobname using the input file name
log_messages.printf(MSG_DEBUG,
"found input file %s and creating job %s\n", filename, wu_name
);
retval = config.download_path(filename, dst_path);
if (retval) return retval;
sprintf(src_path, "%s/%s", INPUT_FOLDER, filename);
log_messages.printf(MSG_DEBUG,
"move file from %s to %s\n", src_path, dst_path
);
retval = rename(src_path, dst_path);
if (retval) {
log_messages.printf(MSG_CRITICAL,
"rename: %d, errno is %d\n", retval, errno
);
return retval;
}
The parameter for this function is the filename of the input file determined by the main_loop. If you want to supply a second file you have to add a second parameter and add the code to move the second file too.
After defining some variables we’ll create a name for the job. This is done by concatenating a string with the start time of the generator and a sequential number for each job created. These variables are declared in the main() function
If you don’t want the job name based on the date and a sequence number you can provide your own algorithm to generate a unique name. But you must ensure yourself that this name is unique, BOINC has no such function and may behave unexpected if two jobs have the same name.
The next step is to get the download path where the input file sould be stored. This is done using the config.download_path() function. This determines the path of the input file according to the hierarchical storage setting. Then we’ll move the file to it’s new place using the rename() function. As you can see there is a critical log message if this operation fails. You should check the permissions on the source and target directory in this case.
// Fill in the job parameters
//
wu.clear();
wu.appid = app.id;
strcpy(wu.name, wu_name);
wu.rsc_fpops_est = 1e12;
wu.rsc_fpops_bound = 1e12;
wu.rsc_memory_bound = 1e8;
wu.rsc_disk_bound = 1e8;
wu.delay_bound = 86400;
wu.min_quorum = REPLICATION_FACTOR;
wu.target_nresults = REPLICATION_FACTOR;
wu.max_error_results = REPLICATION_FACTOR*2;
wu.max_total_results = REPLICATION_FACTOR*4;
wu.max_success_results = REPLICATION_FACTOR*2;
infiles[0] = filename;
// Register the job with BOINC
//
// TODO: change result template here if needed
return create_work(
wu,
wu_template,
"templates/ostools_result",
"../templates/ostools_result",
infiles,
1,
config
);
}
The last part of this function defines the values you can find in your workunit template (also called input template file). All these values can be found in the wiki (JobIn). The last thing you have to change is the desired result template (also called output template file) path and filename. The function create_work() then creates the needed database entries in the workunit and result tables.
Read the previous part of this How To: the header of the generator
Read the next parts of this How To: the main_loop() function and the main() function.
