📄 sample_work_generator.c
字号:
{
for (i=0; i<dir_count; ++i)
{
free(folder_list[i]->name);
free(folder_list[i]);
}
free(folder_list); }
if (is_found == 0) { // execute the program and retrieve its result code; use generator 2500 to generate 2500 neurons strcpy(command, "cd .. && cd work"); strcat(command, work_gen_number); strcat(command, " && ../work"); strcat(command, work_gen_number); strcat(command, "/generator 0 && cd .. && cd bin"); result_code = system(command); if (result_code != 0) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "generator returned an error code (%d) during execution\n", result_code); exit(1); } // search for the generated file is_found = 0; strcpy(work_folder, "../work"); strcat(work_folder, work_gen_number); DirScanner scanner1(work_folder); while ((scanner1.scan(filename1)) && (is_found == 0)) { strcpy(file_id, ""); if (strstr(filename1.c_str(), ".xml") != NULL) { strncpy(file_id, (const char *)filename1.c_str(), 32); is_in_folder = 0; is_found = 1; } } if (is_found == 0) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "no database file was found\n", 0); exit(1); } } // make a unique name (for the job and its input file) //sprintf(job_name, "aisystem_%d_%d", start_time, seqno++); strcpy(job_name, ""); strcpy(job_name, file_id); job_name[33] = '\0'; int file_path_len = 0; strcpy(file_path, ""); strcpy(file_path, "/home/ovi/aisystem/work"); strcat(file_path, work_gen_number); if (is_in_folder == 1) { strcat(file_path, "/process/"); strcat(file_path, folder_short); } strcat(file_path, "/"); strcat(file_path, file_id); strcat(file_path, ".db"); if (is_in_folder == 1) file_path_len = 59 + strlen(work_gen_number) + 11 + 1; else file_path_len = 59 + strlen(work_gen_number) + 1; file_path[file_path_len] = '\0'; strcpy(file_name, ""); strcpy(file_name, file_id); strcat(file_name, ".db"); file_name[36] = '\0'; // Create the input file. // Put it at the right place in the download dir hierarchy retval = config.download_path(file_name, path); if (retval) return retval; // copy file to hierarchical directory strcpy(command, "cd .. && cp "); strcat(command, file_path); strcat(command, " `/home/ovi/aisystem/bin/dir_hier_path "); strcat(command, file_id); strcat(command, ".db` && cd bin"); result_code = system(command); if (result_code != 0) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "couldn't copy generated file to hierarchical directory, error code =%d\n", result_code); exit(1); } // Fill in the job parameters // wu.clear(); wu.appid = app.id; strcpy(wu.name, job_name); // // the following values are set in workunit file (i.e. aisystem_1.05_wu.xml) from templates folder; // if we set them in here the other settings prevail // //wu.rsc_fpops_est = 1e9; //wu.rsc_fpops_bound = 1e14; //wu.rsc_memory_bound = 1e8; //wu.rsc_disk_bound = 5e7; //wu.delay_bound = 500; //wu.min_quorum = REPLICATION_FACTOR; //wu.target_nresults = REPLICATION_FACTOR; //wu.max_error_results = REPLICATION_FACTOR*4; //wu.max_total_results = REPLICATION_FACTOR*8; //wu.max_success_results = REPLICATION_FACTOR*4; infiles[0] = file_name; // define just the file name without the path // we pass only the file id to the binary file (i.e. aisystem_100_linux_x86) so that the client will add the database extension .db and run the simulator for this file id strcpy(command_line, file_id); // Register the job with BOINC create_result = create_work( wu, wu_template, "templates/aisystem_1.05_re.xml", "../templates/aisystem_1.05_re.xml", infiles, 1, config, command_line ); strcpy(command, ""); strcat(command, "rm -f /home/ovi/aisystem/work"); strcat(command, work_gen_number); if (is_in_folder == 1) { strcat(command, "/process/"); strcat(command, folder_short); } strcat(command, "/"); strcat(command, file_id); strcat(command, ".db && rm -f /home/ovi/aisystem/work"); strcat(command, work_gen_number); if (is_in_folder == 1) { strcat(command, "/process/"); strcat(command, folder_short); } strcat(command, "/"); strcat(command, file_id); strcat(command, ".xml"); result_code = system(command); if (result_code != 0) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "couldn't delete generated db and xml files, error code =%d\n", result_code); exit(1); } return create_result;}void main_loop() { int retval; int count_time = 0; // we run only once check_stop_daemons(); int n = 0; count_time++; /* if (n==0) { // count_unsent_results() is in sched_util.C file count_time++; if (count_time > 7) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "count unsent results is 0\n", retval); exit(0); } } */ int njobs = (CUSHION-n)/REPLICATION_FACTOR; log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "Making %d jobs\n", njobs ); for (int i=0; i<njobs; i++) { retval = make_job(); if (retval) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "can't make job: %d\n", retval ); exit(retval); } } // Now sleep for a few seconds to let the transitioner // create instances for the jobs we just created. // Otherwise we could end up creating an excess of jobs. sleep(5);}int main(int argc, char** argv) { int i, retval; for (i=1; i<argc; i++) { if (!strcmp(argv[i], "-d")) { log_messages.set_debug_level(atoi(argv[++i])); } else if (!strcmp(argv[i], "-w")) { strcpy(work_gen_number, argv[++i]); } else { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "bad cmdline arg: %s", argv[i] ); } } if (config.parse_file("..")) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "can't read config file\n" ); exit(1); } retval = boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd); if (retval) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "can't open db\n"); exit(1); } if (app.lookup("where name='aisystem'")) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "can't find app\n"); exit(1); } if (read_file_malloc("../templates/aisystem_1.05_wu.xml", wu_template)) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "can't read WU template\n"); exit(1); } start_time = time(0); seqno = 0; log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL, "Start\n"); main_loop(); log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL, "End\n"); boinc_db.close();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -