int main(int argc, char **argv) { global_options(&argc, &argv); if (argc < 5) { print_help(); m4ri_die(""); } struct smallops_params params; params.k = atoi(argv[1]); params.m = atoi(argv[2]); params.n = atoi(argv[3]); srandom(17); unsigned long long data[2]; if(strcmp(argv[4],"mzed_slice") == 0) { run_bench(run_mzed_slice, (void*)¶ms, data, 2); } else if(strcmp(argv[4],"mzed_cling") == 0) { run_bench(run_mzed_cling, (void*)¶ms, data, 2); } else if(strcmp(argv[4],"mzed_add") == 0) { run_bench(run_mzed_add, (void*)¶ms, data, 2); } double cc_per_op = ((double)data[1])/ ( (double)params.m * (double)params.n ); printf("%s: m: %5d, n: %5d, cpu cycles: %10llu, cc/(mn): %.5lf, wall time: %lf\n", argv[4], params.m, params.n, data[1], cc_per_op, data[0] / 1000000.0); }
int main(int argc, char *argv[]) { /* For process.h to function. */ ARGC = argc; ARGV = argv; /* Do not remove this umask. Always keep at top. */ umask(0077); load_saved_environment(); if (argc >= 2 && argv[1][0] != '-') return process_command(argc - 1, argv + 1); return global_options(argc, argv); }
int main(int argc, char **argv) { global_options(&argc, &argv); if (argc != 3) { m4ri_die("Parameters m, n expected.\n"); } struct trsm_params p; p.m = atoi(argv[1]); p.n = atoi(argv[2]); srandom(17); unsigned long long data[2]; run_bench(run, (void*)&p, data, 2); printf("m: %5d, n: %5d, cpu cycles: %llu wall time: %lf\n", p.m, p.n, data[1], data[0] / 1000000.0); }
int main(int argc, char **argv) { long nod, buffer; float qerror; char *in_data_file; char *in_code_file; struct teach_params teach; int qmode; struct entries *data, *codes; global_options(argc, argv); if (extract_parameter(argc, argv, "-help", OPTION2)) { printhelp(); exit(0); } in_data_file = extract_parameter(argc, argv, IN_DATA_FILE, ALWAYS); in_code_file = extract_parameter(argc, argv, IN_CODE_FILE, ALWAYS); buffer = oatoi(extract_parameter(argc, argv, "-buffer", OPTION), 0); teach.radius = oatof(extract_parameter(argc, argv, TRAINING_RADIUS, OPTION), 1.0); qmode = oatoi(extract_parameter(argc, argv, "-qetype", OPTION), 0); label_not_needed(1); ifverbose(2) fprintf(stdout, "Input entries are read from file %s\n", in_data_file); data = open_entries(in_data_file); if (data == NULL) { fprintf(stderr, "Can't open datafile: %s\n", in_data_file); exit(1); } ifverbose(2) fprintf(stdout, "Codebook entries are read from file %s\n", in_code_file); codes = open_entries(in_code_file); if (codes == NULL) { fprintf(stderr, "Can't open code file '%s'\n", in_code_file); close_entries(data); exit(1); } if (codes->topol < TOPOL_HEXA) { fprintf(stderr, "File %s is not a map file\n", in_code_file); close_entries(data); close_entries(codes); exit(1); } if (data->dimension != codes->dimension) { fprintf(stderr, "Data and codebook vectors have different dimensions (%d != %d)", data->dimension, codes->dimension); close_entries(data); close_entries(codes); exit(1); } set_teach_params(&teach, codes, data, buffer); set_som_params(&teach); if (qmode > 0) qerror = find_qerror2(&teach); else qerror = find_qerror(&teach); nod = teach.data->num_entries; ifverbose(1) fprintf(stdout, "Quantization error of %s with map %s is %f per sample (%d samples)\n", in_data_file, in_code_file, qerror / (float) nod, nod); else
int main(int argc, char **argv) { char *in_name, *out_name, *s; struct umatrix *umat; struct eps_info einfo; int average = 0; int median = 0; FILE *out_fp; struct file_info *out_fi; global_options(argc, argv); if (extract_parameter(argc, argv, "-help", OPTION2)) { printhelp(); exit(0); } in_name = NULL; out_name = NULL; /* default page size is A4 */ set_paper(get_paper_by_id(PAPER_A4)); /* parse args */ if (extract_parameter(argc, argv, "-border", OPTION2)) doborder = 1; if (extract_parameter(argc, argv, "-portrait", OPTION2)) orientation = PORTRAIT; if (extract_parameter(argc, argv, "-landscape", OPTION2)) orientation = LANDSCAPE; if (extract_parameter(argc, argv, "-ps", OPTION2)) mode = OUTPUT_PS; if (extract_parameter(argc, argv, "-eps", OPTION2)) mode = OUTPUT_EPS; white_treshold = oatof(extract_parameter(argc, argv, "-W", OPTION), 1.0); black_treshold = oatof(extract_parameter(argc, argv, "-B", OPTION), 0.0); out_name = extract_parameter(argc, argv, "-o", OPTION); if (mode == 0) mode = guess_mode(out_name); if ((s = extract_parameter(argc, argv, "-font", OPTION))) fontname = s; fontsize = oatof(extract_parameter(argc, argv, "-fontsize", OPTION), -1.0); title = extract_parameter(argc, argv, "-title", OPTION); if (extract_parameter(argc, argv, "-notitle", OPTION2)) notitle = 1; if ((s = extract_parameter(argc, argv, "-paper", OPTION))) { struct paper_info *p = get_paper_by_name(s); if (p == NULL) { fprintf(stderr, "Unknown paper type: %s\n", s); exit(1); } set_paper(p); } if (extract_parameter(argc, argv, "-average", OPTION2)) average = 1; if (extract_parameter(argc, argv, "-median", OPTION2)) median = 1; if (extract_parameter(argc, argv, "-onlylabs", OPTION2)) drawblocks = 0; if (extract_parameter(argc, argv, "-nolabs", OPTION2)) drawlabels = 0; in_name = extract_parameter(argc, argv, IN_CODE_FILE, ALWAYS); if ((s = getenv("UMAT_HEADERFILE"))) headerfile = s; if ((s = extract_parameter(argc, argv, "-headerfile", OPTION))) headerfile = s; label_not_needed(1); if ((umat = read_map(in_name, 0, 0)) == NULL) { fprintf(stderr, "Can't load file\n"); exit(1); } calc_umatrix(umat, 0, 0); if (average) average_umatrix(umat); if (median) median_umatrix(umat); if (mode == 0) mode = OUTPUT_EPS; if (orientation == BEST) orientation = (umat->mxdim >= umat->mydim) ? LANDSCAPE : PORTRAIT; if ((out_fi = open_file(out_name, "w")) == NULL) { fprintf(stderr, "can't open output file\n"); free_umat(umat); exit(1); } out_fp = fi2fp(out_fi); einfo.umat = umat; einfo.title = title ? title : in_name; image_size(&einfo, 0); if (mode == OUTPUT_EPS) print_eps(out_fp, &einfo); else print_page(out_fp, &einfo); free_umat(umat); umat = NULL; if (out_fi) close_file(out_fi); return 0; }
int main(int argc, char **argv) { int opts = global_options(&argc, &argv); int data_len; #ifdef HAVE_LIBPAPI int papi_counters = PAPI_num_counters(); if (papi_counters < papi_array_len) { fprintf(stderr, "%s: Warning: there are only %d hardware counters available!\n", progname, papi_counters); papi_array_len = papi_counters; } if (papi_test(papi_events, papi_array_len)) exit(1); for (int nv = 0; nv <= papi_array_len; ++nv) loop_calibration[nv] = 100000000; data_len = papi_array_len + 1; #else data_len = 2; #endif if (opts < 0 || argc < 2 || argc > 5) { print_help_and_exit(); } struct elim_params params; params.m = atoi(argv[1]); if (argc >= 3) params.n = atoi(argv[2]); else params.n = params.m; if (argc >= 4) params.algorithm = argv[3]; else params.algorithm = "ple"; if (argc >= 5) params.r = atoi(argv[4]); else params.r = MIN(params.m, params.n); srandom(17); unsigned long long data[16]; for (int i = 0; i < 4; ++i) run_nothing((void*)¶ms, data, &data_len); run_bench(run, (void*)¶ms, data, data_len); double cc_per_op = ((double)data[1])/ ( (double)params.m * (double)params.n * powl((double)params.r,0.807) ); printf("m: %5d, n: %5d, last r: %5d, cpu cycles: %12llu, cc/(mnr^0.807): %.5lf, ", params.m, params.n, params.r, data[1], cc_per_op); print_wall_time(data[0] / 1000000.0); printf(", "); print_cpu_time(data[1] / (double)cpucycles_persecond()); printf("\n"); #ifdef HAVE_LIBPAPI for (int n = 1; n < data_len; ++n) { double tmp = ((double)data[n]) / powl((double)params.n,2.807); printf("%20s (%20llu) per bit (divided by n^2.807): %15.5f\n", papi_event_name(papi_events[n - 1]), data[n], tmp); } #endif }
void parse_config(char *name, char *parameter) { #ifdef CONFDIR char *default_config_file=CONFDIR "/stunnel.conf"; #else char *default_config_file="stunnel.conf"; #endif FILE *fp; char line[STRLEN], *arg, *opt, *errstr, *filename; int line_number, i; LOCAL_OPTIONS *section, *new_section; memset(&options, 0, sizeof(GLOBAL_OPTIONS)); /* reset global options */ memset(&local_options, 0, sizeof(LOCAL_OPTIONS)); /* reset local options */ local_options.next=NULL; section=&local_options; global_options(CMD_INIT, NULL, NULL); service_options(CMD_INIT, section, NULL, NULL); if(!name) name=default_config_file; if(!strcasecmp(name, "-help")) { global_options(CMD_HELP, NULL, NULL); service_options(CMD_HELP, section, NULL, NULL); exit(1); } if(!strcasecmp(name, "-version")) { log_raw("%s", stunnel_info()); log_raw(" "); global_options(CMD_DEFAULT, NULL, NULL); service_options(CMD_DEFAULT, section, NULL, NULL); exit(1); } if(!strcasecmp(name, "-sockets")) { print_socket_options(); exit(1); } #ifndef USE_WIN32 if(!strcasecmp(name, "-fd")) { if(!parameter) { log_raw("No file descriptor specified"); syntax(default_config_file); } for(arg=parameter, i=0; *arg; arg++) { if(*arg<'0' || *arg>'9') { log_raw("Invalid file descriptor %s", parameter); syntax(default_config_file); } i=10*i+*arg-'0'; } fp=fdopen(i, "r"); if(!fp) { log_raw("Invalid file descriptor %s", parameter); syntax(default_config_file); } filename="descriptor"; } else #endif { fp=fopen(name, "r"); if(!fp) { #ifdef USE_WIN32 /* Win32 doesn't seem to set errno in fopen() */ log_raw("Failed to open configuration file %s", name); #else ioerror(name); #endif syntax(default_config_file); } filename=name; } line_number=0; while(fgets(line, STRLEN, fp)) { line_number++; opt=line; while(isspace(*opt)) opt++; /* remove initial whitespaces */ for(i=strlen(opt)-1; i>=0 && isspace(opt[i]); i--) opt[i]='\0'; /* remove trailing whitespaces */ if(opt[0]=='\0' || opt[0]=='#') /* empty line or comment */ continue; if(opt[0]=='[' && opt[strlen(opt)-1]==']') { /* new section */ errstr=section_validate(section); if(errstr) { log_raw("file %s line %d: %s", filename, line_number, errstr); exit(1); } opt++; opt[strlen(opt)-1]='\0'; new_section=calloc(1, sizeof(LOCAL_OPTIONS)); if(!new_section) { log_raw("Fatal memory allocation error"); exit(2); } memcpy(new_section, &local_options, sizeof(LOCAL_OPTIONS)); new_section->servname=stralloc(opt); new_section->next=NULL; section->next=new_section; section=new_section; continue; } arg=strchr(line, '='); if(!arg) { log_raw("file %s line %d: No '=' found", filename, line_number); exit(1); } *arg++='\0'; /* split into option name and argument value */ for(i=strlen(opt)-1; i>=0 && isspace(opt[i]); i--) opt[i]='\0'; /* remove trailing whitespaces */ while(isspace(*arg)) arg++; /* remove initial whitespaces */ errstr=service_options(CMD_EXEC, section, opt, arg); if(section==&local_options && errstr==option_not_found) errstr=global_options(CMD_EXEC, opt, arg); if(errstr) { log_raw("file %s line %d: %s", filename, line_number, errstr); exit(1); } } errstr=section_validate(section); if(errstr) { log_raw("file %s line %d: %s", filename, line_number, errstr); exit(1); } fclose(fp); if(!local_options.next && section->option.accept) { log_raw("accept option is not allowed in inetd mode"); log_raw("remove accept option or define a [section]"); exit(1); } if(!options.option.client) options.option.cert=1; /* Server always needs a certificate */ if(!options.option.foreground) options.option.syslog=1; }
int main(int argc, char **argv) { int not, bnot, error; int xdim, ydim; int topol, neigh; float alpha1, radius1; int fixed, weights; float alpha2, radius2; float qerror, qerrorb; char *in_data_file, *in_test_file, *out_code_file, *alpha_s; struct entries *data = NULL; struct entries *testdata = NULL; struct entries *codes = NULL; struct entries *codess = NULL; struct entries *tmp; struct teach_params params; long buffer, length1, length2, noc, nod; int qmode; struct typelist *type_tmp; error = 0; global_options(argc, argv); print_description(); not = get_int("Give the number of trials", 0); in_data_file = get_str("Give the input data file name"); in_test_file = get_str("Give the input test file name"); out_code_file = get_str("Give the output map file name"); topol = topol_type(get_str("Give the topology type")); if (topol == TOPOL_UNKNOWN) { ifverbose(2) fprintf(stderr, "Unknown topology type, using hexagonal\n"); topol = TOPOL_HEXA; } neigh = neigh_type(get_str("Give the neighborhood type")); if (neigh == NEIGH_UNKNOWN) { ifverbose(2) fprintf(stderr, "Unknown neighborhood type, using bubble\n"); neigh = NEIGH_BUBBLE; } xdim = get_int("Give the x-dimension", 0); ydim = get_int("Give the y-dimension", 0); length1 = get_int("Give the training length of first part", 0); alpha1 = get_float("Give the training rate of first part", 0.0); radius1 = get_float("Give the radius in first part", 0.0); length2 = get_int("Give the training length of second part", 0); alpha2 = get_float("Give the training rate of second part", 0.0); radius2 = get_float("Give the radius in second part", 0.0); printf("\n"); fixed = (int) oatoi(extract_parameter(argc, argv, FIXPOINTS, OPTION), 0); weights = (int) oatoi(extract_parameter(argc, argv, WEIGHTS, OPTION), 0); buffer = oatoi(extract_parameter(argc, argv, "-buffer", OPTION), 0); alpha_s = extract_parameter(argc, argv, "-alpha_type", OPTION); qmode = oatoi(extract_parameter(argc, argv, "-qetype", OPTION), 0); use_fixed(fixed); use_weights(weights); label_not_needed(1); ifverbose(2) fprintf(stderr, "Input entries are read from file %s\n", in_data_file); data = open_entries(in_data_file); if (data == NULL) { fprintf(stderr, "Can't open data file '%s'\n", in_data_file); error = 1; goto end; } set_buffer(data, buffer); ifverbose(2) fprintf(stderr, "Test entries are read from file %s\n", in_test_file); testdata = open_entries(in_test_file); if (testdata == NULL) { fprintf(stderr, "Can't open test data file '%s'\n", in_test_file); error = 1; goto end; } set_buffer(testdata, buffer); noc = xdim * ydim; if (noc <= 0) { fprintf(stderr, "Dimensions of map (%d %d) are incorrect\n", xdim, ydim); error = 1; goto end; } if (xdim < 0) { fprintf(stderr, "Dimensions of map (%d %d) are incorrect\n", xdim, ydim); error = 1; goto end; } if (alpha_s) { type_tmp = get_type_by_str(alpha_list, alpha_s); if (type_tmp->data == NULL) { fprintf(stderr, "Unknown alpha type %s\n", alpha_s); error = 1; goto end; } } else type_tmp = get_type_by_id(alpha_list, ALPHA_LINEAR); params.alpha_type = type_tmp->id; params.alpha_func = type_tmp->data; codess = NULL; qerrorb = FLT_MAX; bnot = 0; while (not) { init_random(not); ifverbose(2) fprintf(stderr, "Initializing codebook\n"); codes = randinit_codes(data, topol, neigh, xdim, ydim); if (codes == NULL) { fprintf(stderr, "Error initializing random codebook, aborting\n"); error = 1; goto end; } set_teach_params(¶ms, codes, NULL, 0); set_som_params(¶ms); params.data = data; params.length = length1; params.alpha = alpha1; params.radius = radius1; ifverbose(2) fprintf(stderr, "Training map, first part, rlen: %ld alpha: %f\n", params.length, params.alpha); codes = som_training(¶ms); params.length = length2; params.alpha = alpha2; params.radius = radius2; ifverbose(2) fprintf(stderr, "Training map, second part, rlen: %ld alpha: %f\n", params.length, params.alpha); codes = som_training(¶ms); params.data = testdata; ifverbose(2) fprintf(stderr, "Calculating quantization error\n"); if (qmode > 0) qerror = find_qerror2(¶ms); else qerror = find_qerror(¶ms); nod = testdata->num_entries; if (qerror < qerrorb) { qerrorb = qerror; bnot = not; tmp = codess; codess = codes; codes = tmp; } close_entries(codes); codes = NULL; ifverbose(1) fprintf(stderr, "%3d: %f\n", not, qerror/(float) nod); not--; } if (codess != NULL) { ifverbose(2) fprintf(stdout, "Codebook entries are saved to file %s\n", out_code_file); save_entries(codess, out_code_file); ifverbose(1) fprintf(stdout, "Smallest error with random seed %3d: %f\n", bnot, qerrorb/(float) nod); } end: if (codess) close_entries(codess); if (data) close_entries(data); if (testdata) close_entries(testdata); return(error); }