示例#1
0
int main(void) {
  FILE *fin = fopen( "matrix2.in", "r" );

  if( fin == NULL ) {
    printf( "Error: could not open matrix2.in\n" );
    exit( EXIT_FAILURE );
  }

  Matrix *a = read_matrix( fin );
  Matrix *b = read_matrix( fin );
  fclose( fin );

  Matrix *c = product_matrix( a, b );

  FILE *output = fopen( "matrix2.out", "w" );

  if( output == NULL ) {
    printf( "Error: could not open matrix2.out\n" );
    exit( EXIT_FAILURE );
  }

  print_matrix( output, c );
  fclose( output );

	destroy_matrix( a );
	destroy_matrix( b );
	destroy_matrix( c );

  return 0;
}
示例#2
0
void main()
{
	int row1, column1, row2, column2;
	int matrix1[100][100], matrix2[100][100], final_matrix[100][100];
	printf("Enter number of rows and columns of matrix 1\n");
	scanf_s("%d%d", &row1, &column1);
	printf("Enter elements of matrix 1\n");
	read_matrix(row1, column1, matrix1);
	printf("Enter number of rows and columns of matrix 2\n");
	scanf_s("%d%d", &row2, &column2);
	if (column1 != row2)
		printf("Matrices cannot be multiplied \n");
	else
	{
		printf("Enter elements of matrix 2\n");
		read_matrix(row2, column2, matrix2);
	}
	printf("Matrix 1  is as follows \n");
	display_matrix(row1, column1, matrix1);
	printf("Mtrix 2 is as follows \n");
	display_matrix(row2, column2, matrix2);
	multiply_matrix(row1, column1, matrix1, row2, column2, matrix2, final_matrix);
	printf("Resultant Matrix is as follows \n");
	display_matrix(row1, column2, final_matrix);
	getchar();
	getchar();
	getchar();
}
示例#3
0
void *read_all()
{
  printf("---!!! READ ALL THREAD START !!!---\n");
  read_matrix(matrixa);
  read_matrix(matrixb);
  printf("---!!! READ ALL THREAD END !!!---\n");
  sem_post(&mutex);
  return 0;
}
// Read binary ROM data for basis functions and coefficients
static int load_data(const char dir[], gsl_vector *cvec_amp, gsl_vector *cvec_phi, gsl_matrix *Bamp, gsl_matrix *Bphi, gsl_vector *cvec_amp_pre) {
  // Load binary data for amplitude and phase spline coefficients as computed in Mathematica
  int ret = XLAL_SUCCESS;
  ret |= read_vector(dir, "SEOBNRv1ROM_SS_Amp_ciall.dat", cvec_amp);
  ret |= read_vector(dir, "SEOBNRv1ROM_SS_Phase_ciall.dat", cvec_phi);
  ret |= read_matrix(dir, "SEOBNRv1ROM_SS_Bamp_bin.dat", Bamp);
  ret |= read_matrix(dir, "SEOBNRv1ROM_SS_Bphase_bin.dat", Bphi);
  ret |= read_vector(dir, "SEOBNRv1ROM_SS_AmpPrefac_ci.dat", cvec_amp_pre);
  return(ret);
}
示例#5
0
int main()
{
    int N;
    scanf("%d",&N);
    int *matrix_a = (int *)malloc(N * N * sizeof(int));
    int *matrix_b = (int *)malloc(N * N * sizeof(int));
    int *matrix_c = (int *)malloc(N * N * sizeof(int));
    read_matrix(matrix_a, N);
    read_matrix(matrix_b, N);
    multiply_matrix_3(matrix_a, matrix_b, matrix_c, N);
    display_matrix(matrix_c, N);
}
示例#6
0
文件: fclib.c 项目: xhub/fclib
/** read local problem;
 * return problem on success; NULL on failure */
struct fclib_local* fclib_read_local (const char *path)
{
  struct fclib_local *problem;
  hid_t  file_id, main_id, id;

