int load_bpf_file(char *path) { int fd, i; Elf *elf; GElf_Ehdr ehdr; GElf_Shdr shdr, shdr_prog; Elf_Data *data, *data_prog, *symbols = NULL; char *shname, *shname_prog; if (elf_version(EV_CURRENT) == EV_NONE) return 1; fd = open(path, O_RDONLY, 0); if (fd < 0) return 1; elf = elf_begin(fd, ELF_C_READ, NULL); if (!elf) return 1; if (gelf_getehdr(elf, &ehdr) != &ehdr) return 1; /* scan over all elf sections to get license and map info */ for (i = 1; i < ehdr.e_shnum; i++) { if (get_sec(elf, i, &ehdr, &shname, &shdr, &data)) continue; if (0) printf("section %d:%s data %p size %zd link %d flags %d\n", i, shname, data->d_buf, data->d_size, shdr.sh_link, (int) shdr.sh_flags); } for (i = 1; i < ehdr.e_shnum; i++) { if (get_sec(elf, i, &ehdr, &shname, &shdr, &data)) continue; if (strcmp(shname, ".text") == 0){ insn_prog = (struct insn_prog *) data->d_buf; prog_size = data->d_size; if (0) printf("section name %s, data %p, size %d\n", shname, data->d_buf, data->d_size); } } close(fd); return 0; }
/* Usually called once every second, this function updates the * uptime.yaku TXT CHAOS RR in the local table. */ int uptime_refresh(void) { struct RRentry *uptimerr = NULL; char buffer[1024]; byte *encoded_uptime; int encoded_uptime_size; time_t uptime; uptimerr = local_search(YAKU_UPTIME_RR_NAME".", T_TXT, C_CHAOS, 0); if (uptimerr == NULL) { uptimerr = alloc_rr(YAKU_UPTIME_RR_NAME, T_TXT, C_CHAOS, 1); if (uptimerr == NULL) return -1; uptimerr->data[0] = 0; uptimerr->ttl = 0; local_add_entry(uptimerr); } uptime = get_sec() - ens_start; snprintf(buffer, 1024, "%ld days,%ld hours,%ld minutes,%ld seconds", uptime/86400, (uptime%86400)/3600, ((uptime%86400)%3600)/60, ((uptime%86400)%3600)%60); encoded_uptime = name_encode(buffer, &encoded_uptime_size, ','); if (encoded_uptime == NULL) return encoded_uptime_size; encoded_uptime_size--; free(uptimerr->data); uptimerr->data = encoded_uptime; uptimerr->size = encoded_uptime_size; return 0; }
// todo- make this non-shcon specific int _shcon_timed_out_msg (msg_t* _msg) { int tmp = 0; int ret = 0; int _cur_time = 0; if (_msg == NULL) { ERR_PRINT (_EPTRNULL); ret = -1; return ret; } tmp = _cur_time = get_sec (); if (tmp < 0) { ERR_FROM (); ret = tmp; return ret; } tmp = (_msg->hdr.timeout + _msg->hdr.date); ret = tmp < _cur_time; return ret; }
static int sprd_rtc_set_sec(unsigned long secs) { unsigned sec, min, hour, day; unsigned set_mask = 0, int_rsts; unsigned long temp; int i = 0; sec = secs % 60; temp = (secs - sec)/60; min = temp%60; temp = (temp - min)/60; hour = temp%24; temp = (temp - hour)/24; day = temp; sci_adi_set(ANA_RTC_INT_CLR, RTC_UPD_TIME_MASK); if(sec != get_sec()){ sci_adi_raw_write(ANA_RTC_SEC_UPDATE, sec); set_mask |= RTC_SEC_ACK_BIT; } if(min != get_min()){ sci_adi_raw_write(ANA_RTC_MIN_UPDATE, min); set_mask |= RTC_MIN_ACK_BIT; } if(hour != get_hour()){ sci_adi_raw_write(ANA_RTC_HOUR_UPDATE, hour); set_mask |= RTC_HOUR_ACK_BIT; } if(day != get_day()){ sci_adi_raw_write(ANA_RTC_DAY_UPDATE, day); set_mask |= RTC_DAY_ACK_BIT; } /* * wait till all update done */ do{ int_rsts = sci_adi_read(ANA_RTC_INT_RSTS) & RTC_UPD_TIME_MASK; if(set_mask == int_rsts) break; if(i < SPRD_RTC_SET_MAX){ msleep(1); i++; }else{ return 1; } }while(1); sci_adi_set(ANA_RTC_INT_CLR, RTC_UPD_TIME_MASK); return 0; }
void* handle_monster( void *a ) { usleep( WAIT ); while ( !is_hero_dead() ) { pos gallego_pos = get_hero_pos(), monster_pos = get_monster_pos(), next_pos = get_monster_pos(); maybe_monster_wants_stop(); search_hero( _monster_moviment_default, &gallego_pos, &monster_pos, &next_pos ); if ( gallego_pos.row == next_pos.row && gallego_pos.column == next_pos.column ) monster_catched(); if ( get_( next_pos.row, next_pos.column ) == BOSTA ) { score_up(); pisou_na_bosta(); veiudo.shited_sec = get_sec(); } if ( get_( next_pos.row, next_pos.column ) == TRAP ) { veiudo.wet_sec = get_sec(); veiudo.wet = 1; // vou por som de pisar no molhado que ficará na função move...junto com o monster.wav //if ( !get_rand( 15 ) ) // play_wet(); } // if ( get_sec() - veiudo.shited_sec == 2 || get_sec() - veiudo.shited_sec == -58 ) // veiudo.shited = 0; // a ser colocado no set.c! if ( get_sec() - veiudo.wet_sec == 2 || get_sec() - veiudo.wet_sec == -58 ) veiudo.wet = 0; move( next_pos ); usleep( DELAY ); } return NULL; }
static int alloc_pci_desc(struct iwl_drv *drv, struct iwl_firmware_pieces *pieces, enum iwl_ucode_type type) { int i; for (i = 0; i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i); i++) if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]), get_sec(pieces, type, i))) return -1; return 0; }
/* * for main thread */ int rq_push(int client_fd){ FIND_RQ(rq_queue_head, JOB_FREE); if(rq_queue_head->isjob != JOB_FREE) return -1; rq_queue_head->frontend->ffd = client_fd; rq_queue_head->frontend->ctime = get_sec() ; rq_queue_head->isjob = JOB_HAS; rq_queue_head = rq_queue_head->next; return 0; }
static unsigned long sprd_rtc_get_sec(void) { unsigned sec, min, hour, day; unsigned second = 0; sec = get_sec(); min = get_min(); hour = get_hour(); day = get_day(); second = ((((day*24) + hour)*60 + min)*60 + sec); return second; }
void sprd_rtc_set_sec(unsigned long secs) { unsigned sec, min, hour, day; unsigned set_mask = 0, int_rsts; unsigned long temp; sec = secs % 60; temp = (secs - sec)/60; min = temp%60; temp = (temp - min)/60; hour = temp%24; temp = (temp - hour)/24; day = temp; ANA_REG_OR(ANA_RTC_INT_CLR, RTC_UPD_TIME_MASK); if(sec != get_sec()){ ANA_REG_SET(ANA_RTC_SEC_UPDATE, sec); set_mask |= RTC_SEC_ACK_BIT; } if(min != get_min()){ ANA_REG_SET(ANA_RTC_MIN_UPDATE, min); set_mask |= RTC_MIN_ACK_BIT; } if(hour != get_hour()){ ANA_REG_SET(ANA_RTC_HOUR_UPDATE, hour); set_mask |= RTC_HOUR_ACK_BIT; } if(day != get_day()){ ANA_REG_SET(ANA_RTC_DAY_UPDATE, day); set_mask |= RTC_DAY_ACK_BIT; } //wait till all update done do{ int_rsts = ANA_REG_GET(ANA_RTC_INT_RSTS) & RTC_UPD_TIME_MASK; if(set_mask == int_rsts) break; }while(1); ANA_REG_OR(ANA_RTC_INT_CLR, RTC_UPD_TIME_MASK); return; }
unsigned long sprd_rtc_get_sec(void) { unsigned sec, min, hour, day; unsigned first = 0, second = 0; do { sec = get_sec(); min = get_min(); hour = get_hour(); day = get_day(); second = ((((day*24) + hour)*60 + min)*60 + sec); if((second - first) == 0) break; first = second; }while(1); return first; }
int load_bpf_file(char *path) { int fd, i; Elf *elf; GElf_Ehdr ehdr; GElf_Shdr shdr, shdr_prog; Elf_Data *data, *data_prog, *symbols = NULL; char *shname, *shname_prog; if (elf_version(EV_CURRENT) == EV_NONE) return 1; fd = open(path, O_RDONLY, 0); if (fd < 0) return 1; elf = elf_begin(fd, ELF_C_READ, NULL); if (!elf) return 1; if (gelf_getehdr(elf, &ehdr) != &ehdr) return 1; /* clear all kprobes */ i = system("echo \"\" > /sys/kernel/debug/tracing/kprobe_events"); /* scan over all elf sections to get license and map info */ for (i = 1; i < ehdr.e_shnum; i++) { if (get_sec(elf, i, &ehdr, &shname, &shdr, &data)) continue; if (0) /* helpful for llvm debugging */ printf("section %d:%s data %p size %zd link %d flags %d\n", i, shname, data->d_buf, data->d_size, shdr.sh_link, (int) shdr.sh_flags); if (strcmp(shname, "license") == 0) { processed_sec[i] = true; memcpy(license, data->d_buf, data->d_size); } else if (strcmp(shname, "version") == 0) { processed_sec[i] = true; if (data->d_size != sizeof(int)) { printf("invalid size of version section %zd\n", data->d_size); return 1; } memcpy(&kern_version, data->d_buf, sizeof(int)); } else if (strcmp(shname, "maps") == 0) { processed_sec[i] = true; if (load_maps(data->d_buf, data->d_size)) return 1; } else if (shdr.sh_type == SHT_SYMTAB) { symbols = data; } } /* load programs that need map fixup (relocations) */ for (i = 1; i < ehdr.e_shnum; i++) { if (get_sec(elf, i, &ehdr, &shname, &shdr, &data)) continue; if (shdr.sh_type == SHT_REL) { struct bpf_insn *insns; if (get_sec(elf, shdr.sh_info, &ehdr, &shname_prog, &shdr_prog, &data_prog)) continue; if (shdr_prog.sh_type != SHT_PROGBITS || !(shdr_prog.sh_flags & SHF_EXECINSTR)) continue; insns = (struct bpf_insn *) data_prog->d_buf; processed_sec[shdr.sh_info] = true; processed_sec[i] = true; if (parse_relo_and_apply(data, symbols, &shdr, insns)) continue; if (memcmp(shname_prog, "kprobe/", 7) == 0 || memcmp(shname_prog, "kretprobe/", 10) == 0 || memcmp(shname_prog, "tracepoint/", 11) == 0 || memcmp(shname_prog, "xdp", 3) == 0 || memcmp(shname_prog, "perf_event", 10) == 0 || memcmp(shname_prog, "socket", 6) == 0 || memcmp(shname_prog, "cgroup/", 7) == 0) load_and_attach(shname_prog, insns, data_prog->d_size); } } /* load programs that don't use maps */ for (i = 1; i < ehdr.e_shnum; i++) { if (processed_sec[i]) continue; if (get_sec(elf, i, &ehdr, &shname, &shdr, &data)) continue; if (memcmp(shname, "kprobe/", 7) == 0 || memcmp(shname, "kretprobe/", 10) == 0 || memcmp(shname, "tracepoint/", 11) == 0 || memcmp(shname, "xdp", 3) == 0 || memcmp(shname, "perf_event", 10) == 0 || memcmp(shname, "socket", 6) == 0 || memcmp(shname, "cgroup/", 7) == 0) load_and_attach(shname, data->d_buf, data->d_size); } close(fd); return 0; }
static void do_client(const char *server, short port, char *filename, afs_int32 command, afs_int32 times, afs_int32 bytes, afs_int32 sendbytes, afs_int32 readbytes, int dumpstats, int nojumbo, int maxmtu, int maxwsize, int minpeertimeout, int udpbufsz, int nostats, int hotthread, int threads) { struct rx_connection *conn; afs_uint32 addr; struct rx_securityClass *secureobj; int secureindex; int ret; char stamp[2048]; struct client_data *params; #ifdef AFS_PTHREAD_ENV int i; pthread_t thread[MAX_THREADS]; pthread_attr_t tattr; void *status; #endif params = calloc(1, sizeof(struct client_data)); #ifdef AFS_NT40_ENV if (afs_winsockInit() < 0) { printf("Can't initialize winsock.\n"); exit(1); } #endif if (hotthread) rx_EnableHotThread(); if (nostats) rx_enable_stats = 0; addr = str2addr(server); rx_SetUdpBufSize(udpbufsz); ret = rx_Init(0); if (ret) errx(1, "rx_Init failed"); if (nojumbo) rx_SetNoJumbo(); if (maxmtu) rx_SetMaxMTU(maxmtu); if (maxwsize) { rx_SetMaxReceiveWindow(maxwsize); rx_SetMaxSendWindow(maxwsize); } if (minpeertimeout) rx_SetMinPeerTimeout(minpeertimeout); get_sec(0, &secureobj, &secureindex); switch (command) { case RX_PERF_RPC: sprintf(stamp, "RPC: threads\t%d, times\t%d, write bytes\t%d, read bytes\t%d", threads, times, sendbytes, readbytes); break; case RX_PERF_RECV: sprintf(stamp, "RECV: threads\t%d, times\t%d, bytes\t%d", threads, times, bytes); break; case RX_PERF_SEND: sprintf(stamp, "SEND: threads\t%d, times\t%d, bytes\t%d", threads, times, bytes); break; case RX_PERF_FILE: sprintf(stamp, "FILE %s: threads\t%d, times\t%d, bytes\t%d", filename, threads, times, bytes); break; } conn = rx_NewConnection(addr, htons(port), RX_SERVER_ID, secureobj, secureindex); if (conn == NULL) errx(1, "failed to contact server"); #ifdef AFS_PTHREAD_ENV pthread_attr_init(&tattr); pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); #endif params->conn = conn; params->filename = filename; params->command = command; params->times = times; params->bytes = bytes; params->sendbytes = sendbytes; params->readbytes = readbytes; start_timer(); #ifdef AFS_PTHREAD_ENV for ( i=0; i<threads; i++) { pthread_create(&thread[i], &tattr, client_thread, params); if ( (i + 1) % RX_MAXCALLS == 0 ) { conn = rx_NewConnection(addr, htons(port), RX_SERVER_ID, secureobj, secureindex); if (conn != NULL) { struct client_data *new_params = malloc(sizeof(struct client_data)); memcpy(new_params, params, sizeof(struct client_data)); new_params->conn = conn; params = new_params; } } } #else client_thread(params); #endif #ifdef AFS_PTHREAD_ENV for ( i=0; i<threads; i++) pthread_join(thread[i], &status); #endif switch (command) { case RX_PERF_RPC: end_and_print_timer(stamp, (long long)threads*times*(sendbytes+readbytes)); break; case RX_PERF_RECV: case RX_PERF_SEND: case RX_PERF_FILE: end_and_print_timer(stamp, (long long)threads*times*bytes); break; } DBFPRINT(("done for good\n")); if (dumpstats) { rx_PrintStats(stdout); rx_PrintPeerStats(stdout, rx_PeerOf(conn)); } rx_Finalize(); #ifdef AFS_PTHREAD_ENV pthread_attr_destroy(&tattr); #endif free(params); }
static void do_server(short port, int nojumbo, int maxmtu, int maxwsize, int minpeertimeout, int udpbufsz, int nostats, int hotthread, int minprocs, int maxprocs) { struct rx_service *service; struct rx_securityClass *secureobj; int secureindex; int ret; #ifdef AFS_NT40_ENV if (afs_winsockInit() < 0) { printf("Can't initialize winsock.\n"); exit(1); } #endif if (hotthread) rx_EnableHotThread(); if (nostats) rx_enable_stats = 0; rx_SetUdpBufSize(udpbufsz); ret = rx_Init(htons(port)); if (ret) errx(1, "rx_Init failed"); if (nojumbo) rx_SetNoJumbo(); if (maxmtu) rx_SetMaxMTU(maxmtu); if (maxwsize) { rx_SetMaxReceiveWindow(maxwsize); rx_SetMaxSendWindow(maxwsize); } if (minpeertimeout) rx_SetMinPeerTimeout(minpeertimeout); get_sec(1, &secureobj, &secureindex); service = rx_NewService(0, RX_SERVER_ID, "rxperf", &secureobj, secureindex, rxperf_ExecuteRequest); if (service == NULL) errx(1, "Cant create server"); rx_SetMinProcs(service, minprocs); rx_SetMaxProcs(service, maxprocs); rx_SetCheckReach(service, 1); rx_StartServer(1); abort(); }
int main() { int n,looplim = 10000; while(cin >> n) { vMat all_Mat; Mat sec_Mat; cout << "=======" << endl; cout << n << endl; Mat L; double start_t = clock(); double ans = INF; double t3 = 0,t4 = 0; clock_t c1,c2; //step 0 vd ans_v; for(int i = 0 ; i < n ; i++) { vd tmpl,x; for(int j = 0 ; j < n ; j++) { if(i == j) {x.push_back(1);} else {x.push_back(0);} } if(get_f(x) <= ans) { ans = get_f(x); ans_v = x; } for(int j = 0 ; j < n ; j++) { if(x[j] == 1) { tmpl.push_back(get_f(x)); } else { tmpl.push_back(INF); } } L.push_back(tmpl); } int cnt = 0; vMat used_Mat;//,all_Mat; all_Mat.push_back(L); sec_Mat.push_back(get_sec(L)); multimap<double,Mat> dMatmp; set<pvdi> st; set<pdi> stf; vector<set<pdi> > vst(n); set<int> used_idx; st.insert(make_pair(get_diag(L),all_Mat.size()-1)); stf.insert(make_pair(L[0][0],all_Mat.size()-1)); priority_queue<pair<double,int> , vector<pair<double,int> > , greater<pair<double,int> > > pq; //priority_queue<pair<double,int> > pq; pq.push(make_pair(get_d(L),all_Mat.size()-1)); //O(min(loop,local min)) int max_set_size = 1000000; int cut_cnt = 0; while(cnt++ < looplim && !pq.empty()) { if(pq.size() > 1000000) break; if(cnt % 1000 == 0) { cout << "cnt:" << cnt << endl; cout << "lb:" << pq.top().first << endl; cout << "f:" << ans << endl; cout << "size:" << pq.size() << endl; cout << "cut:" << cut_cnt << endl; cout << "time:" << (clock() - start_t)/CLOCKS_PER_SEC << endl; cout << "---" << endl; } //step 1 //select l in Lk with the smallest d double d = pq.top().first; int idx = pq.top().second; pq.pop(); L = all_Mat[idx]; //print_Mat(L); //print_Mat(L); //cout << endl; if(used_idx.find(idx) != used_idx.end()){ continue; } if(ans - d < eps) { break; } vd xs; for(int i = 0 ; i < L.size() ; i++) { //caution : division by zero xs.push_back(d/L[i][i]); } //step 2 double tmpf = get_f(xs); //print_v(xs); //cout << get_f(xs) << endl; if(tmpf <= ans) { ans = tmpf; ans_v = xs; } vd lk; for(int i = 0 ; i < xs.size() ; i++) { if(xs[i] > zero_boundary) lk.push_back(tmpf/xs[i]); else lk.push_back(INF); } vMat Lm; vi idxs = get_lower_idx_s(st,lk); //vi idxs = get_lower_idx(st,lk,vst); //vi idxs = get_lower_idx_s(st,lk); Mat Sec; for(int i = 0 ; i < idxs.size() ; i++) { if(used_idx.find(idxs[i]) == used_idx.end()){ used_idx.insert(idxs[i]); Lm.push_back(all_Mat[idxs[i]]); Sec.push_back(sec_Mat[idxs[i]]); } } used_idx.insert(idx); //step 4 //O(L- size * n * n^2) vd dlk = lk; for(int j = 0 ; j < Lm.size() ; j++) { Mat tmpL = Lm[j]; vd tmplk = lk; //print_Mat(tmpL); //cout << endl; vi idx = get_swap_idx(tmplk,Sec[j]); /* cout << "s:" << endl; for(int i = 0 ; i < idx.size() ; i++) { cout << idx[i] << " "; } cout << endl; */ for(int i = 0 ; i < idx.size() ; i++) { L = tmpL; lk = tmplk; //print_Mat(L); swap(L[idx[i]],lk); //cout << "--" << endl; //print_v(Sec[j]); //cout << "v:" << is_valid_combination(L,Sec[j]) << " " << is_valid_combination(L) << endl; //if(get_d(L) > d) { all_Mat.push_back(L); sec_Mat.push_back(get_sec(L)); st.insert(make_pair(get_diag(L),all_Mat.size()-1)); stf.insert(make_pair(L[0][0],all_Mat.size()-1)); pq.push(make_pair(get_d(L),all_Mat.size()-1)); //} swap(L[idx[i]],lk); } } priority_queue<pair<double,int> , vector<pair<double,int> > , greater<pair<double,int> > > tmp_pq = pq; priority_queue<pair<double,int> , vector<pair<double,int> > , greater<pair<double,int> > > nxt_pq; int set_size = 0; while(!tmp_pq.empty()) { set_size++; int idx = tmp_pq.top().second; if(set_size < max_set_size) nxt_pq.push(tmp_pq.top()); else { st.erase(make_pair(get_diag(all_Mat[idx]),idx)); } tmp_pq.pop(); } pq = nxt_pq; } cout << "cnt:" << cnt << endl; cout << "ans:" << ans << endl; cout << "ans_v:"; print_v(ans_v); } return 0; }
double get_rate(clock_t diff, int byte) { return (double)(byte)/((double)(1<<20) * get_sec(diff)); }
int main(int argc, char **argv) { int block_size = 1024; int nloop = 1024; int num_thread = 2; int opt, ti; int test_id = 0; struct prog_arg prog_arg; struct thread_data *thread_data; size_t mem_size, a_block_size; int verbose = 0; double tb, te; long long cb, ce; while ((opt = getopt(argc, argv, "n:b:t:o:v")) != -1) { switch (opt) { case 'n': nloop = atoi(optarg); break; case 'b': block_size = atoi(optarg); break; case 't': num_thread = atoi(optarg); break; case 'o': { int i; for (i=0; i<NUM_BENCH; i++) { if (strcmp(bench_list[i].name, optarg) == 0) { test_id = i; break; } } if (i == NUM_BENCH) { printf("invalid test name : %s\n", optarg); usage(); } } break; case 'v': verbose = 1; break; default: usage(); break; } } thread_data = malloc(sizeof(*thread_data) * num_thread); a_block_size = ALIGN_UP(block_size, 64); prog_arg.block_size_op = block_size; prog_arg.block_size = a_block_size; prog_arg.nloop = nloop; prog_arg.nthread = num_thread; if (verbose) { printf("op=%s, nloop=%d, block_size=%d, num_thread=%d\n", bench_list[test_id].name, nloop, block_size, num_thread); } mem_size = a_block_size * num_thread; prog_arg.mem1 = memalign(64, mem_size); prog_arg.mem2 = memalign(64, mem_size); prog_arg.mem3 = memalign(64, mem_size); memset(prog_arg.mem1, 0xff, mem_size); memset(prog_arg.mem2, 0xff, mem_size); memset(prog_arg.mem3, 0xff, mem_size); if (bench_list[test_id].flags & SINGLE_THREAD) { bench_list[test_id].func(&prog_arg, NULL); } else { for (ti=0; ti<num_thread; ti++) { thread_data[ti].tid = ti; } tb = get_sec(); for (ti=0; ti<num_thread; ti++) { run_bench(&thread_data[ti], &bench_list[test_id], &prog_arg); } for (ti=0; ti<num_thread; ti++) { pthread_join(thread_data[ti].t, NULL); } te = get_sec(); bench_list[test_id].dump(&prog_arg, te-tb, 0); } }
int main() { struct sigaction sigIntHandler; sigIntHandler.sa_handler = my_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); const int ImageW=1000,ImageH=1000; cv::Mat m(ImageH,ImageW, CV_8UC3, cvScalar(255,255,255)); cv::Mat mr(ImageH,ImageW, CV_8UC3, cvScalar(255,255,255)); World w; w.tf = Pose(V2d(ImageW/2,ImageH/2),0,0.5); w.borderL = -700; w.borderT = 700; w.borderR = 700; w.borderB = -700; for(int i=0;i<NUMBER_OF_ROBOTS;i++){ Object::Ptr robot = Object::Ptr(new Robot(Pose(V2d(frand(w.borderL,w.borderR),frand(w.borderB,w.borderT)),0*d2r),ROBOT_SIZE)); robot->speed = V2d::polar(1.0*d2r,115); w.objects.push_back(robot); } for(int i=0;i<NUMBER_OF_PACKS;i++){ Object::Ptr pack = Object::Ptr(new Pack(Pose(V2d(frand(w.borderL,w.borderR),frand(w.borderB,w.borderT)),0*d2r),PACK_SIZE)); pack->speed = V2d::polar(1.0*d2r,400); w.objects.push_back(pack); } // {Object::Ptr pack = Object::Ptr(new Pack(Pose(V2d(0,0),70*d2r),PACK_SIZE)); // pack->speed = V2d::polar(0,385); // w.objects.push_back(pack);} // {Object::Ptr pack = Object::Ptr(new Pack(Pose(V2d(-51,2),0),PACK_SIZE)); // pack->speed = V2d::polar(0,385); // w.objects.push_back(pack);} int k=0; Time time; int duration = 15; long iterations=0; double last = get_sec(); while(k!=1310819 and k!=1048603){ iterations++; //waitKey(); w.save_state(); time = Time(duration); w.update(time); #ifdef VISUAL m.setTo(cv::Scalar(255,255,255)); rectangle(m,Point(w.tf.location.x+w.borderL*w.tf.scale,w.tf.location.y+w.borderT*w.tf.scale),Point(w.tf.location.x+w.borderR*w.tf.scale,w.tf.location.y+w.borderB*w.tf.scale),cvScalar(0,0,0)); w.draw(m); cv::flip(m,mr,0); cv::imshow("OK",mr); #endif k = cv::waitKey(duration); if(iterations%20==0){ double now = get_sec(); cout<<"\r"<<iterations<<":"<<1.0/((now-last)/20.0)<<"Hz "; cout.flush(); last = now; } if(k>0) cout<<"pressed: "<<k<<endl; } return 0; }
int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "usage: %s csr_matrix_file\n", argv[0]); exit(0); } int i, j, k; struct timespec start, end; int num_threads = 1; #pragma omp parallel { #pragma omp master { num_threads = omp_get_num_threads(); } } printf("Thread number: %d.\n", num_threads); #pragma omp parallel for for (i = 0; i < num_threads; i++) { int cpu = omp_get_thread_num(); thread_bind(cpu); } FILE *fp; struct csr_mat_t csr, csr_re, csr_t, csr_t_re, csr_t_t; struct blk_mat_t blk; struct csr_cont_t csr_h, csr_v; struct blk_cont_t blk_h, blk_t_h; read_csr_mat(argv[1], &csr); int rows = csr.rows; int cols = csr.cols; INT64 non_zeros = csr.non_zeros; csr_transpose(&csr, &csr_t); release_csr_mat(&csr); int *reorder_map = (int*)malloc(cols * sizeof(int)); csr_reorder(&csr_t, &csr_re, reorder_map); release_csr_mat(&csr_t); csr_transpose(&csr_re, &csr_t_t); release_csr_mat(&csr_re); split_csr_lb_nz(&csr_t_t, &csr_h, num_threads, SPLIT_HORIZON); release_csr_mat(&csr_t_t); csr_cont_to_blk_cont(&csr_h, &blk_h); release_csr_cont(&csr_h); printf("Notify: finished the preprocessing.\n"); FLOAT *x = (FLOAT*)numa_alloc(cols * sizeof(FLOAT)); FLOAT *y = (FLOAT*)numa_alloc(rows * sizeof(FLOAT)); for (i = 0; i < cols; i++) { x[i] = 1.0; } // warm up spmv_blks(&blk_h, x, y, NULL); printf("Notify: begin csr spmv.\n"); clock_gettime(CLOCK_MONOTONIC_RAW, &start); for (i = 0; i < LOOP_TIME; i++) { spmv_blks(&blk_h, x, y, NULL); } clock_gettime(CLOCK_MONOTONIC_RAW, &end); double time = get_sec(&start, &end) / LOOP_TIME; double gflops = 2.0 * non_zeros / time * 1e-9; printf("Notify: blk spmv time = %lfs, perf = %lf GFLOPS.\n", time, gflops); // result_file(y, rows); return 0; }