int main(int argc, char **argv) { const char *fin = argv[1]; const char *fout1 = argv[2]; const char *fout2 = argv[3]; struct timeval timer1, timer2; size_t D_dims[2], E_dims[2], Q_dims[2]; double *D = read_mat(fin, "D", D_dims); double *E = read_mat(fin, "E", E_dims); double *Q; int N = (D_dims[0] > D_dims[1]) ? (int)D_dims[0] : (int)D_dims[1]; double *WORK; int *IWORK; Q_dims[0] = Q_dims[1] = (size_t)N; Q = (double *)malloc(N * N * sizeof(double)); WORK = (double *)malloc((2 * N + 2 * N * N) * sizeof(double)); IWORK = (int *)malloc((3 + 5 * N) * sizeof(int)); gettimeofday(&timer1, NULL); dlaed0(N, D, E, Q, N, WORK, IWORK); gettimeofday(&timer2, NULL); printf("Time: %.3lf s\n", GetTimerValue(timer1, timer2) / 1000.0 ); write_mat(fout1, "D", D, D_dims); write_mat(fout2, "Q", Q, Q_dims); return 0; }
int main() { int a[128][128], b[128][128], c[128][128]; read_mat(a); read_mat(b); if (mul(a,b,c)) print(c); else printf("Nu se inmulteste!\n"); return 0; }
// load a matrix from file "n" into matrix A // returns 0: success, <0 failure int load_matrix( char* n, matrix_t* A ) { assert( A != NULL ); if ( n == NULL ) { fprintf( stderr, "input error: No input specified (-i)\n" ); return 1; // failure } // make sure we don't have a memory leak clear_matrix(A); int ret; enum sparse_matrix_file_format_t ext; if (( ret = _identify_format_from_extension( n, &ext, 1 ) ) != 0 ) return ret; switch(ext) { case MATRIX_MARKET: ret = readmm( n, A, NULL ); break; // NULL = ignore comments case MATLAB: ret = read_mat( n, A ); break; case HARWELL_BOEING: ret = 100; assert(0); break; // shouldn't be able to get here } if ( ret != 0 ) { fprintf( stderr, "input error: Failed to load matrix\n"); // TODO move these printouts to main... return ret; } if(A->sym == SM_UNSYMMETRIC) detect_matrix_symmetry( A ); return 0; // success }
bool Spectrum2D::_read_file(std::string name, std::string format) { if (format == "m4b") return read_m4b(name); else if (format == "mat") return read_mat(name); else return false; }
int main() { int n, verify; int matrix[MAX_N][MAX_N]; int col_max[MAX_N]; verify = scanf("%d", &n); if ((verify != 1) || (n > 20) || (n < 1)) invalid_input(); exclude_com(); read_mat(matrix, n, col_max); printf("Os pontos de sela da matriz são:\n\n"); check_selas(matrix, col_max, n); return 0; }
void test_rnw(hid_t fapl) { size_t dim0, dim1; int i, j, k; int x, y; clock_t b, e; double file_open_time, file_close_time; double dataset_open_time, dataset_close_time; double read_time, write_time; file_open_time = 0; file_close_time = 0; dataset_open_time = 0; dataset_close_time = 0; read_time = 0; write_time = 0; for (dim0 = DIM0_START; dim0 <= DIM0_LIM; dim0 *= 2) { for (dim1 = DIM1_START; dim1 <= DIM1_LIM; dim1 *= 2) { for (i = 0; i < LENGTH; i++) { // Open file b = clock(); hid_t file_id; file_id = open_file(fapl, FILE_NAME_RNW); e = clock(); file_open_time += (double) (e - b) / CLOCKS_PER_SEC; // get name of dataset char name[25]; sprintf(name, "dataset_%dx%d", dim0, dim1); // puts string into buffer // Open dataset b = clock(); hid_t dataset_id; dataset_id = open_dataset(file_id, name); e = clock(); dataset_open_time += (double) (e - b) / CLOCKS_PER_SEC; // READS AND WRITES double matrix[dim0][dim1]; for (k = 0; k < READS_AND_WRITES; k++) { b = clock(); read_mat(dataset_id, dim0, dim1, matrix); e = clock(); read_time += (double) (e - b) / CLOCKS_PER_SEC; // Modify the data at least a bit // just to eliminate any shortcuts. /* for (x = 0; x < dim0; x++) { for (y = 0; y < dim1; y++) { matrix[x][y] += 1; } } */ // NOTE: there don't seem to be any shortcuts b = clock(); write_mat(dataset_id, dim0, dim1, matrix); e = clock(); write_time += (double) (e - b) / CLOCKS_PER_SEC; } // Close dataset b = clock(); close_dataset(dataset_id); e = clock(); dataset_close_time += (double) (e - b) / CLOCKS_PER_SEC; // Close file b = clock(); close_file(file_id); e = clock(); file_close_time += (double) (e - b) / CLOCKS_PER_SEC; } } } printf("Executed an average-case read and write test with the following properties:\n"); printf("The experiment uses file: " FILE_NAME_RNW "\n"); printf("The experiment repeats %d times.\n", LENGTH); printf("Dim0 starting from %d and doubling until %d.\n", DIM0_START, DIM0_LIM); printf("Dim1 starting from %d and doubling until %d.\n", DIM1_START, DIM1_LIM); printf("Reading and writing a matrix %d times.\n", READS_AND_WRITES); double total_reads_and_writes; total_reads_and_writes = LENGTH * READS_AND_WRITES * (DIM0_LIM - DIM0_START) * (DIM1_LIM - DIM1_START); printf("This means a total of %.0lf doubles have been read and written.\n", total_reads_and_writes); printf("\n"); printf("Opening the file took a total of %f seconds.\n", file_open_time); printf("Closing the file took a total of %f seconds.\n", file_close_time); printf("Opening the dataset took a total of %f seconds.\n", dataset_open_time); printf("Closing the dataset took a total of %f seconds.\n", dataset_close_time); printf("Reading the data took a total of %f seconds.\n", read_time); printf("Writing the data took a total of %f seconds.\n", write_time); printf("This means that reading produces an average overhead of %f ns per double.\n", read_time / total_reads_and_writes * NANOSECONDS_IN_A_SECOND); printf("This means that writing produces an average overhead of %f ns per double.\n\n", write_time / total_reads_and_writes * NANOSECONDS_IN_A_SECOND); }
/*! * This function does the processing for the c_elegans class. * * It initializes the various matrices and reads values from the input files */ void c_elegans::postprocess(input& in){ rhs_type::postprocess(in); if(dimension != num_neur*2){ err("Dimension must be 558, which is double the number of neurons", "", "", FATAL_ERROR); } in.retrieve(beta, "beta", this); in.retrieve(tau, "tau", this); in.retrieve(gelec, "gelec", this); in.retrieve(gchem, "gchem", this); in.retrieve(memV, "memV", this); in.retrieve(memG, "memG", this); in.retrieve(EchemEx, "EchemEx", this); in.retrieve(EchemInh, "EchemInh", this); in.retrieve(ar, "ar", this); in.retrieve(ad, "ad", this); std::string ag_fname, a_fname; in.retrieve(ag_fname, "ag_mat", this); in.retrieve(a_fname, "a_mat", this); sparse_type a_m(num_neur, num_neur); ag_full.resize(num_neur, num_neur); laplacian.resize(num_neur, num_neur); read_mat(ag_fname, ag_full); read_mat(a_fname, a_m); //create transposed sparse matrix AEchem AEchem_trans_full.resize(num_neur, num_neur); AEchem_trans_full = a_m.transpose(); AEchem_trans.resize(num_neur, num_neur); //do any needed fake iterations, must make more general at some point size_t num_comb; int iterations; in.retrieve(num_comb, "num_comb", this); in.retrieve(iterations, "iterations", this); in.retrieve(cur_ind, "!start_ind", this); abl_neur.resize(num_comb); for(auto& val : abl_neur){ val = 0; } if(abl_neur.size() != 1){ next_comb(abl_neur, num_neur); } for(int i = 0; i < cur_ind; i++){ for(int j = 0; j < iterations; j++){ if(next_comb(abl_neur, num_neur)){ char ind_str[20];//won't ever have a 20 digit index //handy buffer to overflow for those hacking this. sprintf(ind_str, "%d", (int)cur_ind); err(std::string("Combinations exhausted in index ") + ind_str, "c_elegans::postprocess","rhs/c_elegans.cpp", FATAL_ERROR); } } } auto dat_inds = std::shared_ptr<writer>(new writer(true)); dat_inds->add_data(data::create("Ablations", abl_neur.data(), abl_neur.size()), writer::OTHER); holder->add_writer(dat_inds); //write first ablation data //set up dummy connection to toroidal controller for now controller* cont; in.retrieve(cont, "controller", this); auto val = std::make_shared<variable>(); val->setname("c_elegans_quickfix"); val->holder = holder; val->parse("0.1"); in.insert_item(val); cont->addvar(val); in.retrieve(dummy, val->name(), this); has_gone=true; //is true at first to allow update of zero index to occur first_round=true; update(); }
int main(int argc, char *argv[]) { struct rt_i *rtip = NULL; char db_title[TITLE_LEN+1];/* title from MGED file */ const char *tmp_str; extern char local_u_name[65]; extern double base2local; extern double local2base; FILE *fPtr; int Ch; /* Option name */ int mat_flag = 0; /* Read matrix from stdin? */ int use_of_air = 0; int print_ident_flag = 1; char ocastring[1024] = {0}; struct bu_list script_list; /* For -e and -f options */ struct script_rec *srp; extern outval ValTab[]; /* from if.c, callback functions for overlap, hit, and miss shots */ int if_overlap(struct application *, struct partition *, struct region *, struct region *, struct partition *); int if_hit(struct application *, struct partition *, struct seg *); int if_miss(struct application *); BU_LIST_INIT(&script_list); bu_setprogname(argv[0]); ocname[OVLP_RESOLVE] = "resolve"; ocname[OVLP_REBUILD_FASTGEN] = "rebuild_fastgen"; ocname[OVLP_REBUILD_ALL] = "rebuild_all"; ocname[OVLP_RETAIN] = "retain"; *ocastring = '\0'; bu_optind = 1; /* restart */ /* Handle command-line options */ while ((Ch = bu_getopt(argc, argv, OPT_STRING)) != -1) { if (bu_optopt == '?') Ch='h'; switch (Ch) { case 'A': attrib_add(bu_optarg, &need_prep); break; case 'B': rt_bot_minpieces = atoi(bu_optarg); break; case 'T': setenv("LIBRT_BOT_MINTIE", bu_optarg, 1); break; case 'b': do_backout = 1; break; case 'E': if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "before erasure"); while (BU_LIST_WHILE(srp, script_rec, &script_list)) { BU_LIST_DEQUEUE(&(srp->l)); free_script(srp); } if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "after erasure"); break; case 'e': enqueue_script(&script_list, READING_STRING, bu_optarg); if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "after enqueueing a literal"); break; case 'f': enqueue_script(&script_list, READING_FILE, bu_optarg); if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "after enqueueing a file name"); break; case 'L': listformats(); bu_exit(EXIT_SUCCESS, NULL); case 'M': mat_flag = 1; break; case 'O': sscanf(bu_optarg, "%1024s", ocastring); break; case 's': silent_flag = SILENT_YES; /* Positively yes */ break; case 'v': silent_flag = SILENT_NO; /* Positively no */ break; case 'x': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.debug); break; case 'X': sscanf(bu_optarg, "%x", (unsigned int *)&nirt_debug); break; case 'u': if (sscanf(bu_optarg, "%d", &use_of_air) != 1) { (void) fprintf(stderr, "Illegal use-air specification: '%s'\n", bu_optarg); return 1; } break; case 'H': if (sscanf(bu_optarg, "%d", &print_ident_flag) != 1) { (void) fprintf(stderr, "Illegal header output option specified: '%s'\n", bu_optarg); return 1; } break; default: printusage(); bu_exit (Ch != 'h', NULL); } } /* end while getopt */ if (argc - bu_optind < 2) { printusage(); return 1; } if (isatty(0)) { if (silent_flag != SILENT_YES) silent_flag = SILENT_NO; } else { /* stdin is not a TTY */ if (silent_flag != SILENT_NO) silent_flag = SILENT_YES; } if (silent_flag != SILENT_YES && print_ident_flag) (void) fputs(brlcad_ident("Natalie's Interactive Ray Tracer"), stdout); if (use_of_air && (use_of_air != 1)) { fprintf(stderr, "Warning: useair=%d specified, will set to 1\n", use_of_air); use_of_air = 1; } switch (*ocastring) { case '\0': overlap_claims = OVLP_RESOLVE; break; case '0': case '1': case '2': case '3': if (ocastring[1] == '\0') { sscanf(ocastring, "%d", &overlap_claims); } else { fprintf(stderr, "Illegal overlap_claims specification: '%s'\n", ocastring); return 1; } break; case 'r': if (BU_STR_EQUAL(ocastring, "resolve")) overlap_claims = OVLP_RESOLVE; else if (BU_STR_EQUAL(ocastring, "rebuild_fastgen")) overlap_claims = OVLP_REBUILD_FASTGEN; else if (BU_STR_EQUAL(ocastring, "rebuild_all")) overlap_claims = OVLP_REBUILD_ALL; else if (BU_STR_EQUAL(ocastring, "retain")) overlap_claims = OVLP_RETAIN; else { fprintf(stderr, "Illegal overlap_claims specification: '%s'\n", ocastring); return 1; } break; default: fprintf(stderr, "Illegal overlap_claims specification: '%s'\n", ocastring); return 1; } db_name = argv[bu_optind]; /* build directory for target object */ if (silent_flag != SILENT_YES) { printf("Database file: '%s'\n", db_name); printf("Building the directory..."); } if ((rtip = rt_dirbuild(db_name, db_title, TITLE_LEN)) == RTI_NULL) { fflush(stdout); fprintf(stderr, "Could not load file %s\n", db_name); return 1; } rti_tab[use_of_air] = rtip; rti_tab[1 - use_of_air] = RTI_NULL; rtip->useair = use_of_air; rtip->rti_save_overlaps = (overlap_claims > 0); ++bu_optind; do_rt_gettrees(rtip, argv + bu_optind, argc - bu_optind, &need_prep); /* Initialize the table of resource structures */ rt_init_resource(&res_tab, 0, rtip); /* initialization of the application structure */ RT_APPLICATION_INIT(&ap); ap.a_hit = if_hit; /* branch to if_hit routine */ ap.a_miss = if_miss; /* branch to if_miss routine */ ap.a_overlap = if_overlap;/* branch to if_overlap routine */ ap.a_logoverlap = rt_silent_logoverlap; ap.a_onehit = 0; /* continue through shotline after hit */ ap.a_resource = &res_tab; ap.a_purpose = "NIRT ray"; ap.a_rt_i = rtip; /* rt_i pointer */ ap.a_zero1 = 0; /* sanity check, sayth raytrace.h */ ap.a_zero2 = 0; /* sanity check, sayth raytrace.h */ ap.a_uptr = (void *)a_tab.attrib; /* initialize variables */ azimuth() = 0.0; elevation() = 0.0; direct(X) = -1.0; direct(Y) = 0.0; direct(Z) = 0.0; grid(HORZ) = 0.0; grid(VERT) = 0.0; grid(DIST) = 0.0; grid2targ(); set_diameter(rtip); /* initialize the output specification */ default_ospec(); /* initialize NIRT's local units */ base2local = rtip->rti_dbip->dbi_base2local; local2base = rtip->rti_dbip->dbi_local2base; tmp_str = bu_units_string(local2base); if (tmp_str) { bu_strlcpy(local_u_name, tmp_str, sizeof(local_u_name)); } else { bu_strlcpy(local_u_name, "Unknown units", sizeof(local_u_name)); } if (silent_flag != SILENT_YES) { printf("Database title: '%s'\n", db_title); printf("Database units: '%s'\n", local_u_name); printf("model_min = (%g, %g, %g) model_max = (%g, %g, %g)\n", rtip->mdl_min[X] * base2local, rtip->mdl_min[Y] * base2local, rtip->mdl_min[Z] * base2local, rtip->mdl_max[X] * base2local, rtip->mdl_max[Y] * base2local, rtip->mdl_max[Z] * base2local); } /* Run the run-time configuration file, if it exists */ if ((fPtr = fopenrc()) != NULL) { interact(READING_FILE, fPtr, rtip); fclose(fPtr); } /* Run all scripts specified on the command line */ run_scripts(&script_list, rtip); /* Perform the user interface */ if (mat_flag) { read_mat(rtip); return 0; } else { interact(READING_FILE, stdin, rtip); } return 0; }
int main () { freopen ("tourism.in", "rt", stdin); freopen ("tourism.out", "wt", stdout); var['0'] = 0; var['1'] = 1; var['2'] = 2; var['3'] = 3; var['4'] = 4; var['5'] = 5; var['6'] = 6; var['7'] = 7; var['8'] = 8; var['9'] = 9; var['A'] = 10; var['B'] = 11; var['C'] = 12; var['D'] = 13; var['E'] = 14; var['F'] = 15; var['G'] = 16; var['H'] = 17; var['I'] = 18; var['J'] = 19; var['K'] = 20; var['L'] = 21; var['M'] = 22; var['N'] = 23; var['O'] = 24; var['P'] = 25; var['Q'] = 26; var['R'] = 27; var['S'] = 28; var['T'] = 29; var['U'] = 30; var['V'] = 31; var['W'] = 32; var['X'] = 33; var['Y'] = 34; var['Z'] = 35; var['a'] = 36; var['b'] = 37; var['c'] = 38; var['d'] = 39; var['e'] = 40; var['f'] = 41; var['g'] = 42; var['h'] = 43; var['i'] = 44; var['j'] = 45; var['k'] = 46; var['l'] = 47; var['m'] = 48; var['n'] = 49; var['o'] = 50; var['p'] = 51; var['q'] = 52; var['r'] = 53; var['s'] = 54; var['t'] = 55; var['u'] = 56; var['v'] = 57; var['w'] = 58; var['x'] = 59; var['y'] = 60; var['z'] = 61; var['!'] = 62; var['?'] = 63; scanf ("%d", &n); memset (M, 0, sizeof M); if (n == 3) printf ("0 1 2\n"); else printf ("-1"); return 0; read_mat (); int m; scanf ("%d", &m); return 0; }