int run(void) { database *db; if (!cache) { cache = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_probe); } LOG(LOG_INFO, "reading info from database (group %u)", (unsigned)OPT_VALUE_GROUPID); uw_setproctitle("reading info from database (group %u)", (unsigned)OPT_VALUE_GROUPID); db = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_VALUE_DBPORT, OPT_ARG(DBNAME), OPT_ARG(DBUSER), OPT_ARG(DBPASSWD)); if (db) { refresh_database(db); close_database(db); } if (g_hash_table_size(cache) > 0) { LOG(LOG_INFO, "running %d probes from group %u", g_hash_table_size(cache), (unsigned)OPT_VALUE_GROUPID); uw_setproctitle("running %d probes from group %u", g_hash_table_size(cache), (unsigned)OPT_VALUE_GROUPID); run_actual_probes(); /* this runs the actual probes */ LOG(LOG_INFO, "writing results"); uw_setproctitle("writing results"); write_results(); } return(g_hash_table_size(cache)); }
int main(int argc, char** argv) { int rows = 9000; int cols = 128; int tcount = 1000; printf("Reading input data file.\n"); float* dataset = read_points("dataset.dat", rows, cols); printf("Reading test data file.\n"); float* testset = read_points("testset.dat", tcount, cols); int nn = 3; int* result = (int*) malloc(tcount*nn*sizeof(int)); float* dists = (float*) malloc(tcount*nn*sizeof(float)); struct FLANNParameters p = DEFAULT_FLANN_PARAMETERS; p.algorithm = KDTREE; p.trees = 8; p.log_level = LOG_INFO; float speedup; printf("Computing index.\n"); flann_index_t index_id = flann_build_index(dataset, rows, cols, &speedup, &p); flann_find_nearest_neighbors_index(index_id, testset, tcount, result, dists, nn, &p); write_results("results.dat",result, tcount, nn); flann_free_index(index_id, &p); free(dataset); free(testset); free(result); free(dists); return 0; }
/*--------------- main routine ---------------*/ int main( int argc, char *argv[] ) { options_t * opts = &g_opts; int rv; if( argc < 2 ) { show_help(); return 0; } mainENTRY("3dTto1D main"); machdep(); AFNI_logger("3dTto1D",argc,argv); /* process command line arguments (and read dataset and mask) */ rv = process_opts(opts, argc, argv); if( rv ) RETURN(rv < 0); /* only a negative return is considered failure */ if( check_dims(opts) ) RETURN(1); /* evaluation of rv now depends on the method, usually non-zero is bad */ rv = compute_results(opts); /* for 4095_warn, return now, regardless */ if( opts->method == T21_METH_4095_WARN ) RETURN(rv); /* otherwise, any non-zero return is a failure */ if ( rv ) RETURN(1); if( write_results(opts) ) RETURN(1); RETURN(0); }
int _tmain(int argc, _TCHAR* argv[]) { double tcpConnectOverheadRemote = tcp_connect_overhead(); double tcpConnectOverheadLoopback = tcp_connect_overhead(1); write_results("Network_Connection_Overhead_Results.txt", tcpConnectOverheadRemote, tcpConnectOverheadLoopback); return 0; }
int run(void) { dbi_conn conn; if (!cache) { cache = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_probe); } LOG(LOG_INFO, "reading info from database"); uw_setproctitle("reading info from database"); conn = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_ARG(DBPORT), OPT_ARG(DBNAME), OPT_ARG(DBUSER), OPT_ARG(DBPASSWD)); if (conn) { refresh_database(conn); close_database(conn); } if (g_hash_table_size(cache) > 0) { LOG(LOG_INFO, "running %d probes", g_hash_table_size(cache)); uw_setproctitle("running %d probes", g_hash_table_size(cache)); run_actual_probes(); /* this runs the actual probes */ LOG(LOG_INFO, "writing results"); uw_setproctitle("writing results"); write_results(); } return(g_hash_table_size(cache)); }
int _tmain(int argc, _TCHAR* argv[]) { double dMeasurementOverhead, dLoopOverhead; dMeasurementOverhead = measurement_overhead(); dLoopOverhead = loop_overhead() - dMeasurementOverhead; write_results("CPU_Measurement_Overhead_Results.txt", dMeasurementOverhead, dLoopOverhead); return 0; }
int main(int argc, char *argv[]) { dispstr(0,"Welcome to the HMM program!\n"); #ifndef __STDC_IEC_559__ printf("WARNING: ISO/IEC 60559 not respected!\n"); #endif parse(argc, argv); dispstr(0,"Loading file...\n"); delays_mt input = getinput(); dispstr(0,"Sorting inputs...\n"); mysort(&input); //this offsets the timestamps to zero, and finds the min and max value of the delays. delay_mt ymin = input.delay[0]; delay_mt ymax = ymin; delay_mt current; time_mt tmin = input.time[0]; for(long long i = 0; i<input.length; i++) { input.time[i] = input.time[i] - tmin; current = input.delay[i]; if(current < ymin) ymin = current; if(current > ymax) ymax = current; } //now, we offset the delays to zero for(long long i = 0;i<input.length;i++) { //MINDELAY is an epsilon in order not to bug the algo input.delay[i] = input.delay[i] - ymin + MINDELAY; } struct params p; dispstr(0,"Initializing Markov parameters...\n"); initparams(&p, ymax); input.length = input.length/300; dispstr(0,"Training model...\n"); train(&p, &input, ymax); dispstr(0,"Writing results...\n"); write_results(&p); freeparams(&p); dispstr(0,"Done.\n"); return EXIT_SUCCESS; }
int main(int argc, char const *argv[]) { clock_t now = clock(); printf("--- # benchmarking\n"); now = clock(); execute(argv); now = clock() - now; write_results(now); return 0; }
void Tesseract::output_pass( //Tess output pass //send to api PAGE_RES_IT &page_res_it, const TBOX *target_word_box) { BLOCK_RES *block_of_last_word; inT16 block_id; BOOL8 force_eol; //During output BLOCK *nextblock; //block of next word WERD *nextword; //next word page_res_it.restart_page (); block_of_last_word = NULL; while (page_res_it.word () != NULL) { check_debug_pt (page_res_it.word (), 120); if (target_word_box) { TBOX current_word_box=page_res_it.word ()->word->bounding_box(); FCOORD center_pt((current_word_box.right()+current_word_box.left())/2,(current_word_box.bottom()+current_word_box.top())/2); if (!target_word_box->contains(center_pt)) { page_res_it.forward (); continue; } } if (tessedit_write_block_separators && block_of_last_word != page_res_it.block ()) { block_of_last_word = page_res_it.block (); block_id = block_of_last_word->block->index(); } force_eol = (tessedit_write_block_separators && (page_res_it.block () != page_res_it.next_block ())) || (page_res_it.next_word () == NULL); if (page_res_it.next_word () != NULL) nextword = page_res_it.next_word ()->word; else nextword = NULL; if (page_res_it.next_block () != NULL) nextblock = page_res_it.next_block ()->block; else nextblock = NULL; //regardless of tilde crunching write_results(page_res_it, determine_newline_type(page_res_it.word()->word, page_res_it.block()->block, nextword, nextblock), force_eol); page_res_it.forward(); } }
int main(int argc, char** argv) { float* dataset; float* testset; int nn; int* result; float* dists; struct FLANNParameters p; float speedup; flann_index_t index_id; int rows = 9000; int cols = 128; int tcount = 1000; /* * The files dataset.dat and testset.dat can be downloaded from: * http://people.cs.ubc.ca/~mariusm/uploads/FLANN/datasets/dataset.dat * http://people.cs.ubc.ca/~mariusm/uploads/FLANN/datasets/testset.dat */ printf("Reading input data file.\n"); dataset = read_points("dataset.dat", rows, cols); printf("Reading test data file.\n"); testset = read_points("testset.dat", tcount, cols); nn = 3; result = (int*) malloc(tcount*nn*sizeof(int)); dists = (float*) malloc(tcount*nn*sizeof(float)); p = DEFAULT_FLANN_PARAMETERS; p.algorithm = FLANN_INDEX_KDTREE; p.trees = 8; p.log_level = FLANN_LOG_INFO; p.checks = 64; printf("Computing index.\n"); index_id = flann_build_index(dataset, rows, cols, &speedup, &p); flann_find_nearest_neighbors_index(index_id, testset, tcount, result, dists, nn, &p); write_results("results.dat",result, tcount, nn); flann_free_index(index_id, &p); free(dataset); free(testset); free(result); free(dists); return 0; }
// ---------------------------------------------------------------------- void SimulationTaskLocalizationEvaluation:: write_out( const SimulationController& sc, const HeaderInfo& header, const Results& results ) const throw( std::runtime_error ) { std::string fname = sc.environment().optional_string_param( "loc_ls_out", "" ); if ( fname == "" ) return; std::string ftype = sc.environment().required_string_param( "loc_ls_type" ); if ( ftype != "create" && ftype != "append" ) throw std::runtime_error("Wrong argument for 'loc_ls_type'. Should be 'create' or 'append'"); if ( ftype == "create" ) write_header( fname, header ); write_results( fname, results ); }
int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Expected 2 arguments\n"); exit(1); } char *fname = argv[1]; Solver solver; solver_init(&solver); printf("reading %s\n", fname); solver_read_file(&solver, fname); const bool solution_found = solver_naive(&solver); if (solution_found) { print_values(solver.values, solver.n_variables); } write_results(&solver, solution_found); solver_destroy(&solver); }
void start(graphlab::command_line_options& clopts, std::string & graph_dir, std::string & format, std::string & exec_type, std::string & saveprefix) { local_graph_type l_graph; std::vector<vertex_record> lvid2record_ref; std::vector<replica_record> replicas_lvid2record_ref; //typedef graphlab::hopscotch_map<graphlab::vertex_id_type, graphlab::lvid_type> hopscotch_map_type; //hopscotch_map_type vid2lvid_ref; //hopscotch_map_type replicas_vid2lvid_ref; unsigned int iter = 0; int iteration_number = 0; int surviving_server_count; bool replacement_server = atoi(getenv("REPLACEMENT")) != 0; int replacement_server_count = atoi(getenv("REPLACEMENT_COUNT")); bool ground_truth = atoi(getenv("GROUND_TRUTH")) != 0; bool proactive_replication = atoi(getenv("PROACTIVE_REPLICATION")) != 0; graphlab::reactive_zorro<pagerank>* rs; std::unordered_map<std::string, int> current_ip_to_id_map; // map from ip of process to its id for currently alive processes std::unordered_map<std::string, int> previous_ip_to_id_map; // map from ip of process to its id for previously alove processes std::vector<int> id_to_previous_id; // map from previous id of a process to its current ip, -1 if a process was not replaced while (1) { try { if (iter > 0) { // TODO: Sleep here if required to ensure that the count of surviving servers is accurate. // Consider all survivors and any replacement servers (if available) for the next execution. surviving_server_count = rs->stop_watching_zoookeeper(); // we can increase the surviving server count if replacements available std::cout << "Zorro: Surviving server count: " << surviving_server_count << std::endl; std::cout << "Zorro: Replacement server count: " << replacement_server_count << std::endl; setenv("ZK_NUMNODES", std::to_string(surviving_server_count + replacement_server_count).c_str(), 1); } // Initialize from ZooKeeper graphlab::dc_init_param initparam; graphlab::init_param_from_zookeeper(initparam); graphlab::distributed_control dc(initparam); // Initialize without ZooKeeper //graphlab::distributed_control dc; if (iter > 0) { rs->stop(); // end previous reactive_server session delete rs; } // Initialize the graph graph_type graph(dc, clopts); std::cout << "Zorro: Graph initialized." << std::endl; // Initialize synchronous engine graphlab::omni_engine<pagerank> engine(dc, graph, exec_type, clopts); auto sync_engine_ptr = static_cast<graphlab::synchronous_engine<pagerank> * >(engine.get_engine_ptr()); // Set local_graph and lvid2record map in synchronous engine. // These are required to trasnfer surviving vertex values to replacement servers. if (!replacement_server) { sync_engine_ptr->set_l_graph_backup(&l_graph); sync_engine_ptr->set_lvid2record_backup(&lvid2record_ref); if (proactive_replication) { sync_engine_ptr->set_replicas_lvid2record_backup(&replicas_lvid2record_ref); } } std::cout << "Zorro: Constructing id maps" << std::endl; // Waitless Zorro maps previous process ids to new process ids std::vector<std::string>& machines = initparam.machines; for (int i = 0; i < machines.size(); ++i) { std::cout << machines[i] << std::endl; size_t pos = machines[i].find(":"); current_ip_to_id_map[machines[i].substr(0, pos)] = i; } if (iter == 0) { id_to_previous_id.resize(dc.numprocs()); // TODO: Figure out the most efficient method to copy unordered_maps previous_ip_to_id_map.insert(current_ip_to_id_map.begin(), current_ip_to_id_map.end()); } std::cout << "Zorro: Constructing id to id map" << std::endl; // Map previous proc ids to new proc ids for (auto element : previous_ip_to_id_map) { if (current_ip_to_id_map.find(element.first) != current_ip_to_id_map.end()) { id_to_previous_id[element.second] = current_ip_to_id_map[element.first]; } else { id_to_previous_id[element.second] = -1; } } for (size_t i = 0; i < id_to_previous_id.size(); ++i) { std::cout << "Previous id: " << i << " now has an id: " << id_to_previous_id[i] << std::endl; } std::cout << "Zorro: Initializing reactive server" << std::endl; rs = new graphlab::reactive_zorro<pagerank>(); rs->init(&dc, &engine, iteration_number); rs->wait_for_join(); std::vector< std::pair<size_t, bool> > server_list = extract_and_set_iteration(sync_engine_ptr, rs->get_received_servers()); sync_engine_ptr->set_server_list(server_list); std::cout << "Zorro: All processes have joined: " << server_list.size() << std::endl; sync_engine_ptr->resize_received_state_container(dc.numprocs()); dc.barrier(); graphlab::thread_group tgroup; // Broadcast surviving state if not a replacement server if(iter > 0 && !replacement_server) { std::cout << "Zorro: Rebuilding state by requesting vertex data." << std::endl; if (proactive_replication) { sync_engine_ptr->broadcast_surviving_state_replicas(tgroup, surviving_server_count, id_to_previous_id); } else { sync_engine_ptr->broadcast_surviving_state(tgroup, surviving_server_count, id_to_previous_id); } } // Load the graph graph.load_format(graph_dir, format); // must call finalize before querying the graph graph.finalize(); std::cout << "#vertices: " << graph.num_vertices() << " #edges:" << graph.num_edges() << std::endl; // Initialize the vertex data sync_engine_ptr->resize(); // Separately called to enable parallel graph loading with recovery graph.transform_vertices(init_vertex); tgroup.join(); std::vector<vid_vdata_vector_type> received_state; received_state = sync_engine_ptr->get_received_state(); std::cout << "Zorro: Receive surviving state thread joined. Now merging." << std::endl; // Merge received state into primary graph state graphlab::thread_group tgroup_merge; for (size_t i = 0; i < received_state.size(); ++i) { tgroup_merge.launch(boost::bind(&merge_values, boost::ref(received_state[i]), boost::ref(graph))); } tgroup_merge.join(); engine.signal_all(); try { engine.start(); rs->stop(); const double runtime = engine.elapsed_seconds(); std::cout << "Zorro: Completed Running engine in " << runtime << " seconds." << std::endl; if (ground_truth) { write_results("/home/lamport/output_ground", graph); // write ground truth } else { write_results("/home/lamport/output", graph); // write result with failures } // Save the final graph if (saveprefix != "") { std::cout << "SAVING FILE" << std::endl; graph.save(saveprefix, pagerank_writer(), false, // do not gzip true, // save vertices false); // do not save edges } return; } catch(graphlab::failure_exception e) { l_graph = std::move(graph.get_local_graph()); //vid2lvid_ref = std::move(graph.get_vid2lvid()); lvid2record_ref = std::move(graph.get_lvid2record()); if (proactive_replication) { //replicas_vid2lvid_ref = std::move(graph.get_replicas_vid2lvid()); replicas_lvid2record_ref = std::move(graph.get_replicas_lvid2record()); } iteration_number = sync_engine_ptr->iteration(); // TODO: Figure out the most efficient method to copy unordered_maps previous_ip_to_id_map.clear(); previous_ip_to_id_map.insert(current_ip_to_id_map.begin(), current_ip_to_id_map.end()); current_ip_to_id_map.clear(); throw e; } } catch(graphlab::failure_exception) { std::cout << "Zorro: Failed Running engine at iteration: " << iter << ". Recovering..." << std::endl; ++iter; continue; } } }
int main(int argc, char **argv) { int i, j; /* loop and temporary variables */ struct timespec sleep_time = {0, 3000000}; /* 3 ms */ float average_snr=0; int packet_counter=0; /* clock and log rotation management */ int log_rotate_interval = 3600; /* by default, rotation every hour */ int time_check = 0; /* variable used to limit the number of calls to time() function */ unsigned long pkt_in_log = 0; /* count the number of packet written in each log file */ /* configuration file related */ const char global_conf_fname[] = "global_conf.json"; /* contain global (typ. network-wide) configuration */ const char local_conf_fname[] = "local_conf.json"; /* contain node specific configuration, overwrite global parameters for parameters that are defined in both */ const char debug_conf_fname[] = "debug_conf.json"; /* if present, all other configuration files are ignored */ /* allocate memory for packet fetching and processing */ struct lgw_pkt_rx_s rxpkt[16]; /* array containing up to 16 inbound packets metadata */ struct lgw_pkt_rx_s *p; /* pointer on a RX packet */ int nb_pkt; /* local timestamp variables until we get accurate GPS time */ struct timespec fetch_time; char fetch_timestamp[30]; struct tm * x; /* parse command line options */ while ((i = getopt (argc, argv, "hr:")) != -1) { switch (i) { case 'h': usage(); return EXIT_FAILURE; break; case 'r': log_rotate_interval = atoi(optarg); if ((log_rotate_interval == 0) || (log_rotate_interval < -1)) { MSG( "ERROR: Invalid argument for -r option\n"); return EXIT_FAILURE; } break; default: MSG("ERROR: argument parsing use -h option for help\n"); usage(); return EXIT_FAILURE; } } /* configure signal handling */ sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; sigact.sa_handler = sig_handler; sigaction(SIGQUIT, &sigact, NULL); sigaction(SIGINT, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); /* configuration files management */ if (access(debug_conf_fname, R_OK) == 0) { /* if there is a debug conf, parse only the debug conf */ MSG("INFO: found debug configuration file %s, other configuration files will be ignored\n", debug_conf_fname); parse_SX1301_configuration(debug_conf_fname); parse_gateway_configuration(debug_conf_fname); } else if (access(global_conf_fname, R_OK) == 0) { /* if there is a global conf, parse it and then try to parse local conf */ MSG("INFO: found global configuration file %s, trying to parse it\n", global_conf_fname); parse_SX1301_configuration(global_conf_fname); parse_gateway_configuration(global_conf_fname); if (access(local_conf_fname, R_OK) == 0) { MSG("INFO: found local configuration file %s, trying to parse it\n", local_conf_fname); parse_SX1301_configuration(local_conf_fname); parse_gateway_configuration(local_conf_fname); } } else if (access(local_conf_fname, R_OK) == 0) { /* if there is only a local conf, parse it and that's all */ MSG("INFO: found local configuration file %s, trying to parse it\n", local_conf_fname); parse_SX1301_configuration(local_conf_fname); parse_gateway_configuration(local_conf_fname); } else { MSG("ERROR: failed to find any configuration file named %s, %s or %s\n", global_conf_fname, local_conf_fname, debug_conf_fname); return EXIT_FAILURE; } /* starting the concentrator */ i = lgw_start(); if (i == LGW_HAL_SUCCESS) { MSG("INFO: concentrator started, packet can now be received\n"); } else { MSG("ERROR: failed to start the concentrator\n"); return EXIT_FAILURE; } /* transform the MAC address into a string */ sprintf(lgwm_str, "%08X%08X", (uint32_t)(lgwm >> 32), (uint32_t)(lgwm & 0xFFFFFFFF)); /* opening log file and writing CSV header*/ time(&now_time); open_log(); /* main loop */ while ((quit_sig != 1) && (exit_sig != 1)) { /* fetch packets */ nb_pkt = lgw_receive(ARRAY_SIZE(rxpkt), rxpkt); if (nb_pkt == LGW_HAL_ERROR) { MSG("ERROR: failed packet fetch, exiting\n"); return EXIT_FAILURE; } else if (nb_pkt == 0) { clock_nanosleep(CLOCK_MONOTONIC, 0, &sleep_time, NULL); /* wait a short time if no packets */ } else { /* local timestamp generation until we get accurate GPS time */ clock_gettime(CLOCK_REALTIME, &fetch_time); x = gmtime(&(fetch_time.tv_sec)); sprintf(fetch_timestamp,"%04i-%02i-%02i %02i:%02i:%02i.%03liZ",(x->tm_year)+1900,(x->tm_mon)+1,x->tm_mday,x->tm_hour,x->tm_min,x->tm_sec,(fetch_time.tv_nsec)/1000000); /* ISO 8601 format */ } /* log packets */ for (i=0; i < nb_pkt; ++i) { p = &rxpkt[i]; if (compare_id(p)==0) { if(packet_counter!=0){ write_results(average_snr,packet_counter,p); } send_join_response(p); packet_counter=0; average_snr=0; } /* writing gateway ID */ fprintf(log_file, "\"%08X%08X\",", (uint32_t)(lgwm >> 32), (uint32_t)(lgwm & 0xFFFFFFFF)); /* writing node MAC address */ fputs("\"\",", log_file); // TODO: need to parse payload /* writing UTC timestamp*/ fprintf(log_file, "\"%s\",", fetch_timestamp); // TODO: replace with GPS time when available /* writing internal clock */ fprintf(log_file, "%10u,", p->count_us); /* writing RX frequency */ fprintf(log_file, "%10u,", p->freq_hz); /* writing RF chain */ fprintf(log_file, "%u,", p->rf_chain); /* writing RX modem/IF chain */ fprintf(log_file, "%2d,", p->if_chain); /* writing status */ switch(p->status) { case STAT_CRC_OK: fputs("\"CRC_OK\" ,", log_file); break; case STAT_CRC_BAD: fputs("\"CRC_BAD\",", log_file); break; case STAT_NO_CRC: fputs("\"NO_CRC\" ,", log_file); break; case STAT_UNDEFINED:fputs("\"UNDEF\" ,", log_file); break; default: fputs("\"ERR\" ,", log_file); } /* writing payload size */ fprintf(log_file, "%3u,", p->size); /* writing modulation */ switch(p->modulation) { case MOD_LORA: fputs("\"LORA\",", log_file); break; case MOD_FSK: fputs("\"FSK\" ,", log_file); break; default: fputs("\"ERR\" ,", log_file); } /* writing bandwidth */ switch(p->bandwidth) { case BW_500KHZ: fputs("500000,", log_file); break; case BW_250KHZ: fputs("250000,", log_file); break; case BW_125KHZ: fputs("125000,", log_file); break; case BW_62K5HZ: fputs("62500 ,", log_file); break; case BW_31K2HZ: fputs("31200 ,", log_file); break; case BW_15K6HZ: fputs("15600 ,", log_file); break; case BW_7K8HZ: fputs("7800 ,", log_file); break; case BW_UNDEFINED: fputs("0 ,", log_file); break; default: fputs("-1 ,", log_file); } /* writing datarate */ if (p->modulation == MOD_LORA) { switch (p->datarate) { case DR_LORA_SF7: fputs("\"SF7\" ,", log_file); break; case DR_LORA_SF8: fputs("\"SF8\" ,", log_file); break; case DR_LORA_SF9: fputs("\"SF9\" ,", log_file); break; case DR_LORA_SF10: fputs("\"SF10\" ,", log_file); break; case DR_LORA_SF11: fputs("\"SF11\" ,", log_file); break; case DR_LORA_SF12: fputs("\"SF12\" ,", log_file); break; default: fputs("\"ERR\" ,", log_file); } } else if (p->modulation == MOD_FSK) { fprintf(log_file, "\"%6u\",", p->datarate); } else { fputs("\"ERR\" ,", log_file); } /* writing coderate */ switch (p->coderate) { case CR_LORA_4_5: fputs("\"4/5\",", log_file); break; case CR_LORA_4_6: fputs("\"2/3\",", log_file); break; case CR_LORA_4_7: fputs("\"4/7\",", log_file); break; case CR_LORA_4_8: fputs("\"1/2\",", log_file); break; case CR_UNDEFINED: fputs("\"\" ,", log_file); break; default: fputs("\"ERR\",", log_file); } /* writing packet RSSI */ fprintf(log_file, "%+.0f,", p->rssi); /* writing packet average SNR */ fprintf(log_file, "%+5.1f,", p->snr); /* writing hex-encoded payload (bundled in 32-bit words) */ fputs("\"", log_file); for (j = 0; j < p->size; ++j) { if ((j > 0) && (j%4 == 0)) fputs("-", log_file); fprintf(log_file, "%02X", p->payload[j]); } /* end of log file line */ fputs("\"\n", log_file); fflush(log_file); ++pkt_in_log; } /* check time and rotate log file if necessary */ ++time_check; if (time_check >= 8) { time_check = 0; time(&now_time); if (difftime(now_time, log_start_time) > log_rotate_interval) { fclose(log_file); MSG("INFO: log file %s closed, %lu packet(s) recorded\n", log_file_name, pkt_in_log); pkt_in_log = 0; open_log(); } } } if (exit_sig == 1) { /* clean up before leaving */ i = lgw_stop(); if (i == LGW_HAL_SUCCESS) { MSG("INFO: concentrator stopped successfully\n"); } else { MSG("WARNING: failed to stop concentrator successfully\n"); } fclose(log_file); MSG("INFO: log file %s closed, %lu packet(s) recorded\n", log_file_name, pkt_in_log); } MSG("INFO: Exiting packet logger program\n"); return EXIT_SUCCESS; }
/** Carries out simulation setup and management. @param argc The number of arguments @param argv The array of arguments */ int main(int argc, char *argv[]) { int *results, *shm_states; int i, op_count, proc_id; char *tmp_operator, *cmd; list *commands; operation *shm_operations; if(signal(SIGTERM, &stop_execution) == SIG_ERR) { write_to_fd(2, "Failed to register signal\n"); exit(1); } if(argc != 3) { write_to_fd(2, "Usage: main.x <source file> <results file>\n"); exit(1); } commands = parse_file(argv[1]); processors = atoi(list_extract(commands)); if (processors <= 0) { write_to_fd(2, "Invalid number of processors\n"); exit(1); } write_with_int(1, "Number of processors: ", processors); op_count = list_count(commands); if (op_count == 0) { write_to_fd(2, "No operations provided\n"); exit(1); } write_with_int(1, "Number of operations: ", op_count); results = (int *) malloc(op_count * sizeof(int)); if (results == NULL) { write_to_fd(2, "Failed to allocate results array\n"); exit(1); } init_ipc(2 * processors + 2, processors * sizeof(operation), processors * sizeof(int), 0666 | IPC_CREAT | IPC_EXCL); write_with_int(1, "Created semaphore set with ID ", ipc_id[0]); write_with_int(1, "Created shm for operations with ID ", ipc_id[1]); write_with_int(1, "Created shm for states with ID ", ipc_id[2]); init_sems(processors); shm_operations = (operation *) shm_attach(ipc_id[1]); shm_states = (int *) shm_attach(ipc_id[2]); for (i = 0; i < processors; ++i) shm_states[i] = 0; start_processors(); for (i = 1; list_count(commands) > 0; ++i) { cmd = list_extract(commands); write_with_int(1, "\nOperation #", i); proc_id = atoi(strtok(cmd, " ")); sem_p(2 * processors + 1); if (proc_id-- == 0) { proc_id = find_proc(shm_states); } write_with_int(1, "Waiting for processor ", proc_id + 1); sem_p(2 * proc_id); write_with_int(1, "Delivering operation to processor ", proc_id + 1); if (shm_states[proc_id] != 0) { results[(shm_states[proc_id] + 1) * -1] = shm_operations[proc_id].num1; write_with_int(1, "Previous result: ", shm_operations[proc_id].num1); } shm_operations[proc_id].num1 = atoi(strtok(NULL, " ")); tmp_operator = strtok(NULL, " "); shm_operations[proc_id].op = *tmp_operator; shm_operations[proc_id].num2 = atoi(strtok(NULL, " ")); shm_states[proc_id] = i; write_with_int(1, "Operation delivered. Unblocking processor ", proc_id + 1); sem_v((2 * proc_id) + 1); free(cmd); } list_destruct(commands); for (i = 0; i < processors; ++i) { sem_p(2 * i); write_with_int(1, "\nPassing termination command to processor #", i + 1); if (shm_states[i] != 0) { results[(shm_states[i] + 1) * -1] = shm_operations[i].num1; write_with_int(1, "Last result: ", shm_operations[i].num1); } shm_operations[i].op = 'K'; sem_v((2 * i) + 1); } for (i = 0; i < processors; ++i) if(wait(NULL) == -1) write_to_fd(2, "Wait failed\n"); write_to_fd(1, "\nAll processors exited. Writing output file\n"); write_results(argv[2], results, op_count); free(results); write_to_fd(1, "Closing IPCs\n"); shm_detach((void *) shm_operations); shm_detach((void *) shm_states); close_ipc(); exit(0); }
void WriteCmrFile() { if (CmrFile != NoKey) write_results(StringTable(GetClpValue(CmrFile, 0))); }
int main(int argc, char **argv) { int i; /* loop and temporary variables */ struct timespec sleep_time = {0, 3000000}; /* 3 ms */ int packet_counter = 0; /* allocate memory for packet fetching and processing */ struct lgw_pkt_rx_s rxpkt[16]; /* array containing up to 16 inbound packets metadata */ struct lgw_pkt_rx_s *p; /* pointer on a RX packet */ int nb_pkt; configure_gateway(); /* parse command line options */ while ((i = getopt (argc, argv, "hr:")) != -1) { switch (i) { case 'h': usage(); return EXIT_FAILURE; break; case 'r': result_file_name = optarg; break; default: MSG("ERROR: argument parsing use -h option for help\n"); usage(); return EXIT_FAILURE; } } /* configure signal handling */ sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; sigact.sa_handler = sig_handler; sigaction(SIGQUIT, &sigact, NULL); sigaction(SIGINT, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); /* starting the concentrator */ i = lgw_start(); if (i == LGW_HAL_SUCCESS) { MSG("INFO: concentrator started, packet can now be received\n"); } else { MSG("ERROR: failed to start the concentrator\n"); return EXIT_FAILURE; } openResultFile(); /* transform the MAC address into a string */ sprintf(lgwm_str, "%08X%08X", (uint32_t)(lgwm >> 32), (uint32_t)(lgwm & 0xFFFFFFFF)); /* main loop */ while ((quit_sig != 1) && (exit_sig != 1)) { /* fetch packets */ nb_pkt = lgw_receive(ARRAY_SIZE(rxpkt), rxpkt); if (nb_pkt == LGW_HAL_ERROR) { MSG("ERROR: failed packet fetch, exiting\n"); return EXIT_FAILURE; } else if (nb_pkt == 0) { clock_nanosleep(CLOCK_MONOTONIC, 0, &sleep_time, NULL); /* wait a short time if no packets */ } else { /* local timestamp generation until we get accurate GPS time */ } /* log packets */ for (i=0; i < nb_pkt; ++i) { p = &rxpkt[i]; switch(compare_id(p)) { case JOIN_REQ_MSG: MSG("Sending join response.\n"); send_join_response(p); packet_counter = 0; size = 0; break; case TEST_MSG: snr[packet_counter] = p->snr; packet_counter++; size = p->size; break; case END_TEST_MSG: if (packet_counter != 0) { write_results(packet_counter, p); MSG("Ended series: %i packets received.\n", packet_counter); } packet_counter = 0; size = 0; break; case ALL_TESTS_ENDED_MSG: exit_sig = 1; // ending program MSG("All tests have been finished.\n"); break; default: // message not recognized break; } } } if (exit_sig == 1) { /* clean up before leaving */ i = lgw_stop(); if (i == LGW_HAL_SUCCESS) { MSG("INFO: concentrator stopped successfully\n"); } else { MSG("WARNING: failed to stop concentrator successfully\n"); } } fclose(result_file); MSG("INFO: Exiting uplink concentrator program\n"); return EXIT_SUCCESS; }
int main(int argc, char** argv) { s32 opt; u8 mem_limit_given = 0, timeout_given = 0, qemu_mode = 0; u32 tcnt; char** use_argv; doc_path = access(DOC_PATH, F_OK) ? "docs" : DOC_PATH; while ((opt = getopt(argc,argv,"+o:m:t:A:eqZQ")) > 0) switch (opt) { case 'o': if (out_file) FATAL("Multiple -o options not supported"); out_file = optarg; break; case 'm': { u8 suffix = 'M'; if (mem_limit_given) FATAL("Multiple -m options not supported"); mem_limit_given = 1; if (!strcmp(optarg, "none")) { mem_limit = 0; break; } if (sscanf(optarg, "%llu%c", &mem_limit, &suffix) < 1 || optarg[0] == '-') FATAL("Bad syntax used for -m"); switch (suffix) { case 'T': mem_limit *= 1024 * 1024; break; case 'G': mem_limit *= 1024; break; case 'k': mem_limit /= 1024; break; case 'M': break; default: FATAL("Unsupported suffix or bad syntax for -m"); } if (mem_limit < 5) FATAL("Dangerously low value of -m"); if (sizeof(rlim_t) == 4 && mem_limit > 2000) FATAL("Value of -m out of range on 32-bit systems"); } break; case 't': if (timeout_given) FATAL("Multiple -t options not supported"); timeout_given = 1; if (strcmp(optarg, "none")) { exec_tmout = atoi(optarg); if (exec_tmout < 20 || optarg[0] == '-') FATAL("Dangerously low value of -t"); } break; case 'e': if (edges_only) FATAL("Multiple -e options not supported"); edges_only = 1; break; case 'q': if (quiet_mode) FATAL("Multiple -q options not supported"); quiet_mode = 1; break; case 'Z': /* This is an undocumented option to write data in the syntax expected by afl-cmin. Nobody else should have any use for this. */ cmin_mode = 1; quiet_mode = 1; break; case 'A': /* Another afl-cmin specific feature. */ at_file = optarg; break; case 'Q': if (qemu_mode) FATAL("Multiple -Q options not supported"); if (!mem_limit_given) mem_limit = MEM_LIMIT_QEMU; qemu_mode = 1; break; default: usage(argv[0]); } if (optind == argc || !out_file) usage(argv[0]); setup_shm(); setup_signal_handlers(); set_up_environment(); find_binary(argv[optind]); if (!quiet_mode) { show_banner(); ACTF("Executing '%s'...\n", target_path); } detect_file_args(argv + optind); if (qemu_mode) use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind); else use_argv = argv + optind; run_target(use_argv); tcnt = write_results(); if (!quiet_mode) { if (!tcnt) FATAL("No instrumentation detected" cRST); OKF("Captured %u tuples in '%s'." cRST, tcnt, out_file); } exit(child_crashed * 2 + child_timed_out); }
int main(int argc, char **argv) { bwt_index backward, forward; char *Worig; ref_vector W; results_list rl_prev, rl_next, rl_prev_i, rl_next_i, rl_final; uintmax_t read_index=0; uintmax_t RESULTS, FRAGSIZE; exome ex; FILE *queries_file, *output_file; check_syntax(argc, 7, "exact_search search_file input_dir output_file results_buffer frag_size nucleotides"); timevars(); init_replace_table(argv[6]); queries_file = fopen(argv[1], "r"); check_file_open(queries_file, argv[1]); output_file = fopen(argv[3], "w"); check_file_open(output_file, argv[3]); RESULTS = atoi(argv[4]); FRAGSIZE = atoi(argv[5]); if (FRAGSIZE <= 0) { fprintf(stderr, "Fragsize must be greater than 0\n"); exit(1); } tic("Loading FM-Index"); load_bwt_index(NULL, &backward, argv[2], 1, true); load_bwt_index(NULL, &forward, argv[2], 0, true); toc(); tic("Preparing search space"); load_exome_file(&ex, argv[2]); new_results_list(&rl_prev, RESULTS); new_results_list(&rl_prev_i, RESULTS); new_results_list(&rl_next, RESULTS); new_results_list(&rl_next_i, RESULTS); new_results_list(&rl_final, RESULTS); Worig = (char *) malloc( MAXLINE * sizeof(char) ); check_malloc(Worig, "main"); W.vector = (uint8_t *) malloc( MAXLINE * sizeof(uint8_t) ); check_malloc(W.vector, "main"); toc(); intmax_t *k = (intmax_t*)malloc(RESULTS * sizeof(intmax_t)); intmax_t *l = (intmax_t*)malloc(RESULTS * sizeof(intmax_t)); uintmax_t nW_aux; tic("Sequence mapping"); while(nextFASTAToken(queries_file, Worig, W.vector, &nW_aux)) { if (!W.vector) { printf ("Error de lectura de la cadena a buscar\n"); return -1; } W.n = nW_aux; rl_prev.read_index = read_index; rl_prev_i.read_index = read_index; rl_next.read_index = read_index; rl_next_i.read_index = read_index; rl_final.read_index = read_index; BWSearchCPU(W.vector, W.n, &backward, &forward, &rl_prev, &rl_next, &rl_prev_i, &rl_next_i, &rl_final, FRAGSIZE, 1); write_results(&rl_final, k, l, &ex, &backward, &forward, Worig, nW_aux, 2, output_file); rl_final.num_results=0; read_index++; } toc(); printf("Memory frees\n"); free(W.vector); free(Worig); free(k); free(l); free_bwt_index(NULL, &backward); free_bwt_index(NULL, &forward); free(rl_prev.list); free(rl_next.list); free(rl_prev_i.list); free(rl_next_i.list); free(rl_final.list); fclose(queries_file); fclose(output_file); return 0; }
ultranest_results ultranest(LikelihoodFunc, const char * root, const int ndim, const int max_samples, const double logZtol, const int nlive_points, unsigned int nsteps) { unsigned int i = 0; double tolerance = logZtol; int pbar_maxval = nlive_points; char pbar_label[200]; pbar_label[0] = 0; ultranest_draw_state * drawer = ultranest_draw_init(Like, ndim, nsteps, 1.); #ifdef ENABLE_PROGRESSBAR progressbar * pbar = progressbar_new("initialising...", pbar_maxval); pbar->format[1] = '='; #endif ultranest_state * sampler = ultranest_sampler_init(Like, root, ndim, nlive_points, drawer); #ifdef ENABLE_PROGRESSBAR progressbar_update_label(pbar, "sampling..."); progressbar_update(pbar, i); #endif point * current = ultranest_sampler_next(sampler); /* begin integration */ double logVolremaining = 0; double logwidth = log(1 - exp(-1. / sampler->nlive_points)); weighted_point * weights = NULL; ultranest_results res; res.root = root; double wi = logwidth + current->L; double logZ = wi; double H = current->L - logZ; double logZerr; while(1) { logwidth = log(1 - exp(-1. / sampler->nlive_points)) + logVolremaining; logVolremaining -= 1. / sampler->nlive_points; weights = (weighted_point *) realloc(weights, (i+sampler->nlive_points+1) * sizeof(weighted_point)); weights[i].p = current; weights[i].weight = logwidth; i = i + 1; logZerr = sqrt(H / sampler->nlive_points); // double i_final = -sampler->nlive_points * (-sampler->Lmax + logsubexp(fmax(tolerance - logZerr, logZerr / 100.) + logZ, logZ)); // i_final = -sampler.nlive_points * (-sampler.Lmax + log(exp(max(tolerance - logZerr, logZerr / 100.) + logZ) - exp(logZ))) assert(fmax(tolerance - logZerr, logZerr / 100.) > 0); assert(fmax(tolerance - logZerr, logZerr / 100.) + logZ > logZ); int i_final = -(sampler->nlive_points * (-sampler->Lmax + logsubexp(logZ, fmax(tolerance - logZerr, logZerr / 100.)))); pbar_maxval = (int) fmin(fmax(i+1, i_final), i+100000); ultranest_sampler_integrate_remainder(sampler, logwidth, logVolremaining, logZ, NULL); progressbar_settext(pbar_label, i, pbar_maxval, sampler->nlive_points, sampler->ndraws, logZ, sampler->remainderZ, logZerr, sampler->remainderZerr, current, sampler->ndim); #ifdef ENABLE_PROGRESSBAR progressbar_update_label(pbar, pbar_label); pbar->max = pbar_maxval; progressbar_update(pbar, i); #else printf("%s\n", pbar_label); #endif if (i > sampler->nlive_points) { // tolerance double total_error = logZerr + sampler->remainderZerr; if (max_samples > 0 && (unsigned) max_samples < sampler->ndraws) { #ifdef ENABLE_PROGRESSBAR progressbar_finish(pbar); #endif printf("maximum number of samples reached\n"); break; } if (total_error < tolerance) { #ifdef ENABLE_PROGRESSBAR progressbar_finish(pbar); #endif printf("tolerance reached\n"); break; } // we want to make maxContribution as small as possible // but if it becomes 10% of logZerr, that is enough if (sampler->remainderZerr < logZerr / 10.) { #ifdef ENABLE_PROGRESSBAR progressbar_finish(pbar); #endif printf("tolerance will not improve: remainder error (%.3f) is much smaller than systematic errors (%.3f)\n", sampler->remainderZerr, logZerr); break; } } current = ultranest_sampler_next(sampler); wi = logwidth + current->L; double logZnew = logaddexp(logZ, wi); H = exp(wi - logZnew) * current->L + exp(logZ - logZnew) * (H + logZ) - logZnew; logZ = logZnew; } // not needed for integral, but for posterior samples, otherwise there // is a hole in the most likely parameter ranges. i += ultranest_sampler_integrate_remainder(sampler, logwidth, logVolremaining, logZ, weights + i); logZerr += sampler->remainderZerr; logZ = logaddexp(logZ, sampler->remainderZ); res.logZ = logZ; res.logZerr = logZerr; res.ndraws = sampler->ndraws; res.niter = i; res.H = H; res.weighted_points = weights; printf("ULTRANEST result: lnZ = %.2f +- %.2f\n", res.logZ, res.logZerr); write_results(root, res, ndim); return res; }
/* * Main function for doing DNS lookups. */ int do_dns_lookups(void) { int i = 0; int ret = 0; int hostcount = 0; thread_params t1_params, t2_params, t3_params, t4_params, t5_params; void *t1_status, *t2_status, *t3_status, *t4_status, *t5_status; result *list_iterator; result *result_all; workitem *wi_start, *wi_t1, *wi_t2, *wi_t3, *wi_t4, *wi_t5; result_all = NULL; list_iterator = NULL; wi_start = NULL; wi_t1 = NULL; wi_t2 = NULL; wi_t3 = NULL; wi_t4 = NULL; wi_t5 = NULL; /* Display some info */ logline(LOG_INFO, "Run configuration:"); logline(LOG_INFO, " Using DNS servers:"); while (params->servers[i] != '\0') { logline(LOG_INFO, " %s", params->servers[i]); i++; } if (params->domain) logline(LOG_INFO, " Using domain : %s", params->domain); if (params->inputfile) logline(LOG_INFO, " Using input file : %s", params->inputfile); if (params->outputfile) logline(LOG_INFO, " Using output file : %s", params->outputfile); if (params->reverse) logline(LOG_INFO, " DNS lookup mode : Reverse"); else logline(LOG_INFO, " DNS lookup mode : Forward"); switch (params->loglevel) { case 1: logline(LOG_INFO, " Log Level : Error"); break; case 2: logline(LOG_INFO, " Log Level : Info"); break; case 3: logline(LOG_INFO, " Log Level : Debug"); break; default: logline(LOG_INFO, " Log Level : Error"); } /* Check work items prior to processing */ logline(LOG_INFO, "Checking input file..."); if (params->reverse) { /* File must contain a bunch of ip addresses */ ret = check_input_file_ip(); } else { /* File must contain host names */ ret = check_input_file_host(); } switch (ret) { case 0: logline(LOG_INFO, "Input file check successful. Data seems to be in required format."); break; case -1: case -2: logline(LOG_INFO, "There is a problem with the input file format. Aborting."); break; case -3: logline(LOG_INFO, "The input file could not be opened. Are you sure the file exists?"); break; default: logline(LOG_INFO, "An unhandled error related to the input file occured."); } if (ret < 0) return -1; /* Load work items into linked list */ logline(LOG_INFO, "Processing starts now, stay tuned..."); logline(LOG_DEBUG, " Loading work items..."); load_workitems(params->inputfile, &wi_start, params->reverse); logline(LOG_DEBUG, " %d work items loaded from file", count_workitems(wi_start)); /* Distribute workitems among threads */ logline(LOG_DEBUG, " Distributing work items among threads..."); dist_workitems(&wi_start, &wi_t1, &wi_t2, &wi_t3, &wi_t4, &wi_t5); logline(LOG_DEBUG, " Work items distributed"); logline(LOG_DEBUG, " Thread 1: Work item count = %d", count_workitems(wi_t1)); logline(LOG_DEBUG, " Thread 2: Work item count = %d", count_workitems(wi_t2)); logline(LOG_DEBUG, " Thread 3: Work item count = %d", count_workitems(wi_t3)); logline(LOG_DEBUG, " Thread 4: Work item count = %d", count_workitems(wi_t4)); logline(LOG_DEBUG, " Thread 5: Work item count = %d", count_workitems(wi_t5)); /* Prepare data structures for threads */ t1_params.thread_id = 1; t1_params.wi_list = wi_t1; t1_params.reverse = params->reverse; t1_params.result_list = NULL; t1_params.server = get_random_server(); t2_params.thread_id = 2; t2_params.wi_list = wi_t2; t2_params.reverse = params->reverse; t2_params.result_list = NULL; t2_params.server = get_random_server(); t3_params.thread_id = 3; t3_params.wi_list = wi_t3; t3_params.reverse = params->reverse; t3_params.result_list = NULL; t3_params.server = get_random_server(); t4_params.thread_id = 4; t4_params.wi_list = wi_t4; t4_params.reverse = params->reverse; t4_params.result_list = NULL; t4_params.server = get_random_server(); t5_params.thread_id = 5; t5_params.wi_list = wi_t5; t5_params.reverse = params->reverse; t5_params.result_list = NULL; t5_params.server = get_random_server(); if (pthread_create(&t1, NULL, proc_workitems, &t1_params)) { logline(LOG_ERROR, " Thread 1: Could not be created"); return -1; } else { logline(LOG_DEBUG, " Thread 1: Created"); } if (pthread_create(&t2, NULL, proc_workitems, &t2_params)) { logline(LOG_ERROR, " Thread 2: Could not be created"); return -1; } else { logline(LOG_DEBUG, " Thread 2: Created"); } if (pthread_create(&t3, NULL, proc_workitems, &t3_params)) { logline(LOG_ERROR, " Thread 3: Could not be created"); return -1; } else { logline(LOG_DEBUG, " Thread 3: Created"); } if (pthread_create(&t4, NULL, proc_workitems, &t4_params)) { logline(LOG_ERROR, " Thread 4: Could not be created"); return -1; } else { logline(LOG_DEBUG, " Thread 4: Created"); } if (pthread_create(&t5, NULL, proc_workitems, &t5_params)) { logline(LOG_ERROR, " Thread 5: Could not be created"); return -1; } else { logline(LOG_DEBUG, " Thread 5: Created"); } /* Wait for threads to finish */ pthread_join(t1, &t1_status); pthread_join(t2, &t2_status); pthread_join(t3, &t3_status); pthread_join(t4, &t4_status); pthread_join(t5, &t5_status); /* Extract results out of threads */ if ((int *)t1_status < 0) { logline(LOG_ERROR, " Thread 1: An error occurred"); } else { /* Extract results from thread 1 */ logline(LOG_DEBUG, " Thread 1: Finished successfully"); } if ((int *)t2_status < 0) { logline(LOG_ERROR, " Thread 2: An error occurred"); } else { /* Extract results from thread 2 */ logline(LOG_DEBUG, " Thread 2: Finished successfully"); } if ((int *)t3_status < 0) { logline(LOG_ERROR, " Thread 3: An error occurred"); } else { /* Extract results from thread 3 */ logline(LOG_DEBUG, " Thread 3: Finished successfully"); } if ((int *)t4_status < 0) { logline(LOG_ERROR, " Thread 4: An error occurred"); } else { /* Extract results from thread 4 */ logline(LOG_DEBUG, " Thread 4: Finished successfully"); } if ((int *)t5_status < 0) { logline(LOG_ERROR, " Thread 5: An error occurred"); } else { /* Extract results from thread 5 */ logline(LOG_DEBUG, " Thread 5: Finished successfully"); } /* Consolidate results */ if (result_all == NULL) { result_all = t1_params.result_list; } else { list_iterator = result_all; while (list_iterator->next) { list_iterator = list_iterator->next; } list_iterator->next = t1_params.result_list; } if (result_all == NULL) { result_all = t2_params.result_list; } else { list_iterator = result_all; while (list_iterator->next) { list_iterator = list_iterator->next; } list_iterator->next = t2_params.result_list; } if (result_all == NULL) { result_all = t3_params.result_list; } else { list_iterator = result_all; while (list_iterator->next) { list_iterator = list_iterator->next; } list_iterator->next = t3_params.result_list; } if (result_all == NULL) { result_all = t4_params.result_list; } else { list_iterator = result_all; while (list_iterator->next) { list_iterator = list_iterator->next; } list_iterator->next = t4_params.result_list; } if (result_all == NULL) { result_all = t5_params.result_list; } else { list_iterator = result_all; while (list_iterator->next) { list_iterator = list_iterator->next; } list_iterator->next = t5_params.result_list; } logline(LOG_INFO, "Finished processing data."); logline(LOG_INFO, "The following hosts have been identified:"); /* Print results on screen */ list_iterator = result_all; while (list_iterator) { hostcount++; logline(LOG_INFO, " Host: %s, IP: %s", list_iterator->host, list_iterator->ip); list_iterator = list_iterator->next; } if (hostcount == 0) { logline(LOG_INFO, " Unfortunately, no hosts have been found. Try again using different settings."); } else { logline(LOG_INFO, " %d hosts found.", hostcount); } /* Export results to text file */ if ((params->outputfile != NULL) && (hostcount > 0)) { logline(LOG_INFO, "Exporting data to %s...", params->outputfile); list_iterator = result_all; write_results(list_iterator); logline(LOG_INFO, "Export finished."); } logline(LOG_INFO, "Thank you for flying with us!"); }
/* Functions */ int main( int argc, char **argv ) { int eof = 0; FILE *in, *out; int op; /* read (0) or write (1) */ /* Check for arguments */ if ( argc < 4 ) { /* Complain, explain, and exit */ fprintf( stderr, "missing or bad command line arguments\n" ); fprintf( stderr, USAGE ); exit( -1 ); } /* open the input file and return the file descriptor */ if (( in = fopen( argv[1], "r" )) < 0 ) { fprintf( stderr, "input file open failure\n" ); return -1; } /* Initialization */ /* for example: build optimal list */ page_replacement_init( in, atoi(argv[3]) ); /* execution loop */ while ( TRUE ) { int pid; unsigned int vaddr, paddr; int valid; /* get memory access */ if ( get_memory_access( in, &pid, &vaddr, &op, &eof )) { fprintf( stderr, "get_memory_access\n" ); exit( -1 ); } /* done at eof */ if ( eof ) break; total_accesses++; /* if memory access count reaches window size, update working set bits */ processes[pid].ct++; /* check if need to context switch */ if (( !current_pid ) || ( pid != current_pid )) { if ( context_switch( pid )) { fprintf( stderr, "context_switch\n" ); exit( -1 ); } } /* lookup mapping in TLB */ if ( !tlb_resolve_addr( vaddr, &paddr, op )) { pt_resolve_addr( vaddr, &paddr, &valid, op ); /* if invalid, update page tables (w/ replacement, if necessary) */ if ( !valid ) pt_demand_page( pid, vaddr, &paddr, op, atoi(argv[3]) ); } } /* close the input file */ fclose( in ); /* open the output file and return the file descriptor */ if (( out = fopen( argv[2], "w+" )) < 0 ) { fprintf( stderr, "write output info\n" ); return -1; } write_results( out ); exit( 0 ); }
/* save results */ static void save_results_table(void) { int rows,cols,n=40,length,c; WINDOW *mywin; FILE *outfile; DIR *mydir; struct dirent *mydirent; char fname[n+1]; rows = (LINES - 3) / 2; length = strlen(save_table_str) + n + 2; cols = (COLS - length) / 2; /* create input window */ mywin = subwin(stdscr,3,length,rows,cols); keypad(mywin,TRUE); wattrset(mywin,COLOR_PAIR(BG_PAIR)); /* setup colors */ wbkgdset(mywin,COLOR_PAIR(BG_PAIR)); werase(mywin); /* erase and color window */ mvwaddstr(mywin,1,1,save_table_str); length = strlen(save_table_str) + 1; box(mywin,0,0); wrefresh(mywin); echo(); mvwgetnstr(mywin,1,length,fname,n); noecho(); /* open current directory */ mydir = opendir("."); if (mydir == NULL ) { werase(mywin); mvwaddstr(mywin,1,1,opendir_err); box(mywin,0,0); wrefresh(mywin); while ( (c = mvwgetch(mywin,1,strlen(save_file_exists)+1)) ) { if(c == 'n' || c == 'N') { delwin(mywin); return; } } } /* check existing files */ while( (mydirent = readdir(mydir)) != NULL ) { if( strcmp(fname,mydirent->d_name) == 0 ) { werase(mywin); mvwaddstr(mywin,1,1,save_file_exists); box(mywin,0,0); wrefresh(mywin); while ( (c = mvwgetch(mywin,1,strlen(save_file_exists)+1)) ) { if(c == 'n' || c == 'N') { delwin(mywin); closedir(mydir); return; } else if (c == 'y' || c == 'Y') break; } break; } } closedir(mydir); /* open output file */ errno = 0; outfile = fopen(fname,"w"); if (errno) { werase(mywin); mvwaddstr(mywin,1,1,save_table_err); box(mywin,0,0); wrefresh(mywin); while( (c = mvwgetch(mywin,1,strlen(save_table_err+1))) ) { if( c == 13 ) { delwin(mywin); return; } } } /* write results */ write_results(outfile); fclose(outfile); delwin(mywin); return; }
/* * Accept as parameter: * - input file * - algorithm * - S: serial * - P: Pthread parallel * - O: OpenMP parallel * - verbose (show data in console) * - # of threads * * Main steps * 1. Read matrix from file * 2. Solve linear system using Jacobi Method * 3. Write output * * Output * Result file with statistics */ int main(int argc, char *argv[]) { if ( argc != 5 ) { puts("Inform input file and number of threads!"); exit(1); } //algorithm char algorithm = argv[2][0]; //# of threads int thread_count = strtol(argv[3], NULL, 10); //console output level int verbose = strtol(argv[4], NULL, 10); if (verbose) puts("---BEGIN---"); //prints info if (verbose) printf("Input file: '%s', thread count: %i, algorithm: %c\n\n", argv[1], thread_count, algorithm); //loads matrix matrix *m = matrix_load(argv[1]); //prints matrix if (verbose) matrix_print(m); //starts timer timer* t = start_timer(); jacobi_result* result; switch (algorithm) { case 'P': // pthread parallel result = jacobi_parallel_pthread_better(m, thread_count, verbose); break; case 'O': // OpenMP parallel result = jacobi_parallel_omp(m, thread_count, verbose); break; /* case 'M': // MPI parallel break; */ case 'S': // serial default: result = jacobi_serial(m, verbose); } //Sleep(500); //stops timer stop_timer(t, verbose); //prints result if (verbose) { int i; printf("\nResults: "); for (i = 0; i < m->size && i < 200; i++) { printf("%f, ", result->x[i]); } printf("\nIterations: %i ", result->k); } //saves results write_results(t, argv[1], thread_count, algorithm, m->size); //frees matrix matrix_destroy(m); //frees timer free(t); //frees result //free(result->x); free(result); if (verbose) puts("\n\n---END---"); return EXIT_SUCCESS; }