void *cuckoo_thread(void *arg) { int i; int id = *((int *) (arg)); int tot_val_sum = 0; red_printf("Thread %d: Starting lookups\n", id); struct timespec start, end; while(1) { clock_gettime(CLOCK_REALTIME, &start); for(i = 0; i < NUM_KEYS; i += BATCH_SIZE) { tot_val_sum += process_batch(&keys[i]); } clock_gettime(CLOCK_REALTIME, &end); double seconds = (end.tv_sec - start.tv_sec) + (double) (end.tv_nsec - start.tv_nsec) / 1000000000; red_printf("Thread ID: %d, Rate = %.2f M/s. Value sum = %d\n", id, NUM_KEYS / (seconds * 1000000), tot_val_sum); } }
void mpi_process_group::receive_batch(process_id_type source, outgoing_messages& new_messages) const { impl_->free_sent_batches(); if(!impl_->processing_batches) { // increase the number of received batches ++impl_->number_received_batches[source]; // and receive the batch impl::incoming_messages& incoming = impl_->incoming[source]; typedef std::vector<impl::message_header>::iterator iterator; iterator end = new_messages.headers.end(); for (iterator i = new_messages.headers.begin(); i != end; ++i) { incoming.headers.push_back(*i); incoming.headers.back().offset = incoming.buffer.size(); incoming.buffer.insert(incoming.buffer.end(), &new_messages.buffer[i->offset], &new_messages.buffer[i->offset] + i->bytes); } // Set up the iterators pointing to the next header in each block for (std::size_t i = 0; i < incoming.next_header.size(); ++i) incoming.next_header[i] = incoming.headers.begin(); #ifndef NO_IMMEDIATE_PROCESSING process_batch(source); #endif } else { #ifdef DEBUG std::cerr << "Pushing incoming message batch onto queue since we are already processing a batch.\n"; #endif // use swap to avoid copying impl_->new_batches.push(std::make_pair(int(source),outgoing_messages())); impl_->new_batches.back().second.swap(new_messages); impl_->max_received = (std::max)(impl_->max_received,impl_->new_batches.size()); } }
int main(int argc, char **argv) { printf("%lu\n", sizeof(struct ndn_bucket)); struct ndn_bucket *ht; int i, j; int dst_ports[BATCH_SIZE], nb_succ = 0, dst_port_sum = 0; /** < Variables for PAPI */ float real_time, proc_time, ipc; long long ins; int retval; red_printf("main: Initializing NDN hash table\n"); ndn_init(URL_FILE, 0xf, &ht); red_printf("\tmain: Setting up NDN index done!\n"); red_printf("main: Getting name array for lookups\n"); int nb_names = ndn_get_num_lines(NAME_FILE); nb_names = nb_names - (nb_names % BATCH_SIZE); /**< Align input to batch */ struct ndn_name *name_arr = ndn_get_name_array(NAME_FILE); red_printf("\tmain: Constructed name array!\n"); red_printf("main: Starting NDN lookups\n"); /** < Init PAPI_TOT_INS and PAPI_TOT_CYC counters */ if((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK) { printf("PAPI error: retval: %d\n", retval); exit(1); } for(i = 0; i < nb_names; i += BATCH_SIZE) { memset(dst_ports, -1, BATCH_SIZE * sizeof(int)); process_batch(&name_arr[i], dst_ports, ht); for(j = 0; j < BATCH_SIZE; j ++) { #if NDN_DEBUG == 1 printf("Name %s -> port %d\n", name_arr[i + j].name, dst_ports[j]); #endif nb_succ += (dst_ports[j] == -1) ? 0 : 1; dst_port_sum += dst_ports[j]; } } if((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK) { printf("PAPI error: retval: %d\n", retval); exit(1); } red_printf("Time = %.4f s, Lookup rate = %.2f M/s | nb_succ = %d, sum = %d\n" "Instructions = %lld, IPC = %f\n", real_time, nb_names / (real_time * 1000000), nb_succ, dst_port_sum, ins, ipc); return 0; }
int main(int argc, char **argv) { int i; /** < Variables for PAPI */ float real_time, proc_time, ipc; long long ins; int retval; red_printf("main: Initializing cuckoo hash table\n"); cuckoo_init(&keys, &ht_index); red_printf("main: Starting lookups\n"); /** < Init PAPI_TOT_INS and PAPI_TOT_CYC counters */ if((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK) { printf("PAPI error: retval: %d\n", retval); exit(1); } for(i = 0; i < NUM_KEYS; i += BATCH_SIZE) { process_batch(&keys[i]); } if((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK) { printf("PAPI error: retval: %d\n", retval); exit(1); } red_printf("Time = %.4f s, rate = %.2f\n" "Instructions = %lld, IPC = %f\n" "sum = %d, succ_1 = %d, succ_2 = %d, fail = %d\n", real_time, NUM_KEYS / real_time, ins, ipc, sum, succ_1, succ_2, fail); return 0; }
int main(int argc, char **argv) { int i; /** < Variables for PAPI */ float real_time, proc_time, ipc; long long ins; int retval; red_printf("main: Initializing nodes for random walk\n"); rand_walk_init(&nodes); red_printf("main: Starting random walks\n"); /** < Init PAPI_TOT_INS and PAPI_TOT_CYC counters */ if((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK) { printf("PAPI error: retval: %d\n", retval); exit(1); } /** < Do a random-walk from every node in the graph */ for(i = 0; i < NUM_NODES; i += BATCH_SIZE) { process_batch(&nodes[i]); } if((retval = PAPI_ipc(&real_time, &proc_time, &ins, &ipc)) < PAPI_OK) { printf("PAPI error: retval: %d\n", retval); exit(1); } red_printf("Time = %.4f, rate = %.2f sum = %lld\n" "Instructions = %lld, IPC = %f\n", real_time, NUM_NODES / real_time, sum, ins, ipc); return 0; }
void mpi_process_group::synchronize() const { // Don't synchronize if we've already finished if (boost::mpi::environment::finalized()) return; #ifdef DEBUG std::cerr << "SYNC: " << process_id(*this) << std::endl; #endif emit_on_synchronize(); process_id_type id = process_id(*this); // Our rank process_size_type p = num_processes(*this); // The number of processes // Pack the remaining incoming messages into the beginning of the // buffers, so that we can receive new messages in this // synchronization step without losing those messages that have not // yet been received. pack_headers(); impl_->synchronizing_stage[id] = -1; int stage=-1; bool no_new_messages = false; while (true) { ++stage; #ifdef DEBUG std::cerr << "SYNC: " << id << " starting stage " << (stage+1) << ".\n"; #endif // Tell everyone that we are synchronizing. Note: we use MPI_Isend since // we absolutely cannot have any of these operations blocking. // increment the stage for the source ++impl_->synchronizing_stage[id]; if (impl_->synchronizing_stage[id] != stage) std::cerr << "Expected stage " << stage << ", got " << impl_->synchronizing_stage[id] << std::endl; BOOST_ASSERT(impl_->synchronizing_stage[id]==stage); // record how many still have messages to be sent if (static_cast<int>(impl_->synchronizing_unfinished.size())<=stage) { BOOST_ASSERT(static_cast<int>(impl_->synchronizing_unfinished.size()) == stage); impl_->synchronizing_unfinished.push_back(no_new_messages ? 0 : 1); } else impl_->synchronizing_unfinished[stage]+=(no_new_messages ? 0 : 1); // record how many are in that stage if (static_cast<int>(impl_->processors_synchronizing_stage.size())<=stage) { BOOST_ASSERT(static_cast<int>(impl_->processors_synchronizing_stage.size()) == stage); impl_->processors_synchronizing_stage.push_back(1); } else ++impl_->processors_synchronizing_stage[stage]; impl_->synchronizing = true; for (int dest = 0; dest < p; ++dest) { int sync_message = no_new_messages ? -1 : impl_->number_sent_batches[dest]; if (dest != id) { impl_->number_sent_batches[dest]=0; MPI_Request request; MPI_Isend(&sync_message, 1, MPI_INT, dest, msg_synchronizing, impl_->comm,&request); int done=0; do { poll(); MPI_Test(&request,&done,MPI_STATUS_IGNORE); } while (!done); } else { // need to subtract how many messages I should have received impl_->number_received_batches[id] -=impl_->number_sent_batches[id]; impl_->number_sent_batches[id]=0; } } // Keep handling out-of-band messages until everyone has gotten // to this point. while (impl_->processors_synchronizing_stage[stage] <p) { // with the trigger based solution we cannot easily pass true here poll(/*wait=*/false, -1, true); } // check that everyone is at least here for (int source=0; source<p ; ++source) BOOST_ASSERT(impl_->synchronizing_stage[source] >= stage); // receive any batches sent in the meantime // all have to be available already while (true) { bool done=true; for (int source=0; source<p ; ++source) if(impl_->number_received_batches[source] < 0) done = false; if (done) break; poll(false,-1,true); } #ifndef NO_IMMEDIATE_PROCESSING for (int source=0; source<p ; ++source) BOOST_ASSERT(impl_->number_received_batches[source] >= 0); #endif impl_->synchronizing = false; // Flush out remaining messages if (impl_->synchronizing_unfinished[stage]==0) break; #ifdef NO_IMMEDIATE_PROCESSING for (process_id_type dest = 0; dest < p; ++dest) process_batch(dest); #endif no_new_messages = true; for (process_id_type dest = 0; dest < p; ++dest) { if (impl_->outgoing[dest].headers.size() || impl_->number_sent_batches[dest]>0) no_new_messages = false; send_batch(dest); } } impl_->comm.barrier/*nomacro*/(); #if 0 // set up for next synchronize call for (int source=0; source<p; ++source) { if (impl_->synchronizing_stage[source] != stage) { std::cerr << id << ": expecting stage " << stage << " from source " << source << ", got " << impl_->synchronizing_stage[source] << std::endl; } BOOST_ASSERT(impl_->synchronizing_stage[source]==stage); } #endif std::fill(impl_->synchronizing_stage.begin(), impl_->synchronizing_stage.end(), -1); // get rid of the information regarding recorded numbers of processors // for the stages we just finished impl_->processors_synchronizing_stage.clear(); impl_->synchronizing_unfinished.clear(); for (process_id_type dest = 0; dest < p; ++dest) BOOST_ASSERT (impl_->outgoing[dest].headers.empty()); #ifndef NO_IMMEDIATE_PROCESSING for (int source=0; source<p ; ++source) BOOST_ASSERT (impl_->number_received_batches[source] == 0); #endif impl_->free_sent_batches(); #ifdef DEBUG std::cerr << "SYNC: " << process_id(*this) << " completed." << std::endl; #endif }
void *ids_func(void *ptr) { int i, j; struct aho_ctrl_blk *cb = (struct aho_ctrl_blk *) ptr; int id = cb->tid; struct aho_dfa *dfa_arr = cb->dfa_arr; struct aho_pkt *pkts = cb->pkts; int num_pkts = cb->num_pkts; /**< Per-batch matched patterns */ struct mp_list_t mp_list[BATCH_SIZE]; for(i = 0; i < BATCH_SIZE; i ++) { mp_list[i].num_match = 0; } /**< Being paranoid about GCC optimization: ensure that the memcpys in * process_batch functions don't get optimized out */ int matched_pat_sum = 0; int tot_proc = 0; /**< How many packets did we actually match ? */ int tot_success = 0; /**< Packets that matched a DFA state */ int tot_bytes = 0; /**< Total bytes matched through DFAs */ while(1) { struct timespec start, end; clock_gettime(CLOCK_REALTIME, &start); for(i = 0; i < num_pkts; i += BATCH_SIZE) { process_batch(dfa_arr, &pkts[i], mp_list); for(j = 0; j < BATCH_SIZE; j ++) { int num_match = mp_list[j].num_match; assert(num_match < MAX_MATCH); tot_success += num_match == 0 ? 0 : 1; int pat_i; #if DEBUG == 1 printf("Pkt %d matched: ", pkts[i + j].pkt_id); for(pat_i = 0; pat_i < num_match; pat_i ++) { printf("%d ", mp_list[j].ptrn_id[pat_i]); matched_pat_sum += mp_list[j].ptrn_id[pat_i]; } printf("\n"); #else for(pat_i = 0; pat_i < num_match; pat_i ++) { matched_pat_sum += mp_list[j].ptrn_id[pat_i]; } #endif tot_proc ++; tot_bytes += pkts[i + j].len; /**< Re-initialize for next iteration */ mp_list[j].num_match = 0; } } clock_gettime(CLOCK_REALTIME, &end); double ns = (end.tv_sec - start.tv_sec) * 1000000000 + (double) (end.tv_nsec - start.tv_nsec); red_printf("ID %d: Rate = %.2f Gbps. tot_success = %d\n", id, ((double) tot_bytes * 8) / ns, tot_success); red_printf("num_pkts = %d, tot_proc = %d | matched_pat_sum = %d\n", num_pkts, tot_proc, matched_pat_sum); matched_pat_sum = 0; /**< Sum of all matched pattern IDs */ tot_success = 0; tot_bytes = 0; tot_proc = 0; #if DEBUG == 1 /**< Print matched states only once */ exit(0); #endif } }
int main(int argc, char **argv) { // To know if there was an error or not int errcode = 0; // Scan all arguments int show_help = 0; int show_ver = 0; const char *filename = NULL; int scan_ok = 1; int err_manyfiles = 0; for (int curr_arg = 1; curr_arg < argc; curr_arg++) { // Get pointer to argument, to make our lives easier const char *arg = argv[curr_arg]; // If it's an option, parse it if (scan_ok && arg[0] == '-') { // Stop parsing options? if (!strcmp(arg, "--")) scan_ok = 0; // Show help or version? else if (!strcmp(arg, "-h") || !strcmp(arg, "--help")) show_help = 1; else if (!strcmp(arg, "-v") || !strcmp(arg, "--version")) show_ver = 1; // Unknown argument else { fprintf(stderr, "Error: unknown option \"%s\"\n", arg); errcode = 1; } } // Filename? else if (filename == NULL) filename = arg; // Too many files specified? else err_manyfiles = 1; } // Look for error conditions if (!show_help && !show_ver) { if (filename == NULL) { errcode = 1; fprintf(stderr, "Error: batch filename missing\n"); } else if (err_manyfiles) { errcode = 1; fprintf(stderr, "Error: too many filenames specified\n"); } } // If there was an error then quit if (errcode) return EXIT_FAILURE; // Show tool version? if (show_ver) { puts("0.8"); return EXIT_SUCCESS; } // Show tool usage? if (show_help) { printf("Usage:\n" " %s <batchfile>\n" "\n" "Options:\n" " -h or --help ...... Show this help\n" " -v or --version ... Show tool version\n", argv[0]); return EXIT_SUCCESS; } // Parse batch file errcode = process_batch(filename); // If there was an error, show a message if (errcode) { // Determine message to show const char *msg; switch(errcode) { case ERR_OPENBATCH: msg = "can't open batch file"; break; case ERR_READBATCH: msg = "can't read from batch file"; break; case ERR_NOMEMORY: msg = "ran out of memory"; break; case ERR_PARSE: msg = "unable to process batch file"; break; default: msg = "unknown error"; break; } // Show message on screen fprintf(stderr, "Error: %s\n", msg); } // Quit program reset_events(); return errcode ? EXIT_FAILURE : EXIT_SUCCESS; }
/*ARGSUSED1*/ int dispatch_batch(void *batchvoidp, void **dummy) { BATCH batch = (BATCH)batchvoidp; int iStatus = SUCCESS; int iDbStatus = SUCCESS; int iLockStatus = SUCCESS; static char * this_func = "dispatch_batch"; char szSetClause[256]; char Msg[256]; int bid_state; bid_state = arb_get_current_state(); if (bid_state == ARB_STATUS_LOGOUT) return(F_LOGOUT_ERROR); SET_DISPATCH_TYPE; if (RERUN) dir = done_dir; /* for RERUN, check done_dir first */ else dir = ready_dir; /* for non-RERUN, only check ready_dir */ reinit_queues(); /* Dispatch the batch. */ iStatus = preprocess_batch(batch); /* LOCKs batch and devices. */ sprintf(Msg, "iStatus after preprocess= %d", iStatus); trace("dispatch_batch",Msg); if (SUCCESS == iStatus) { iStatus = process_batch(batch, dir); sprintf(Msg, "iStatus after process= %d", iStatus); trace("dispatch_batch",Msg); } if (SUCCESS == iStatus) { iStatus = postprocess_batch(batch); sprintf(Msg, "iStatus after postprocess= %d", iStatus); trace("dispatch_batch",Msg); } /* Need to unlock all devices for BID that PRINTs LLT */ if (!BID_ftp) { if (DEVICES_ARE_LOCKED) if(SUCCESS != (iLockStatus = unlock_all_devices())) iStatus = iLockStatus; /* FATAL error. Dies. */ } /* Check error conditions */ if (fatal_error(iStatus)) { /* Error with device or db */ emit(BIDMOD,BID_FATAL_ERROR, this_func, batch->batch_id,iStatus); sprintf(szSetClause," SET dispatch_status=%d", BID_ERROR); iDbStatus = set_bill_files(szSetClause, NULL, batch->batch_id, bid_hold_flag, bid_error_flag, BID_NO_STATUS); return(EXIT_FAILURE); } if(SUCCESS != iStatus) { sprintf(Msg, "iStatus = %d", iStatus); trace("dispatch_batch",Msg); /* non-fatal errors -- continue to loop */ if(iStatus == NO_BILL_FILES) return(SUCCESS); if(iStatus == POSTPROC_ERROR) emit(BIDMOD,BID_POSTPROC_ERROR,this_func,batch->batch_id); else emit(BIDMOD,BID_NONFATAL_ERROR,this_func, batch->batch_id); sprintf(szSetClause," SET dispatch_status=%d", BID_ERROR); iDbStatus = set_bill_files(szSetClause, NULL, batch->batch_id, bid_hold_flag, bid_error_flag, BID_NO_STATUS); if (SUCCESS != iDbStatus) return(iDbStatus); } return(EXIT_SUCCESS); }