JOB_DESC() { wu.clear(); command_line = NULL; assign_flag = false; assign_multi = false; strcpy(result_template_file, ""); strcpy(additional_xml, ""); assign_id = 0; assign_type = ASSIGN_NONE; // defaults (in case they're not in WU template) // wu.id = 0; wu.min_quorum = 2; wu.target_nresults = 2; wu.max_error_results = 3; wu.max_total_results = 10; wu.max_success_results = 6; wu.rsc_fpops_est = 3600e9; wu.rsc_fpops_bound = 86400e9; wu.rsc_memory_bound = 5e8; wu.rsc_disk_bound = 1e9; wu.rsc_bandwidth_bound = 0.0; wu.delay_bound = 7*86400; }
JOB_DESC() { wu.clear(); command_line = NULL; assign_flag = false; assign_multi = false; strcpy(wu_template_file, ""); strcpy(result_template_file, ""); assign_id = 0; assign_type = ASSIGN_NONE; // defaults (in case they're not in WU template) // wu.id = 0; wu.min_quorum = DEFAULT_MIN_QUORUM; wu.target_nresults = DEFAULT_TARGET_NRESULTS; wu.max_error_results = DEFAULT_MAX_ERROR_RESULTS; wu.max_total_results = DEFAULT_MAX_TOTAL_RESULTS; wu.max_success_results = DEFAULT_MAX_SUCCESS_RESULTS; wu.rsc_fpops_est = DEFAULT_RSC_FPOPS_EST; wu.rsc_fpops_bound = DEFAULT_RSC_FPOPS_BOUND; wu.rsc_memory_bound = DEFAULT_RSC_MEMORY_BOUND; wu.rsc_disk_bound = DEFAULT_RSC_DISK_BOUND; wu.rsc_bandwidth_bound = 0.0; // Not used wu.delay_bound = DEFAULT_DELAY_BOUND; }
int main_loop(APP& app) { DB_WORKUNIT wu; DB_RESULT canonical_result, result; char buf[256]; char buf2[256]; int retval; task_t task; while(1) { check_stop_daemons(); sprintf(buf, "where appid=%d and assimilate_state=%d", app.id, ASSIMILATE_READY); // Заполнение полей текущего ворк юнита retval = wu.enumerate(buf); if (retval) { if (retval != ERR_DB_NOT_FOUND) { log_messages.printf(MSG_DEBUG, "DB connection lost, exiting\n"); exit(0); } } // Заполнение полей текущего задания sscanf(wu.name, "%[^_]_%[^_]_%d_%*d_%d", task.app_name, task.name, &task.timestamp, &task.size); // Создание списка результатов задания vector<RESULT> results; if (strlen(task.name) > 0) { sprintf(buf, "INNER JOIN workunit ON result.id = workunit.canonical_resultid WHERE workunit.name like \"%%_%s_%%\" and workunit.assimilate_state=%d", task.name, ASSIMILATE_READY); while (!result.enumerate(buf)) { results.push_back(result); } } // Склеивание заданий if ((results.size() == task.size) && (task.size != 0)) { log_messages.printf(MSG_NORMAL,"[%s] Assimilating task\n", task.name); retval = rmerge(task, results); if (retval) { log_messages.printf(MSG_CRITICAL,"[%s] Assimilation failed\n", task.name); } else { // Обновление записей в базе if (update_db) { sprintf(buf, "assimilate_state=%d, transition_time=%d", ASSIMILATE_DONE, (int)time(0)); sprintf(buf2, "appid=%d and assimilate_state=%d and name like \"%%_%s_%%\"", app.id, ASSIMILATE_READY, task.name); wu.update_fields_noid(buf, buf2); boinc_db.commit_transaction(); } log_messages.printf(MSG_NORMAL,"[%s] Task assimilated\n", task.name); //Очистка всех структур wu.clear(); memset(&task, 0, sizeof(task)); results.clear(); } } sleep(SLEEP_INTERVAL); } }
// create one new job // int make_job(int node,int sub_node) { DB_WORKUNIT wu; char name[256], path[MAXPATHLEN]; const char* infiles[2]; int retval; // make a unique name (for the job and its input file) // sprintf(name, "%s_%d_%d_%d", app_name,start_time, node,sub_node); // Create the input file. // Put it at the right place in the download dir hierarchy // retval = config.download_path(name, path); if (retval) return retval; FILE* f = fopen(path, "w"); if (!f) return ERR_FOPEN; //no:of vertices node_to_work fprintf(f,"%d %d %d\n",n1,node,sub_node); fclose(f); // Fill in the job parameters // wu.clear(); wu.appid = app.id; strcpy(wu.name, name); wu.rsc_fpops_est = n1*1e10; wu.rsc_fpops_bound = 1e24; wu.rsc_memory_bound = 1e8; wu.rsc_disk_bound = 1e8; wu.delay_bound = 30*n1; 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] = name; infiles[1] = graphs; // Register the job with BOINC // sprintf(path, "templates/%s", out_template_file); return create_work( wu, in_template, path, config.project_path(path), infiles, 2, config ); }
int main(int argc, const char** argv) { DB_APP app; DB_WORKUNIT wu; int retval; char wu_template[BLOB_SIZE]; char wu_template_file[256], result_template_file[256], result_template_path[1024]; const char* command_line=NULL; const char** infiles = NULL; int i, ninfiles; char download_dir[256], db_name[256], db_passwd[256]; char db_user[256],db_host[256]; char buf[256]; char additional_xml[256]; bool assign_flag = false; bool assign_multi = false; int assign_id = 0; int assign_type; strcpy(result_template_file, ""); strcpy(app.name, ""); strcpy(db_passwd, ""); strcpy(additional_xml, ""); const char* config_dir = 0; i = 1; ninfiles = 0; wu.clear(); // defaults (in case they're not in WU template) wu.id = 0; wu.min_quorum = 2; wu.target_nresults = 2; wu.max_error_results = 3; wu.max_total_results = 10; wu.max_success_results = 6; wu.rsc_fpops_est = 3600e9; wu.rsc_fpops_bound = 86400e9; wu.rsc_memory_bound = 5e8; wu.rsc_disk_bound = 1e9; wu.rsc_bandwidth_bound = 0.0; wu.delay_bound = 7*86400; while (i < argc) { if (arg(argv, i, "appname")) { strcpy(app.name, argv[++i]); } else if (arg(argv, i, "wu_name")) { strcpy(wu.name, argv[++i]); } else if (arg(argv, i, "wu_template")) { strcpy(wu_template_file, argv[++i]); } else if (arg(argv, i, "result_template")) { strcpy(result_template_file, argv[++i]); } else if (arg(argv, i, "batch")) { wu.batch = atoi(argv[++i]); } else if (arg(argv, i, "config_dir")) { config_dir = argv[++i]; } else if (arg(argv, i, "batch")) { wu.batch = atoi(argv[++i]); } else if (arg(argv, i, "priority")) { wu.priority = atoi(argv[++i]); } else if (arg(argv, i, "rsc_fpops_est")) { wu.rsc_fpops_est = atof(argv[++i]); } else if (arg(argv, i, "rsc_fpops_bound")) { wu.rsc_fpops_bound = atof(argv[++i]); } else if (arg(argv, i, "rsc_memory_bound")) { wu.rsc_memory_bound = atof(argv[++i]); } else if (arg(argv, i, "rsc_disk_bound")) { wu.rsc_disk_bound = atof(argv[++i]); } else if (arg(argv, i, "delay_bound")) { wu.delay_bound = atoi(argv[++i]); } else if (arg(argv, i, "min_quorum")) { wu.min_quorum = atoi(argv[++i]); } else if (arg(argv, i, "target_nresults")) { wu.target_nresults = atoi(argv[++i]); } else if (arg(argv, i, "max_error_results")) { wu.max_error_results = atoi(argv[++i]); } else if (arg(argv, i, "max_total_results")) { wu.max_total_results = atoi(argv[++i]); } else if (arg(argv, i, "max_success_results")) { wu.max_success_results = atoi(argv[++i]); } else if (arg(argv, i, "opaque")) { wu.opaque = atoi(argv[++i]); } else if (arg(argv, i, "command_line")) { command_line= argv[++i]; } else if (arg(argv, i, "additional_xml")) { strcpy(additional_xml, argv[++i]); } else if (arg(argv, i, "wu_id")) { wu.id = atoi(argv[++i]); } else if (arg(argv, i, "assign_all")) { assign_multi = true; assign_flag = true; assign_type = ASSIGN_NONE; } else if (arg(argv, i, "assign_host")) { assign_flag = true; assign_type = ASSIGN_HOST; assign_id = atoi(argv[++i]); } else if (arg(argv, i, "assign_user_one")) { assign_flag = true; assign_type = ASSIGN_USER; assign_id = atoi(argv[++i]); } else if (arg(argv, i, "assign_user_all")) { assign_flag = true; assign_type = ASSIGN_USER; assign_multi = true; assign_id = atoi(argv[++i]); } else if (arg(argv, i, "assign_team_one")) { assign_flag = true; assign_type = ASSIGN_TEAM; assign_id = atoi(argv[++i]); } else if (arg(argv, i, "assign_team_all")) { assign_flag = true; assign_type = ASSIGN_TEAM; assign_multi = true; assign_id = atoi(argv[++i]); } else { if (!strncmp("-", argv[i], 1)) { fprintf(stderr, "create_work: bad argument '%s'\n", argv[i]); exit(1); } infiles = argv+i; ninfiles = argc - i; break; } i++; } #define CHKARG(x,m) do { if (!(x)) { fprintf(stderr, "create_work: bad command line: "m"\n"); exit(1); } } while (0) #define CHKARG_STR(v,m) CHKARG(strlen(v),m) CHKARG_STR(app.name , "need --appname"); CHKARG_STR(wu.name , "need --wu_name"); CHKARG_STR(wu_template_file , "need --wu_template"); CHKARG_STR(result_template_file , "need --result_template"); #undef CHKARG #undef CHKARG_STR if (assign_flag) { if (!strstr(wu.name, ASSIGNED_WU_STR)) { fprintf(stderr, "Assigned WU names must contain '%s'\n", ASSIGNED_WU_STR ); exit(1); } } retval = config.parse_file(); if (retval) { fprintf(stderr, "Can't parse config file: %d\n", retval); exit(1); } else { strcpy(db_name, config.db_name); strcpy(db_passwd, config.db_passwd); strcpy(db_user, config.db_user); strcpy(db_host, config.db_host); strcpy(download_dir, config.download_dir); } retval = boinc_db.open(db_name, db_host, db_user, db_passwd); if (retval) { fprintf(stderr, "create_work: error opening database: %d\n", retval ); exit(1); } sprintf(buf, "where name='%s'", app.name); retval = app.lookup(buf); if (retval) { fprintf(stderr, "create_work: app not found\n"); exit(1); } retval = read_filename(wu_template_file, wu_template, sizeof(wu_template)); if (retval) { fprintf(stderr, "create_work: can't open WU template: %d\n", retval); exit(1); } wu.appid = app.id; strcpy(result_template_path, "./"); strcat(result_template_path, result_template_file); retval = create_work( wu, wu_template, result_template_file, result_template_path, const_cast<const char **>(infiles), ninfiles, config, command_line, additional_xml ); if (retval) { fprintf(stderr, "create_work: %d\n", retval); exit(1); } if (assign_flag) { DB_ASSIGNMENT assignment; assignment.clear(); assignment.create_time = time(0); assignment.target_id = assign_id; assignment.target_type = assign_type; assignment.multi = assign_multi; assignment.workunitid = wu.id; retval = assignment.insert(); if (retval) { fprintf(stderr, "assignment.insert() failed: %d\n", retval); exit(1); } } boinc_db.close(); }
int main(int argc, const char** argv) { DB_APP app; DB_WORKUNIT wu; int retval; char wu_template[BLOB_SIZE]; char wu_template_file[256], result_template_file[256], result_template_path[MAXPATHLEN]; const char* command_line=NULL; const char** infiles = NULL; int i, ninfiles; char download_dir[256], db_name[256], db_passwd[256]; char db_user[256],db_host[256]; char buf[256]; char additional_xml[256]; bool show_wu_name = true; bool assign_flag = false; bool assign_multi = false; int assign_id = 0; int assign_type = ASSIGN_NONE; strcpy(wu_template_file, ""); strcpy(result_template_file, ""); strcpy(app.name, ""); strcpy(db_passwd, ""); strcpy(additional_xml, ""); const char* config_dir = 0; i = 1; ninfiles = 0; wu.clear(); // defaults (in case they're not in WU template) wu.id = 0; wu.min_quorum = 2; wu.target_nresults = 2; wu.max_error_results = 3; wu.max_total_results = 10; wu.max_success_results = 6; wu.rsc_fpops_est = 3600e9; wu.rsc_fpops_bound = 86400e9; wu.rsc_memory_bound = 5e8; wu.rsc_disk_bound = 1e9; wu.rsc_bandwidth_bound = 0.0; wu.delay_bound = 7*86400; while (i < argc) { if (arg(argv, i, "appname")) { strcpy(app.name, argv[++i]); } else if (arg(argv, i, "d")) { int dl = atoi(argv[++i]); log_messages.set_debug_level(dl); if (dl ==4) g_print_queries = true; } else if (arg(argv, i, "wu_name")) { show_wu_name = false; strcpy(wu.name, argv[++i]); } else if (arg(argv, i, "wu_template")) { strcpy(wu_template_file, argv[++i]); } else if (arg(argv, i, "result_template")) { strcpy(result_template_file, argv[++i]); } else if (arg(argv, i, "batch")) { wu.batch = atoi(argv[++i]); } else if (arg(argv, i, "config_dir")) { config_dir = argv[++i]; } else if (arg(argv, i, "batch")) { wu.batch = atoi(argv[++i]); } else if (arg(argv, i, "priority")) { wu.priority = atoi(argv[++i]); } else if (arg(argv, i, "rsc_fpops_est")) { wu.rsc_fpops_est = atof(argv[++i]); } else if (arg(argv, i, "rsc_fpops_bound")) { wu.rsc_fpops_bound = atof(argv[++i]); } else if (arg(argv, i, "rsc_memory_bound")) { wu.rsc_memory_bound = atof(argv[++i]); } else if (arg(argv, i, "rsc_disk_bound")) { wu.rsc_disk_bound = atof(argv[++i]); } else if (arg(argv, i, "delay_bound")) { wu.delay_bound = atoi(argv[++i]); } else if (arg(argv, i, "min_quorum")) { wu.min_quorum = atoi(argv[++i]); } else if (arg(argv, i, "target_nresults")) { wu.target_nresults = atoi(argv[++i]); } else if (arg(argv, i, "max_error_results")) { wu.max_error_results = atoi(argv[++i]); } else if (arg(argv, i, "max_total_results")) { wu.max_total_results = atoi(argv[++i]); } else if (arg(argv, i, "max_success_results")) { wu.max_success_results = atoi(argv[++i]); } else if (arg(argv, i, "opaque")) { wu.opaque = atoi(argv[++i]); } else if (arg(argv, i, "command_line")) { command_line= argv[++i]; } else if (arg(argv, i, "additional_xml")) { strcpy(additional_xml, argv[++i]); } else if (arg(argv, i, "wu_id")) { wu.id = atoi(argv[++i]); } else if (arg(argv, i, "broadcast")) { assign_multi = true; assign_flag = true; assign_type = ASSIGN_NONE; } else if (arg(argv, i, "broadcast_user")) { assign_flag = true; assign_type = ASSIGN_USER; assign_multi = true; assign_id = atoi(argv[++i]); } else if (arg(argv, i, "broadcast_team")) { assign_flag = true; assign_type = ASSIGN_TEAM; assign_multi = true; assign_id = atoi(argv[++i]); } else if (arg(argv, i, "target_host")) { assign_flag = true; assign_type = ASSIGN_HOST; assign_id = atoi(argv[++i]); } else if (arg(argv, i, "target_user")) { assign_flag = true; assign_type = ASSIGN_USER; assign_id = atoi(argv[++i]); } else if (arg(argv, i, "target_team")) { assign_flag = true; assign_type = ASSIGN_TEAM; assign_id = atoi(argv[++i]); } else if (arg(argv, i, "help")) { usage(); exit(0); } else { if (!strncmp("-", argv[i], 1)) { fprintf(stderr, "create_work: bad argument '%s'\n", argv[i]); exit(1); } infiles = argv+i; ninfiles = argc - i; break; } i++; } if (!strlen(app.name)) { usage(); } if (!strlen(wu.name)) { sprintf(wu.name, "%s_%d_%f", app.name, getpid(), dtime()); } if (!strlen(wu_template_file)) { sprintf(wu_template_file, "templates/%s_in", app.name); } if (!strlen(result_template_file)) { sprintf(result_template_file, "templates/%s_out", app.name); } retval = config.parse_file(config_dir); if (retval) { fprintf(stderr, "Can't parse config file: %s\n", boincerror(retval)); exit(1); } else { strcpy(db_name, config.db_name); strcpy(db_passwd, config.db_passwd); strcpy(db_user, config.db_user); strcpy(db_host, config.db_host); strcpy(download_dir, config.download_dir); } retval = boinc_db.open(db_name, db_host, db_user, db_passwd); if (retval) { fprintf(stderr, "create_work: error opening database: %s\n", boincerror(retval) ); exit(1); } sprintf(buf, "where name='%s'", app.name); retval = app.lookup(buf); if (retval) { fprintf(stderr, "create_work: app not found\n"); exit(1); } retval = read_filename(wu_template_file, wu_template, sizeof(wu_template)); if (retval) { fprintf(stderr, "create_work: can't open input template %s\n", wu_template_file ); exit(1); } wu.appid = app.id; strcpy(result_template_path, "./"); strcat(result_template_path, result_template_file); retval = create_work( wu, wu_template, result_template_file, result_template_path, const_cast<const char **>(infiles), ninfiles, config, command_line, additional_xml ); if (retval) { fprintf(stderr, "create_work: %s\n", boincerror(retval)); exit(1); } else { if (show_wu_name) { printf("workunit name: %s\n", wu.name); } } if (assign_flag) { DB_ASSIGNMENT assignment; assignment.clear(); assignment.create_time = time(0); assignment.target_id = assign_id; assignment.target_type = assign_type; assignment.multi = assign_multi; assignment.workunitid = wu.id; retval = assignment.insert(); if (retval) { fprintf(stderr, "assignment.insert() failed: %s\n", boincerror(retval) ); exit(1); } sprintf(buf, "transitioner_flags=%d", assign_multi?TRANSITION_NONE:TRANSITION_NO_NEW_RESULTS ); retval = wu.update_field(buf); if (retval) { fprintf(stderr, "wu.update() failed: %s\n", boincerror(retval)); exit(1); } } boinc_db.close(); }
int make_job(struct jobstruct job) { DB_APP app; DB_WORKUNIT wu; char* wu_template; const char *infiles[3]; char *path; char additional_xml[512]; log_messages.printf(MSG_DEBUG, "Making files\n"); // write input file in the download directory // infiles[0] = job.nameligand; infiles[1] = job.namereceptor; infiles[2] = job.confname; char path_ligand[1024]; char path_receptor[1024]; char path_conf[1024]; int retval; config.download_path(job.nameligand, path_ligand); retval = createFile(path_ligand, job.pdbligand); if (retval) { fprintf(stderr, "error making input data\n"); exit(1); } config.download_path(job.namereceptor, path_receptor); retval = createFile(path_receptor, job.pdbreceptor); if (retval) { fprintf(stderr, "error making input data\n"); exit(1); } config.download_path(job.confname, path_conf); retval = createFile(path_conf, job.pdbconf); if (retval) { fprintf(stderr, "error making input data\n"); exit(1); } log_messages.printf(MSG_DEBUG, "Done making files\n"); wu.clear(); // zeroes all fields if (!strlen(wu.name)) { /*sprintf(wu.name, "%s_%d_%f-%s-%s-%s-%s-%s-", app_name, getpid(), dtime(), job.idreceptor, job.namereceptor, job.idligand, job.nameligand, job.experiment);*/ sprintf(wu.name, "%s_%s_%s_%s", app_name, job.idligand, job.idreceptor, job.experiment); } char buff[256]; sprintf(buff, "where name='%s'", app_name); retval = app.lookup(buff); if (retval) { fprintf(stderr, "create_work: app not found\n"); exit(1); } wu.appid = app.id; wu.id = 0; wu.min_quorum = 1; wu.target_nresults = 1; wu.max_error_results = 1; wu.max_total_results = 5; wu.max_success_results = 1; wu.rsc_disk_bound = 150000000; wu.rsc_bandwidth_bound = 0.0; double value = calcValue(job.pdbligand, job.pdbreceptor); std::cout << value << std::endl; double credit = CREDIT_CORRECTOR * value; double fpops_est = FPOPS_CORRECTOR * value; wu.rsc_fpops_est = fpops_est; wu.rsc_fpops_bound = fpops_est * fpops_est; if (credit > 500) { wu.delay_bound = 21 * 86400; } else if (credit > 150) { wu.delay_bound = 14 * 86400; } else { wu.delay_bound = 7 * 86400; } //sprintf(additional_xml, "<credit>%f</credit>\n", credit); sprintf(additional_xml, "<credit>%f</credit>\n<command_line>--ligand ligand --receptor receptor --config conf --rligand %s --rreceptor %s --cpu 1</command_line>", credit, job.nameligand, job.namereceptor); log_messages.printf(MSG_DEBUG, "Start create_work()\n"); create_work(wu, in_template, "templates/vina_result.xml", "../templates/vina_result.xml", infiles, 3, config, NULL, additional_xml); log_messages.printf(MSG_DEBUG, "Done create_work()\n"); return 0; }
int main_loop(APP& app) { DB_WORKUNIT wu; DB_RESULT canonical_result, result; DB_APP_VERSION app_version; // http://boinc.berkeley.edu/doxygen/server/html/classDB__APP__VERSION.html char buf[256]; char buf2[256]; int retval; task_t task; while(1) { check_stop_daemons(); sprintf(buf, "WHERE appid=%d AND assimilate_state=%d AND error_mask<>16", app.id, ASSIMILATE_READY); // Заполнение полей текущего ворк юнита retval = wu.enumerate(buf); if (retval) { if (retval != ERR_DB_NOT_FOUND) { log_messages.printf(MSG_DEBUG, "DB connection lost, exiting\n"); exit(0); } } // Заполнение полей текущего задания sscanf(wu.name, "%[^_]_%d_%d_%[^_]_%d_%*d_%d.%[^_]", task.app_name, &task.id, &task.uid, task.name, &task.timestamp, &task.size, task.extension); sprintf(buf, "SELECT login FROM user WHERE id=%d", task.uid); mysql_query(frontend_db, buf); mysql_result = mysql_store_result(frontend_db); if ((row = mysql_fetch_row(mysql_result)) != NULL) { strcpy(task.login, row[0]); } // Создание списка результатов задания vector<RESULT> results; if (strlen(task.name) > 0) { sprintf(buf, "INNER JOIN workunit ON result.id = workunit.canonical_resultid WHERE workunit.name like \"%%_%d_%d_%s_%%\" and workunit.assimilate_state=%d and workunit.error_mask<>16", task.id, task.uid, task.name, ASSIMILATE_READY); while (!result.enumerate(buf)) { results.push_back(result); } } // Склеивание заданий if ((results.size() == task.size) && (task.size != 0)) { log_messages.printf(MSG_NORMAL,"[%d_%s] Assimilating task\n", task.uid, task.name); retval = handle_result(task, results); if (retval) { log_messages.printf(MSG_CRITICAL,"[%d_%s] Assimilation failed\n", task.uid, task.name); } else { // Обновление записей в базе if (update_db) { sprintf(buf, "assimilate_state=%d, transition_time=%d", ASSIMILATE_DONE, (int)time(0)); sprintf(buf2, "appid=%d and assimilate_state=%d and name like \"%%_%d_%d_%s_%%\"", app.id, ASSIMILATE_READY, task.id, task.uid, task.name); wu.update_fields_noid(buf, buf2); boinc_db.commit_transaction(); // Обновление планктона update_plankton(task, app_version); update_plankton_percent(results, task); } log_messages.printf(MSG_NORMAL,"[%d_%s] Task assimilated\n", task.uid, task.name); //Очистка всех структур wu.clear(); memset(&task, 0, sizeof(task)); results.clear(); } } else { if (results.size()) { update_plankton_percent(results, task); } } sleep(SLEEP_INTERVAL); } }