int test_main(void){ int a=3, c; int b=-5; void *args1[3]; void *args2[3]; int tab[100]; int i,res; work_t *work1,*work2,*work3,*work4; int nb_threads = get_nb_threads(); printf("nb_threads= %d\n", nb_threads); args1[0] = &a; args1[1] = &b; work1 = create_work(2,args1,f1); for (i=0;i<100;i++) tab[i]=i; c=100; args2[0] = &c; args2[1] = tab; args2[2] = &res; work2 = create_work(3, args2, f2); work3 = create_work(4, args2, f2); work4 = create_work(5, args2, f2); submit_work(work1,0); submit_work(work2,1); submit_work(work3,1); submit_work(work4,1); terminate_thread_pool(); wait_work_completion(work1); wait_work_completion(work2); wait_work_completion(work3); wait_work_completion(work4); printf("res=%d\n",res); destroy_work(work1); destroy_work(work2); destroy_work(work3); destroy_work(work4); return 0; }
// 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(); }
void rename_wu_files() { int i, retval; char oldname[256],newname[1024]; unsigned long sz; DB_WORKUNIT db_wu; const char *name[1]; char *wudir="./wu_inbox"; xml_encoding encoding=(noencode?_binary:_x_setiathome); FILE *tmpfile; if (boinc_db.open(boinc_config.db_name,boinc_config.db_host,boinc_config.db_user,boinc_config.db_passwd)) { boinc_db.print_error("boinc_db.open"); log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Fatal error in boinc_db.open\n"); exit(1); } for (i=0;i<NSTRIPS;i++) { name[0]=wuheaders[i].name; sprintf(oldname,"%s/%s",wudir,name[0]); //sprintf(newname,"%s%s/%s",projectdir,WU_SUBDIR,name[0]); retval = dir_hier_path(name[0], boinc_config.download_dir, boinc_config.uldl_dir_fanout, newname, true ); if (retval) { char buf[1024]; log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"[%s] dir_hier_path() failed: %d\n", name[0], retval); exit(1); } struct stat sbuf; if (!stat(oldname,&sbuf) && (tmpfile=fopen(oldname,"a"))) { std::string tmpstr=xml_encode_string(bin_data[i],encoding); fprintf(tmpfile,"<data length=%ld encoding=\"%s\">",tmpstr.size(), xml_encoding_names[encoding]); fwrite(tmpstr.c_str(),tmpstr.size(),1,tmpfile); fprintf(tmpfile,"</data>\n"); fprintf(tmpfile,"</workunit>\n"); sz=bin_data[i].size(); fclose(tmpfile); } else { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Header file no longer exists! splitter start script may be failing\n "); exit(1); } if (!nodb) { if (!filecopy(oldname,newname)) { db_wu.clear(); db_wu.opaque=wuheaders[i].id; strncpy(db_wu.name,name[0],sizeof(db_wu.name)-2); db_wu.appid=app.id; //db_wu.rsc_fpops_est=2.79248e+13*6; //db_wu.rsc_fpops_bound=4.46797e+14*6; double beam=wuheaders[i].group_info->receiver_cfg->beam_width; double ar=wuheaders[i].group_info->data_desc.true_angle_range; double dur=(double)(wuheaders[i].group_info->data_desc.nsamples)/wuheaders[i].subband_desc.sample_rate; double min_slew=wuheaders[i].group_info->analysis_cfg->pot_min_slew; double max_slew=wuheaders[i].group_info->analysis_cfg->pot_max_slew; if ( ar <= beam ) { db_wu.rsc_fpops_est=9.193e+13; } else if ( ar <= ( dur*min_slew ) ) { db_wu.rsc_fpops_est=5.962e+13+2.296e+12/ar; } else if ( ar <= ( dur*max_slew ) ) { db_wu.rsc_fpops_est=5.749e+13+1.476e+13/ar; } else { db_wu.rsc_fpops_est=3.535e+13; } db_wu.rsc_fpops_est*=(0.333/wuheaders[i].group_info->analysis_cfg->chirp_resolution); db_wu.rsc_fpops_bound=db_wu.rsc_fpops_est*10; db_wu.rsc_memory_bound=33554432; db_wu.rsc_disk_bound=33554432; // Our minimum is a 40 MFLOP machine db_wu.delay_bound=std::max(86400.0*7,db_wu.rsc_fpops_est/4e+7); db_wu.min_quorum=sah_config.min_quorum; db_wu.target_nresults=sah_config.target_nresults; db_wu.max_error_results=sah_config.max_error_results; db_wu.max_total_results=sah_config.max_total_results; db_wu.max_success_results=sah_config.max_success_results; strncpy(db_wu.app_name,appname,sizeof(db_wu.app_name)-2); if (create_work(db_wu, wu_template, result_template_filename, result_template_filepath, name, 1, boinc_config, NULL ) ) { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"create work failed\n"); exit(1); } //unlink(oldname); // we now *always* unlink } else { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"file copy failed\n"); exit(1); } unlink(oldname); } } 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; }
inline thread_state set_thread_state( thread_id_type const& thrd, thread_state_enum new_state, thread_state_ex_enum new_state_ex, thread_priority priority, std::size_t thread_num, error_code& ec) { if (HPX_UNLIKELY(!thrd)) { HPX_THROWS_IF(ec, null_thread_id, "threads::detail::set_thread_state", "NULL thread id encountered"); return thread_state(unknown); } // set_state can't be used to force a thread into active state if (new_state == threads::active) { std::ostringstream strm; strm << "invalid new state: " << get_thread_state_name(new_state); HPX_THROWS_IF(ec, bad_parameter, "threads::detail::set_thread_state", strm.str()); return thread_state(unknown); } // we know that the id is actually the pointer to the thread if (!thrd) { if (&ec != &throws) ec = make_success_code(); return thread_state(terminated); // this thread has already been terminated } thread_state previous_state; do { // action depends on the current state previous_state = thrd->get_state(); thread_state_enum previous_state_val = previous_state; // nothing to do here if the state doesn't change if (new_state == previous_state_val) { LTM_(warning) << "set_thread_state: old thread state is the same as new " "thread state, aborting state change, thread(" << thrd.get() << "), description(" << thrd->get_description() << "), new state(" << get_thread_state_name(new_state) << ")"; if (&ec != &throws) ec = make_success_code(); return thread_state(new_state); } // the thread to set the state for is currently running, so we // schedule another thread to execute the pending set_state switch (previous_state_val) { case active: { // schedule a new thread to set the state LTM_(warning) << "set_thread_state: thread is currently active, scheduling " "new thread, thread(" << thrd.get() << "), description(" << thrd->get_description() << "), new state(" << get_thread_state_name(new_state) << ")"; thread_init_data data( boost::bind(&set_active_state, thrd, new_state, new_state_ex, priority, previous_state), "set state for active thread", 0, priority); create_work(thrd->get_scheduler_base(), data, pending, ec); if (&ec != &throws) ec = make_success_code(); return previous_state; // done } break; case terminated: { LTM_(warning) << "set_thread_state: thread is terminated, aborting state " "change, thread(" << thrd.get() << "), description(" << thrd->get_description() << "), new state(" << get_thread_state_name(new_state) << ")"; if (&ec != &throws) ec = make_success_code(); // If the thread has been terminated while this set_state was // pending nothing has to be done anymore. return previous_state; } break; case pending: if (suspended == new_state) { // we do not allow explicit resetting of a state to suspended // without the thread being executed. std::ostringstream strm; strm << "set_thread_state: invalid new state, can't demote a " "pending thread, " << "thread(" << thrd.get() << "), description(" << thrd->get_description() << "), new state(" << get_thread_state_name(new_state) << ")"; LTM_(fatal) << strm.str(); HPX_THROWS_IF(ec, bad_parameter, "threads::detail::set_thread_state", strm.str()); return thread_state(unknown); } break; case suspended: break; // fine, just set the new state default: HPX_ASSERT(false); // should not happen break; } // If the previous state was pending we are supposed to remove the // thread from the queue. But in order to avoid linearly looking // through the queue we defer this to the thread function, which // at some point will ignore this thread by simply skipping it // (if it's not pending anymore). LTM_(info) << "set_thread_state: thread(" << thrd.get() << "), " "description(" << thrd->get_description() << "), " "new state(" << get_thread_state_name(new_state) << "), " "old state(" << get_thread_state_name(previous_state_val) << ")"; // So all what we do here is to set the new state. if (thrd->restore_state(new_state, previous_state)) { thrd->set_state_ex(new_state_ex); break; } // state has changed since we fetched it from the thread, retry LTM_(error) << "set_thread_state: state has been changed since it was fetched, " "retrying, thread(" << thrd.get() << "), " "description(" << thrd->get_description() << "), " "new state(" << get_thread_state_name(new_state) << "), " "old state(" << get_thread_state_name(previous_state_val) << ")"; } while (true); if (new_state == pending) { // REVIEW: Passing a specific target thread may interfere with the // round robin queuing. thrd->get_scheduler_base()->schedule_thread(thrd.get(), thread_num, priority); thrd->get_scheduler_base()->do_some_work(thread_num); } if (&ec != &throws) ec = make_success_code(); return previous_state; }
int main(int argc, char **argv) { int i, j; int color; int val, longindex; int pcs[16]; int wdl_only = 0; #ifdef SUICIDE int switched = 0; #endif numthreads = 1; do { // val = getopt_long(argc, argv, "t:lwc", options, &longindex); val = getopt_long(argc, argv, "t:ld", options, &longindex); switch (val) { case 't': numthreads = atoi(optarg); break; case 'l': log = 1; break; case 'w': wdl_only = 1; break; case 'd': use_envdirs = 1; break; } } while (val != EOF); if (optind >= argc) { fprintf(stderr, "No tablebase specified.\n"); exit(1); } tablename = argv[optind]; init_tablebases(); for (i = 0; i < 16; i++) pcs[i] = 0; numpcs = strlen(tablename) - 1; color = 0; j = 0; for (i = 0; i < strlen(tablename); i++) switch (tablename[i]) { case 'P': pcs[PAWN | color]++; pt[j++] = PAWN | color; break; case 'N': pcs[KNIGHT | color]++; pt[j++] = KNIGHT | color; break; case 'B': pcs[BISHOP | color]++; pt[j++] = BISHOP | color; break; case 'R': pcs[ROOK | color]++; pt[j++] = ROOK | color; break; case 'Q': pcs[QUEEN | color]++; pt[j++] = QUEEN | color; break; case 'K': pcs[KING | color]++; pt[j++] = KING | color; break; case 'v': if (color) exit(1); color = 0x08; break; default: exit(1); } if (!color) exit(1); if (pcs[WPAWN] || pcs[BPAWN]) { fprintf(stderr, "Can't handle pawns.\n"); exit(1); } if (numthreads < 1) numthreads = 1; else if (numthreads > MAX_THREADS) numthreads = MAX_THREADS; printf("number of threads = %d\n", numthreads); if (numthreads == 1) total_work = 1; else total_work = 100 + 10 * numthreads; for (i = 0; i < numpcs; i++) { shift[i] = (numpcs - i - 1) * 6; mask[i] = 0x3fULL << shift[i]; } #ifndef SMALL size = 10ULL << (6 * (numpcs-1)); #else size = 462ULL << (6 * (numpcs-2)); mask[0] = 0x1ffULL << shift[1]; #endif work_g = create_work(total_work, size, 0x3f); #ifndef SMALL work_piv = create_work(total_work, 1ULL << shift[0], 0); #else work_piv0 = create_work(total_work, 1ULL << shift[0], 0); work_piv1 = create_work(total_work, 10ULL << shift[1], 0); #endif static int piece_order[16] = { 0, 0, 3, 5, 7, 9, 1, 0, 0, 0, 4, 6, 8, 10, 2, 0 }; #ifdef SUICIDE j = pt[0]; for (i = 1; i < numpcs; i++) if (piece_order[pt[i]] < piece_order[j]) j = pt[i]; if (j & 0x08) { for (i = 0; i < numpcs; i++) pt[i] ^= 0x08; for (i = 0; i < 8; i++) { int tmp = pcs[i]; pcs[i] = pcs[i + 8]; pcs[i + 8] = tmp; } switched = 1; } #endif for (i = 0; i < numpcs; i++) for (j = i + 1; j < numpcs; j++) if (piece_order[pt[i]] > piece_order[pt[j]]) { int tmp = pt[i]; pt[i] = pt[j]; pt[j] = tmp; } for (i = 0, j = 0; i < numpcs; i++) if (!(pt[i] & 0x08)) white_pcs[j++] = i; white_pcs[j] = -1; for (i = 0, j = 0; i < numpcs; i++) if (pt[i] & 0x08) black_pcs[j++] = i; black_pcs[j] = -1; idx_mask1[numpcs - 1] = 0xffffffffffffffc0ULL; idx_mask2[numpcs - 1] = 0; for (i = numpcs - 2; i >= 0; i--) { idx_mask1[i] = idx_mask1[i + 1] << 6; idx_mask2[i] = (idx_mask2[i + 1] << 6) | 0x3f; } #ifndef SUICIDE for (i = 0; i < numpcs; i++) if (pt[i] == WKING) white_king = i; for (i = 0; i < numpcs; i++) if (pt[i] == BKING) black_king = i; #endif table_w = alloc_huge(2 * size); table_b = table_w + size; printf("Verifying %s.\n", tablename); if (log) { L = fopen(LOGFILE, "a"); fprintf(L, "Verifying %s...", tablename); fflush(L); } init_threads(0); init_tables(); gettimeofday(&start_time, NULL); cur_time = start_time; printf("Initialising broken positions.\n"); run_threaded(calc_broken, work_g, 1); printf("Calculating white captures.\n"); calc_captures_w(); printf("Calculating black captures.\n"); calc_captures_b(); #ifndef SUICIDE printf("Calculating mate positions.\n"); run_threaded(calc_mates, work_g, 1); #else init_capt_threat(); printf("Calculating white threats.\n"); iter_table = table_b; iter_table_opp = table_w; iter_pcs_opp = white_pcs; run_threaded(calc_threats, work_g, 1); printf("Calculating black threats.\n"); iter_table = table_w; iter_table_opp = table_b; iter_pcs_opp = black_pcs; run_threaded(calc_threats, work_g, 1); #endif decomp_init_piece(pcs); // open wdl table struct tb_handle *H = open_tb(tablename, 1); decomp_init_table(H); load_entry = (struct TBEntry_piece *)get_entry(H); if (!wdl_only) { // white, wdl printf("Loading wdl, white.\n"); tb_table = decompress_table(H, 0, 0); set_perm(H, 0, 0, tb_perm, pt); load_table = table_w; load_bside = 0; run_threaded(load_wdl, work_g, 1); // black, wdl printf("Loading wdl, black.\n"); tb_table = decompress_table(H, 1, 0); set_perm(H, 1, 0, tb_perm, pt); load_table = table_b; load_bside = 1; run_threaded(load_wdl, work_g, 1); close_tb(H); // open dtz table H = open_tb(tablename, 0); decomp_init_table(H); load_entry = (struct TBEntry_piece *)get_entry(H); ply_accurate_win = get_ply_accurate_win(H, 0); ply_accurate_loss = get_ply_accurate_loss(H, 0); load_map = get_dtz_map(H, 0); int dtz_side = get_dtz_side(H, 0); init_wdl_dtz(); // dtz printf("Loading dtz, %s.\n" , dtz_side == 0 ? "white" : "black"); tb_table = decompress_table(H, 0, 0); set_perm(H, 0, 0, tb_perm, pt); load_table = dtz_side == 0 ? table_w : table_b; load_bside = 0; if (load_map) run_threaded(load_dtz_mapped, work_g, 1); else run_threaded(load_dtz, work_g, 1); close_tb(H); if (dtz_side == 0) { load_table = table_w; load_opp_table = table_b; load_pieces = white_pcs; load_opp_pieces = black_pcs; } else { load_table = table_b; load_opp_table = table_w; load_pieces = black_pcs; load_opp_pieces = white_pcs; } printf("Verifying %s.\n", dtz_side ? "white" : "black"); run_threaded(verify_opp, work_g, 1); printf("Verifying %s.\n", dtz_side ? "black" : "white"); run_threaded(verify_dtz, work_g, 1); } else { // currently broken (and disabled) // white, wdl printf("Loading wdl, white.\n"); tb_table = decompress_table(H, 0, 0); set_perm(H, 0, 0, tb_perm, pt); load_table = table_w; load_bside = 0; run_threaded(wdl_load_wdl, work_g, 1); // black, wdl printf("Loading wdl, black.\n"); tb_table = decompress_table(H, 1, 0); set_perm(H, 1, 0, tb_perm, pt); load_table = table_b; load_bside = 1; run_threaded(wdl_load_wdl, work_g, 1); close_tb(H); ply_accurate_win = get_ply_accurate_win(H, 0); ply_accurate_loss = get_ply_accurate_loss(H, 0); init_wdl(); load_table = table_w; load_opp_table = table_b; load_pieces = white_pcs; printf("Verifying white.\n"); run_threaded(verify_wdl, work_g, 1); ply_accurate_win = get_ply_accurate_loss(H, 0); ply_accurate_loss = get_ply_accurate_win(H, 0); init_wdl(); load_table = table_b; load_opp_table = table_w; load_pieces = black_pcs; printf("Verifying black.\n"); run_threaded(verify_wdl, work_g, 1); } if (num_errors == 0) { printf("No errors.\n"); if (log) fprintf(L, " No errors.\n"); } if (log) fclose(L); return 0; }