  if ((file_id = H5Fopen (path, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
  {
    fprintf (stderr, "ERROR: opening file failed\n");
    return NULL;
  }

  if (!H5Lexists (file_id, "/fclib_local", H5P_DEFAULT))
  {
    fprintf (stderr, "ERROR: spurious input file %s :: fclib_local group does not exists", path);
    return NULL;
  }

  MM (problem = calloc (1, sizeof (struct fclib_local)));

  IO (main_id = H5Gopen (file_id, "/fclib_local", H5P_DEFAULT));
  IO (H5LTread_dataset_int (file_id, "/fclib_local/spacedim", &problem->spacedim));

  IO (id = H5Gopen (file_id, "/fclib_local/W", H5P_DEFAULT));
  problem->W = read_matrix (id);
  IO (H5Gclose (id));

  if (H5Lexists (file_id, "/fclib_local/V", H5P_DEFAULT))
  {
    IO (id = H5Gopen (file_id, "/fclib_local/V", H5P_DEFAULT));
    problem->V = read_matrix (id);
    IO (H5Gclose (id));

    IO (id = H5Gopen (file_id, "/fclib_local/R", H5P_DEFAULT));
    problem->R = read_matrix (id);
    IO (H5Gclose (id));
  }

  IO (id = H5Gopen (file_id, "/fclib_local/vectors", H5P_DEFAULT));
  read_local_vectors (id, problem);
  IO (H5Gclose (id));

  if (H5Lexists (file_id, "/fclib_local/info", H5P_DEFAULT))
  {
    IO (id = H5Gopen (file_id, "/fclib_local/info", H5P_DEFAULT));
    problem->info = read_problem_info (id);
    IO (H5Gclose (id));
  }

  IO (H5Gclose (main_id));
  IO (H5Fclose (file_id));

  return problem;
}
示例#7
0
int main(void) {
  matrix a,b,c;
  printf("enter first matrix\n");
  read_matrix(&a);
  print_matrix(&a);
  printf("enter second matrix\n");
  read_matrix(&b);
  print_matrix(&b);
  printf("matrix product\n");
  multiply(&a, &b, &c);
  print_matrix(&c);
  return 0;
}
示例#8
0
int main(int argc, char ** argv){
    matrix * matrix_a;
    matrix * matrix_b;
    int thread_count = 0;
    //  if(argc != 7){
    //      fprintf(stderr, "%s", "Not enough arguments");
    //      exit(-1);
    //  }
    for(int i = 1; i < argc; i ++){
        if(strcmp(argv[i],"-a") == 0){
            matrix_a = read_matrix(argv[i+1]);
        }
        if(strcmp(argv[i],"-b") == 0){
            matrix_b = read_matrix(argv[i+1]);
        }
        if(strcmp(argv[i],"-t") == 0){
            thread_count = atoi(argv[i+1]);
        }
    }
    if(matrix_a->cols != matrix_b->rows){
        fprintf(stderr, "%s", "a and b not computable");
        exit(-1);
    }
    printf("Read ready, start computing");

    
    pthread_t thread_id;
    int err;
    in_arg * arg = (in_arg *)malloc(sizeof(in_arg));
    out_arg * result = (out_arg *)malloc(sizeof(out_arg));
    arg->a = matrix_a;
    arg->b = matrix_b;
    arg->from_row = 0;
    arg->to_row = matrix_a->rows - 1;
       err = pthread_create(&thread_id, NULL, compute_thread, (void*)arg);
    
    err = pthread_join(thread_id, (void**)result);
//    double * result_matrix = (double *)malloc(matrix_a->rows * matrix_b->cols * sizeof(double));
//    for(int i = 0 ; i < matrix_a->rows; i++){
//        double *one_strip = compute_strip(matrix_a,matrix_b,i);
//        for(int j = 0 ; j < matrix_a->cols; j++){
//            result_matrix[i * matrix_b->cols + j] = one_strip[j];
//        }
//        free(one_strip);
//    }
    for(int i = 0 ; i < matrix_a->rows * matrix_b->cols; i ++){
        printf("%f ",result->result[i]);
        if(i % matrix_b->cols == matrix_b->cols-1)
            printf("\n");
    }
}
示例#9
0
void Call_Inverse( int n)
{
  POLY ds;
  POLY M1[n][n], t_M1[n][n], product[n][n];
  int k; 

  printf("Please choose the test matrix:  "); 
  printf("1 random matrix.\n");
  printf("2 input your own matrix.\n");
  scanf("%d", &k ); printf("%d\n", k);

  if(k==1) random_matrix ( n, n, M1);
  if(k==2) read_matrix( n, n, M1 );
  printf("the original matrix generated :\n");
  print( n, n, M1);

  copy(n, n, M1, t_M1);
  ds = Inverse_Poly ( n, M1 );
  printf(" The inverse matrix of the matrix is :\n" );
  print(n, n, M1 );
  printf(" The polynomial ds is :\n" );
  Print_Poly( ds.d, ds.p );

  printf("The product (without ds) of the original matrix");
  printf(" and the inverse matrix is:\n");
 
  Multiply(n, n, n, M1, t_M1, product);
  print(n, n, product);
  
  free_matrix(n, n, M1);
  free_matrix(n, n, t_M1);
  free_matrix(n, n, product);
 
}
示例#10
0
文件: PIVOT.C 项目: jbailhache/log
main ()
{
int n;
	MATRIX (A, MAX*MAX, MAX, MAX)

	read_matrix (A);

	if (DIM(A,0) != DIM(A,1))
	{
		printf ("La matrice doit etre carree\n");
		return;
	}
	n = DIM(A,0);

	MATRIX (B, MAX*MAX, n, n)

	printf ("Inversion de la matrice : ");
	print_matrix (A);

	pivot (A, B);

	printf ("Matrice inverse : ");
	print_matrix (B);

	ENDMAT ENDMAT
}
示例#11
0
bool SimGPS::OnStartUp()
{
  list<string> sParams;
  m_MissionReader.EnableVerbatimQuoting(false);
  if(m_MissionReader.GetConfiguration(GetAppName(), sParams)) {
    list<string>::iterator p;
    for(p=sParams.begin(); p!=sParams.end(); p++) {
      string original_line = *p;
      string param = stripBlankEnds(toupper(biteString(*p, '=')));
      string value = stripBlankEnds(*p);
      
      if(param == "GPS_COVARIANCE") {
        GPS_covariance = read_matrix(value);
      }
      if(param == "MAX_DEPTH"){
	max_depth = atof(value.c_str());
      }
      if(param == "ADD_NOISE"){
	add_noise = (tolower(value) == "true");
      }
      if(param == "BACKGROUND_MODE"){
	if (tolower(value) == "true")
	  in_prefix = "NAV";
	else
	  in_prefix = "SIM";
      }
    }
  }
  
  distribution = normal_distribution<double>(0.0,sqrt(GPS_covariance(0,0)));

  RegisterVariables();	
  return(true);
}
int main(int argc, char *argv[])
{
	double* matA = _mm_malloc(WIDTH*HEIGHT*sizeof(double), 64);
	double* matB = _mm_malloc((WIDTH*HEIGHT)*sizeof(double), 64);
	double* prod = _mm_malloc(WIDTH*HEIGHT*sizeof(double), 64);
	double* prod_ref = _mm_malloc(WIDTH*HEIGHT*sizeof(double), 64);

	int read_flag = read_matrix(TEST_FILENAME, prod_ref, matA, matB);
	if (read_flag == 1)
		printf("Cannot open test file\n");
	else if (read_flag == 2)
		printf("Error while reading data from test file");
	else if (read_flag == 3)
		printf("Error while closing the test file");
	if (read_flag)
		return 0;

	uint64_t start = timestamp_us();
	matmul_optimize(prod, matA, matB); /* run the optimization functions. */
	uint64_t time = timestamp_us() - start;

	if (compare_matrix(prod, prod_ref)) {
		printf("%lu incorrect\n", time);
	} else {
		printf("%lu\n", time);
	}
	_mm_free(prod_ref);
	_mm_free(prod);
	_mm_free(matB);
	_mm_free(matA);
	return 0;
}
示例#13
0
int main () {

	// read two N x N matrices

	read_matrix (X);
	read_matrix (Y);

	// multiply the matrices 

	matrix_multiply (X, Y, Z);

	// output the resulting matrix

	print_matrix (Z);
	return 0;
}
示例#14
0
/* <pattern> <matrix> <shading> .buildshadingpattern <pattern> <instance> */
static int
zbuildshadingpattern(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr op2 = op - 2;
    gs_matrix mat;
    gs_pattern2_template_t templat;
    int_pattern *pdata;
    gs_client_color cc_instance;
    int code;

    check_type(*op2, t_dictionary);
    check_dict_read(*op2);
    gs_pattern2_init(&templat);
    if ((code = read_matrix(imemory, op - 1, &mat)) < 0 ||
        (code = dict_uid_param(op2, &templat.uid, 1, imemory, i_ctx_p)) != 1 ||
        (code = shading_param(op, &templat.Shading)) < 0 ||
        (code = int_pattern_alloc(&pdata, op2, imemory)) < 0
        )
        return_error((code < 0 ? code : gs_error_rangecheck));
    templat.client_data = pdata;
    code = gs_make_pattern(&cc_instance,
                           (const gs_pattern_template_t *)&templat,
                           &mat, igs, imemory);
    if (code < 0) {
        ifree_object(pdata, "int_pattern");
        return code;
    }
    make_istruct(op - 1, a_readonly, cc_instance.pattern);
    pop(1);
    return code;
}
示例#15
0
int get_proxy(char * proxypath,char sep){
  /* int i=8; */
  /* fprintf(stderr,"in mcmc AS[%d]=%d\n",i,23); */
  int ff;
  char fff[20];
  int midx = 0;
  fprintf(stderr,"MODE in sir %d\n",MODE);
  ADJL = (double ***)calloc((lastPROXY-firstPROXY+1), sizeof(double**));
  for (ff = firstPROXY; ff <= lastPROXY; ff++){
    /* fprintf(stderr,"proxy numero %d\n",ff); */
    char * file = (char *)calloc(1000,sizeof(char));
    file = strcat(file,proxypath);
    /* fprintf(stderr,"proxy file %s\n",file); */
    if((MODE == 2)||(MODE==3))
      file = strcat(file,"/Adj_");
    if((MODE == 0)||(MODE==1))
      file = strcat(file,"/Adj_");
    sprintf(fff,"%d",ff);
    //if((MODE == 2)||(MODE==3)){
    //sprintf(fff,"%d",0); //// PRENDOLASOMMATOTALE!!! 0
    //  sprintf(fff,"%s","0binary"); //// PRENDOLASOMMATOTALE BINARIZZATA!!! 0binary
    //}
    file = strcat(file,fff);
    /* fprintf(stderr,"proxy file %s\n",file); */
    ADJL[midx] = (double **) calloc ((N+1), sizeof(double*));
    read_matrix(ADJL[midx], file, midx, sep);
    midx++;
    /* fprintf(stderr,"proxy dopo numero %d\n",midx); */
    free(file);
  }
  return 0;
}   
示例#16
0
int
main (void)
{
    matrix_t            r = read_matrix ();
    matrix_t            mayw;
    matrix_t            mustw;
    dm_copy(&r, &mayw);
    dm_copy(&r, &mustw);
    printf ("matrix:\n");
    dm_print (stdout, &r);
    // nub
    dm_sort_rows (&r, &mayw, &mustw, &max_row_first);
    dm_nub_rows (&r, &mayw, &mustw, &eq_rows, NULL);
    // optimize
    dm_optimize (&r, &mayw, &mustw);
    // sort again
    dm_sort_rows (&r, &mayw, &mustw, &max_row_first);

    printf ("matrix:\n");
    dm_print (stdout, &r);
    printf ("state mapping:\n");
    state_mapping (&r);
    printf ("transition mapping:\n");
    transition_mapping (&r);
    printf ("dependencies:\n");
    dependencies (&r);

    return 0;
}
示例#17
0
/* <numarray|numstring> rectstroke - */
static int
zrectstroke(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    gs_matrix mat;
    local_rects_t lr;
    int npop, code;

    if (read_matrix(imemory, op, &mat) >= 0) {
	/* Concatenate the matrix to the CTM just before stroking the path. */
	npop = rect_get(&lr, op - 1, imemory);
	if (npop < 0)
	    return npop;
	code = gs_rectstroke(igs, lr.pr, lr.count, &mat);
	npop++;
    } else {
	/* No matrix. */
	npop = rect_get(&lr, op, imemory);
	if (npop < 0)
	    return npop;
	code = gs_rectstroke(igs, lr.pr, lr.count, (gs_matrix *) 0);
    }
    rect_release(&lr, imemory);
    if (code < 0)
	return code;
    pop(npop);
    return 0;
}
示例#18
0
文件: fclib.c 项目: xhub/fclib
/** read global problem;
 * return problem on success; NULL on failure */
struct fclib_global* fclib_read_global (const char *path)
{
  struct fclib_global *problem;
  hid_t  file_id, main_id, id;

  if ((file_id = H5Fopen (path, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
  {
    fprintf (stderr, "ERROR: opening file failed\n");
    return NULL;
  }

  MM (problem = calloc (1, sizeof (struct fclib_global)));

  IO (main_id = H5Gopen (file_id, "/fclib_global", H5P_DEFAULT));
  IO (H5LTread_dataset_int (file_id, "/fclib_global/spacedim", &problem->spacedim));

  IO (id = H5Gopen (file_id, "/fclib_global/M", H5P_DEFAULT));
  problem->M = read_matrix (id);
  IO (H5Gclose (id));

  IO (id = H5Gopen (file_id, "/fclib_global/H", H5P_DEFAULT));
  problem->H = read_matrix (id);
  IO (H5Gclose (id));

  if (H5Lexists (file_id, "/fclib_global/G", H5P_DEFAULT))
  {
    IO (id = H5Gopen (file_id, "/fclib_global/G", H5P_DEFAULT));
    problem->G = read_matrix (id);
    IO (H5Gclose (id));
  }

  IO (id = H5Gopen (file_id, "/fclib_global/vectors", H5P_DEFAULT));
  read_global_vectors (id, problem);
  IO (H5Gclose (id));

  if (H5Lexists (file_id, "/fclib_global/info", H5P_DEFAULT))
  {
    IO (id = H5Gopen (file_id, "/fclib_global/info", H5P_DEFAULT));
    problem->info = read_problem_info (id);
    IO (H5Gclose (id));
  }

  IO (H5Gclose (main_id));
  IO (H5Fclose (file_id));

  return problem;
}
示例#19
0
/* <matrix1> <matrix2> <matrix> concatmatrix <matrix> */
static int
zconcatmatrix(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    gs_matrix m1, m2, mp;
    int code;

    if ((code = read_matrix(imemory, op - 2, &m1)) < 0 ||
        (code = read_matrix(imemory, op - 1, &m2)) < 0 ||
        (code = gs_matrix_multiply(&m1, &m2, &mp)) < 0 ||
        (code = write_matrix(op, &mp)) < 0
        )
        return code;
    op[-2] = *op;
    pop(2);
    return code;
}
示例#20
0
/* Get FontMatrix and FontName parameters. */
static int
sub_font_params(gs_memory_t *mem, const ref *op, gs_matrix *pmat, gs_matrix *pomat, ref *pfname)
{
    ref *pmatrix, *pfontname, *pfontstyle, *porigfont, *pfontinfo;

    if (dict_find_string(op, "FontMatrix", &pmatrix) <= 0 ||
        read_matrix(mem, pmatrix, pmat) < 0
        )
        return_error(e_invalidfont);
    if (dict_find_string(op, "OrigFont", &porigfont) <= 0)
        porigfont = NULL;
    if (pomat!= NULL) {
        if (porigfont == NULL ||
            dict_find_string(porigfont, "FontMatrix", &pmatrix) <= 0 ||
            read_matrix(mem, pmatrix, pomat) < 0
            )
            memset(pomat, 0, sizeof(*pomat));
    }
    /* Use the FontInfo/OrigFontName key preferrentially (created by MS PSCRIPT driver) */
    if ((dict_find_string((porigfont != NULL ? porigfont : op), "FontInfo", &pfontinfo) > 0) &&
        r_has_type(pfontinfo, t_dictionary) &&
        (dict_find_string(pfontinfo, "OrigFontName", &pfontname) > 0)) {
        if ((dict_find_string(pfontinfo, "OrigFontStyle", &pfontstyle) > 0) &&
                r_size(pfontstyle) > 0) {
            const byte *tmpStr1 = pfontname->value.const_bytes;
            const byte *tmpStr2 = pfontstyle->value.const_bytes;
            int fssize1 = r_size(pfontname), fssize2 = r_size(pfontstyle), fssize = fssize1 + fssize2 + 1;
            byte *sfname = gs_alloc_string(mem, fssize, "sub_font_params");

            if (sfname == NULL)
                return_error(e_VMerror);
            memcpy(sfname, tmpStr1, fssize1);
            sfname[fssize1]=',' ;
            memcpy(sfname + fssize1 + 1, tmpStr2, fssize2);
            make_string(pfname, a_readonly, fssize, sfname);
        } else
            get_font_name(mem, pfname, pfontname);
    } else if (dict_find_string((porigfont != NULL ? porigfont : op), ".Alias", &pfontname) > 0) {
        /* If we emulate the font, we want the requested name rather than a substitute. */
        get_font_name(mem, pfname, pfontname);
    } else if (dict_find_string((porigfont != NULL ? porigfont : op), "FontName", &pfontname) > 0) {
        get_font_name(mem, pfname, pfontname);
    } else
        make_empty_string(pfname, a_readonly);
    return 0;
}
示例#21
0
/* Get a matrix from a dictionary. */
int
dict_matrix_param(const gs_memory_t *mem, const ref * pdict, const char *kstr, gs_matrix * pmat)
{
    ref *pdval;

    if (pdict == 0 || dict_find_string(pdict, kstr, &pdval) <= 0)
        return_error(e_typecheck);
    return read_matrix(mem, pdval, pmat);
}
示例#22
0
void * decompose (void *hnd, c4snet_data_t *InFile, c4snet_data_t *OutFile,
    int a_size, int bs)
{
    int p, i, j;
    double *array;
    tile *atiles, *ltiles;
    char *infile;

    if (bs <= 0) {
        fprintf (stderr, "A block size must be greater than 0\n");
        exit (1);
    }
    if (a_size <= 0) {
        fprintf (stderr, "The dimension of matrix must be greater than 0\n");
        exit (1);
    }
    if (a_size % bs) {
        fprintf(stderr, 
            "matrix size %d is not a multiple of the block size %d\n",
            a_size, bs);
        exit(1);
    }

    p = a_size / bs;

    /* Get the input filename as a string. */
    infile = chars_to_string(InFile);
    outfile = chars_to_string(OutFile);
    C4SNetFree(InFile);
    C4SNetFree(OutFile);

    array = SNetMemAlloc(a_size * a_size * sizeof(double));
    read_matrix(a_size, array, infile);
    free(infile);

    if (clock_gettime(CLOCK_REALTIME, &begin)) {
        pexit("clock_gettime");
    }

    atiles = (tile *) malloc (sizeof (tile) * p * p);
    ltiles = (tile *) malloc (sizeof (tile) * p * p);
    memset (atiles, 0, sizeof (tile) * p * p);
    memset (ltiles, 0, sizeof (tile) * p * p);
    for (i = 0; i < p; i++)
        for (j = 0; j <= i; j++) {
            atiles[j * p + i] = (double *) malloc (sizeof (double) * bs * bs);
            ltiles[j * p + i] = (double *) malloc (sizeof (double) * bs * bs);
            int ai, aj, ti, tj;
            for (ai = i * bs, ti = 0; ti < bs; ai++, ti++)
                for (aj = j * bs, tj = 0; tj < bs; aj++, tj++)
                    atiles[j * p + i][tj * bs + ti] = array[aj * a_size + ai];
        }
    C4SNetOut (hnd, 1, C4SNetCreate (CTYPE_char, sizeof (void *), &atiles),
               C4SNetCreate (CTYPE_char, sizeof (void *), &ltiles), bs, p, 0);
    free(array);
    return hnd;
}
示例#23
0
int main() {
  int n;
  scanf("%d", &n);
  int *a = new int [n * n], *b = new int [n * n];
  read_matrix(n, a);
  read_matrix(n, b);
  Matrix A(n, a), B(n, b);
  A *= B;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      printf("%3d ", A[i][j]);
    }
    printf("\n");
  }
  delete a;
  delete b;
  return 0;
}
示例#24
0
bool read_matrix(const std::string& filename, boost::numeric::ublas::matrix<T, boost::numeric::ublas::column_major>& m) {
  FILE* file = fopen(filename.c_str(), "rb");
  if (!file)
    return false;
  bool res = read_matrix(file, m);
  fclose(file);

  return res;
}
示例#25
0
int 
main(int argc, char* argv[]) 
{
	int dim = 0;
	int **mat=NULL, **ps=NULL, **outmat=NULL;
	FILE* input_file;
    
	if(argc != 2) {
        usage(argv[0]);
    }

    /* open files */
    input_file = fopen(argv[1], "r");
    if(input_file == NULL) {
        usage(argv[0]);
    }

    /* read matrix dimension */
    dim = get_mat_dim(input_file);  
	
	/* init matrices */
	mat = alloc_matrix(dim, dim); 
	ps = alloc_matrix(dim, dim);

	/* read matrix */
	read_matrix(mat, dim, dim, input_file); 

#ifdef _PRINT_INFO
    /* Print the matrix */
    printf("[INFO] Input matrix [%d]\n", dim);
	print_matrix(mat, dim, dim); 
#endif

	printf("Evaluation:\n");
	printf("===========\n");

	double avg_time = 0;
	/* compute an average value of the time needed to run the program */
	for(int i=0; i<NUM_ROUNDS; i++) {
		max_sub_arr(mat, ps, outmat, dim);
		/* runtime of the algorithm is modified by the algorithm itself */
		avg_time += runtime;
	}

	avg_time /= NUM_ROUNDS;

	/* print stats */
	printf("[STAT] Runtime=%f sec\n\n", avg_time);

    /* release resources */
    fclose(input_file);
	free_matrix(mat, dim); 
	free_matrix(ps, dim); 

    return EXIT_SUCCESS;
}
示例#26
0
文件: matrix.c 项目: DaniCF93/studia
int main(int argc, char * args[]){
    int i,j,it;
    unsigned long long counter, stop;
    char a[256], b[256];
    FILE * f;
    f = fopen("results.txt","w");
    

    
    
    
    for(it=2; it<=13; it++){
        fprintf(f,"%d ",it);
        sprintf(a,"mat_%d_a.mat",it);
        sprintf(b,"mat_%d_b.mat",it);
        int a_row = (int)pow(2,it), a_column = (int)pow(2,it), b_row = (int)pow(2,it), b_column = 1;
        
        
        //alokacja pamięci na macierze
        float ** m1 = read_matrix(a,a_row,a_column);
        float * m2 = read_vector(b,b_row);
        float * mw1 = (float*)malloc(a_row* sizeof(float));
		
		
		
		for(i=0; i<a_row; i++)
                mw1[i] = 0;
        counter = rdtsc(); 
        mul(mw1,m1,m2,a_row);
        stop = rdtsc() - counter;
        fprintf(f,"%llu ",stop / (int)pow(2,2*it));
        printf("%d\n",it);
		
		
		for(i=0; i<a_row; i++)
                mw1[i] = 0;
        counter = rdtsc(); 
        mul6(mw1,m1,m2,a_row);
        stop = rdtsc() - counter;
        fprintf(f,"%llu ",stop / (int)pow(2,2*it));
        printf("%d\n",it);
        
        
//print_matrix(mw1,a_row);

        //zwalnianie pamięci
        for(i=0; i<a_row; i++)
		    free(m1[i]);
	    free(m1); 
	    free(m2);
	    free(mw1);
	    fprintf(f,"\n");
	}
	fclose(f);
	return 0;
}
示例#27
0
文件: VPRUT.C 项目: jbailhache/log
main ()
{
	MATRIX (A, MAX*MAX, MAX, MAX);
	read_matrix (A);
	print_matrix (A);
	vprut1 (A);
	print_matrix (A);

	ENDMAT
}
示例#28
0
int main(int argc, char** argv)
{
	if (argc < 3){
		return 1;
	}
	std::string file_name_one(argv[1]);
	std::string file_name_two(argv[2]);
	
	
	std::vector<std::vector<int> > matrix_a = read_matrix(file_name_one);
	std::vector<std::vector<int> > matrix_b = read_matrix(file_name_two);
	
	write_matrix(matrix_a);
	write_matrix(matrix_b);
	std::vector<std::vector<int> > c = multiple_matrix(matrix_a, matrix_b);
	write_matrix(c);
	
	return 0;
}
示例#29
0
/* Common logic for [i][d]transform */
static int
common_transform(i_ctx_t *i_ctx_p,
        int (*ptproc)(gs_state *, double, double, gs_point *),
        int (*matproc)(double, double, const gs_matrix *, gs_point *))
{
    os_ptr op = osp;
    double opxy[2];
    gs_point pt;
    int code;

    /* Optimize for the non-matrix case */
    switch (r_type(op)) {
        case t_real:
            opxy[1] = op->value.realval;
            break;
        case t_integer:
            opxy[1] = (double)op->value.intval;
            break;
        case t_array:		/* might be a matrix */
        case t_shortarray:
        case t_mixedarray: {
            gs_matrix mat;
            gs_matrix *pmat = &mat;

            if ((code = read_matrix(imemory, op, pmat)) < 0 ||
                (code = num_params(op - 1, 2, opxy)) < 0 ||
                (code = (*matproc) (opxy[0], opxy[1], pmat, &pt)) < 0
                ) {		/* Might be a stack underflow. */
                check_op(3);
                return code;
            }
            op--;
            pop(1);
            goto out;
        }
        default:
            return_op_typecheck(op);
    }
    switch (r_type(op - 1)) {
        case t_real:
            opxy[0] = (op - 1)->value.realval;
            break;
        case t_integer:
            opxy[0] = (double)(op - 1)->value.intval;
            break;
        default:
            return_op_typecheck(op - 1);
    }
    if ((code = (*ptproc) (igs, opxy[0], opxy[1], &pt)) < 0)
        return code;
out:
    make_real(op - 1, pt.x);
    make_real(op, pt.y);
    return 0;
}
示例#30
0
int main (int c, char **v)
{
    if (c<2) return 1;
    double H[3][3];
    read_matrix(H, v[1]);
    printf("%f %f %f\n %f %f %f\n %f %f %f\n",
           H[0][0], H[0][1],H[0][2],
           H[1][0], H[1][1],H[1][2],
           H[2][0], H[2][1],H[2][2]);
    return 0;
}