Nathalie Furmento %!s(int64=11) %!d(string=hai) anos
pai
achega
66f3870426

+ 1 - 0
examples/Makefile.am

@@ -39,6 +39,7 @@ EXTRA_DIST = 					\
 	spmd/vector_scal_spmd.c			\
 	spmv/spmv_cuda.cu			\
 	spmv/spmv_opencl.cl			\
+	spmv/matrix_market/examples/fidapm05.mtx \
 	mult/xgemm.c				\
 	lu/xlu.c				\
 	lu/xlu_pivot.c				\

+ 21 - 18
examples/spmv/matrix_market/mm_to_bcsr.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2014  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -93,7 +93,7 @@ static tmp_block_t *search_block(tmp_block_t *block_list, unsigned i, unsigned j
 
 	while (current_block)
 	{
-		if ((current_block->i == i) && (current_block->j == j)) 
+		if ((current_block->i == i) && (current_block->j == j))
 		{
 			/* we found the block */
 			return current_block;
@@ -194,7 +194,7 @@ static void insert_elem(tmp_block_t **block_list, unsigned abs_i, unsigned abs_j
 
 		block->i = i;
 		block->j = j;
-		
+
 		/* printf("create block %d %d !\n", i, j); */
 
 		/* insert it in the block list */
@@ -207,7 +207,7 @@ static void insert_elem(tmp_block_t **block_list, unsigned abs_i, unsigned abs_j
 	local_i = abs_i % c;
 	local_j = abs_j % r;
 	local_index = local_j * c + local_i;
-	
+
 	block->val[local_index] = val;
 }
 
@@ -240,7 +240,7 @@ static void fill_bcsr(tmp_block_t *block_list, unsigned c, unsigned r, bcsr_t *b
 		/* copy the val from the block to the contiguous area in the BCSR */
 		memcpy(&bcsr->val[current_offset], current_block->val, block_size);
 
-		/* write the the index of the block 
+		/* write the the index of the block
 		 * XXX should it be in blocks ? */
 		bcsr->colind[block] = current_block->i;
 
@@ -262,7 +262,7 @@ static void fill_bcsr(tmp_block_t *block_list, unsigned c, unsigned r, bcsr_t *b
 	unsigned row;
 	for (row = 1; row < bcsr->nrows_blocks; row++)
 	{
-		if (bcsr->rowptr[row] == 0) 
+		if (bcsr->rowptr[row] == 0)
 			bcsr->rowptr[row] = bcsr->rowptr[row-1];
 	}
 
@@ -282,7 +282,7 @@ static bcsr_t * blocks_to_bcsr(tmp_block_t *block_list, unsigned c, unsigned r)
 	bcsr->nnz_blocks = nblocks;
 	bcsr->r = r;
 	bcsr->c = c;
-	
+
 	unsigned nrows_blocks = count_row_blocks(block_list);
 	bcsr->nrows_blocks = nrows_blocks;
 
@@ -314,15 +314,18 @@ bcsr_t *mm_file_to_bcsr(char *filename, unsigned c, unsigned r)
 	MM_typecode matcode;
 	int ret_code;
 	int M, N;
-	int nz;   
+	int nz;
 	int i;
 	unsigned *I, *J;
 	float *val;
 
 	bcsr_t *bcsr;
 
-	if ((f = fopen(filename, "r")) == NULL) 
+	if ((f = fopen(filename, "r")) == NULL)
+	{
+		fprintf(stderr, "File <%s> not found\n", filename);
 		exit(1);
+	}
 
 	if (mm_read_banner(f, &matcode) != 0)
 	{
@@ -332,36 +335,36 @@ bcsr_t *mm_file_to_bcsr(char *filename, unsigned c, unsigned r)
 
 	/*  This is how one can screen matrix types if their application */
 	/*  only supports a subset of the Matrix Market data types.      */
-	
+
 	if (mm_is_complex(matcode) && mm_is_matrix(matcode) &&  mm_is_sparse(matcode) )
 	{
 		printf("Sorry, this application does not support ");
 		printf("Market Market type: [%s]\n", mm_typecode_to_str(matcode));
 		exit(1);
 	}
-	
+
 	/* find out size of sparse matrix .... */
-	
+
 	if ((ret_code = mm_read_mtx_crd_size(f, &M, &N, &nz)) !=0)
 		exit(1);
-	
-	
+
+
 	/* reseve memory for matrices */
-	
+
 	I = malloc(nz * sizeof(unsigned));
 	J = malloc(nz * sizeof(unsigned));
 	/* XXX float ! */
 	val = (float *) malloc(nz * sizeof(float));
-	
+
 	for (i=0; i<nz; i++)
 	{
 		fscanf(f, "%d %d %f\n", &I[i], &J[i], &val[i]);
 		I[i]--;  /* adjust from 1-based to 0-based */
 		J[i]--;
 	}
-	
+
 	if (f !=stdin) fclose(f);
-	
+
 	bcsr = mm_to_bcsr((unsigned)nz, I, J, val, c, r);
 
 	free(I);

+ 58 - 56
examples/spmv/matrix_market/mmio.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010, 2013  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2013, 2014  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -13,7 +13,7 @@
  *
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
-/* 
+/*
 *   Matrix Market I/O library for ANSI C
 *
 *   See http://math.nist.gov/MatrixMarket for details.
@@ -38,20 +38,22 @@ int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_,
     int i;
     double *val;
     int *I, *J;
- 
+
     if ((f = fopen(fname, "r")) == NULL)
+    {
+	    fprintf(stderr, "File <%s> not found\n", fname);
             return -1;
- 
- 
+    }
+
     if (mm_read_banner(f, &matcode) != 0)
     {
-        printf("mm_read_unsymetric: Could not process Matrix Market banner ");
-        printf(" in file [%s]\n", fname);
-        return -1;
+	    fprintf(stderr, "mm_read_unsymetric: Could not process Matrix Market banner ");
+	    fprintf(stderr, " in file [%s]\n", fname);
+	    return -1;
     }
- 
- 
- 
+
+
+
     if ( !(mm_is_real(matcode) && mm_is_matrix(matcode) &&
             mm_is_sparse(matcode)))
     {
@@ -60,33 +62,33 @@ int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_,
                 mm_typecode_to_str(matcode));
         return -1;
     }
- 
+
     /* find out size of sparse matrix: M, N, nz .... */
- 
+
     if (mm_read_mtx_crd_size(f, &M, &N, &nz) !=0)
     {
         fprintf(stderr, "read_unsymmetric_sparse(): could not parse matrix size.\n");
         return -1;
     }
- 
+
     *M_ = M;
     *N_ = N;
     *nz_ = nz;
- 
+
     /* reseve memory for matrices */
- 
+
     I = (int *) malloc(nz * sizeof(int));
     J = (int *) malloc(nz * sizeof(int));
     val = (double *) malloc(nz * sizeof(double));
- 
+
     *val_ = val;
     *I_ = I;
     *J_ = J;
- 
+
     /* NOTE: when reading in doubles, ANSI C requires the use of the "l"  */
     /*   specifier as in "%lg", "%lf", "%le", otherwise errors will occur */
     /*  (ANSI C X3.159-1989, Sec. 4.9.6.2, p. 136 lines 13-15)            */
- 
+
     for (i=0; i<nz; i++)
     {
         fscanf(f, "%d %d %lg\n", &I[i], &J[i], &val[i]);
@@ -94,7 +96,7 @@ int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_,
         J[i]--;
     }
     fclose(f);
- 
+
     return 0;
 }
 
@@ -103,7 +105,7 @@ int mm_is_valid(MM_typecode matcode)
     if (!mm_is_matrix(matcode)) return 0;
     if (mm_is_dense(matcode) && mm_is_pattern(matcode)) return 0;
     if (mm_is_real(matcode) && mm_is_hermitian(matcode)) return 0;
-    if (mm_is_pattern(matcode) && (mm_is_hermitian(matcode) || 
+    if (mm_is_pattern(matcode) && (mm_is_hermitian(matcode) ||
                 mm_is_skew(matcode))) return 0;
     return 1;
 }
@@ -112,24 +114,24 @@ int mm_read_banner(FILE *f, MM_typecode *matcode)
 {
     char line[MM_MAX_LINE_LENGTH];
     char banner[MM_MAX_TOKEN_LENGTH];
-    char mtx[MM_MAX_TOKEN_LENGTH]; 
+    char mtx[MM_MAX_TOKEN_LENGTH];
     char crd[MM_MAX_TOKEN_LENGTH];
     char data_type[MM_MAX_TOKEN_LENGTH];
     char storage_scheme[MM_MAX_TOKEN_LENGTH];
     char *p;
 
 
-    mm_clear_typecode(matcode);  
+    mm_clear_typecode(matcode);
 
-    if (fgets(line, MM_MAX_LINE_LENGTH, f) == NULL) 
+    if (fgets(line, MM_MAX_LINE_LENGTH, f) == NULL)
         return MM_PREMATURE_EOF;
 
-    if (sscanf(line, "%s %s %s %s %s", banner, mtx, crd, data_type, 
+    if (sscanf(line, "%s %s %s %s %s", banner, mtx, crd, data_type,
         storage_scheme) != 5)
         return MM_PREMATURE_EOF;
 
     for (p=mtx; *p!='\0'; *p=tolower(*p),p++);  /* convert to lower case */
-    for (p=crd; *p!='\0'; *p=tolower(*p),p++);  
+    for (p=crd; *p!='\0'; *p=tolower(*p),p++);
     for (p=data_type; *p!='\0'; *p=tolower(*p),p++);
     for (p=storage_scheme; *p!='\0'; *p=tolower(*p),p++);
 
@@ -154,7 +156,7 @@ int mm_read_banner(FILE *f, MM_typecode *matcode)
             mm_set_dense(matcode);
     else
         return MM_UNSUPPORTED_TYPE;
-    
+
 
     /* third field */
 
@@ -171,7 +173,7 @@ int mm_read_banner(FILE *f, MM_typecode *matcode)
         mm_set_integer(matcode);
     else
         return MM_UNSUPPORTED_TYPE;
-    
+
 
     /* fourth field */
 
@@ -188,7 +190,7 @@ int mm_read_banner(FILE *f, MM_typecode *matcode)
         mm_set_skew(matcode);
     else
         return MM_UNSUPPORTED_TYPE;
-        
+
 
     return 0;
 }
@@ -197,7 +199,7 @@ int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz)
 {
     if (fprintf(f, "%d %d %d\n", M, N, nz) != 3)
         return MM_COULD_NOT_WRITE_FILE;
-    else 
+    else
         return 0;
 }
 
@@ -210,20 +212,20 @@ int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz )
     *M = *N = *nz = 0;
 
     /* now continue scanning until you reach the end-of-comments */
-    do 
+    do
     {
-        if (fgets(line,MM_MAX_LINE_LENGTH,f) == NULL) 
+        if (fgets(line,MM_MAX_LINE_LENGTH,f) == NULL)
             return MM_PREMATURE_EOF;
     }while (line[0] == '%');
 
     /* line[] is either blank or has M,N, nz */
     if (sscanf(line, "%d %d %d", M, N, nz) == 3)
         return 0;
-        
+
     else
     do
-    { 
-        num_items_read = fscanf(f, "%d %d %d", M, N, nz); 
+    {
+        num_items_read = fscanf(f, "%d %d %d", M, N, nz);
         if (num_items_read == EOF) return MM_PREMATURE_EOF;
     }
     while (num_items_read != 3);
@@ -238,22 +240,22 @@ int mm_read_mtx_array_size(FILE *f, int *M, int *N)
     int num_items_read;
     /* set return null parameter values, in case we exit with errors */
     *M = *N = 0;
-	
+
     /* now continue scanning until you reach the end-of-comments */
-    do 
+    do
     {
-        if (fgets(line,MM_MAX_LINE_LENGTH,f) == NULL) 
+        if (fgets(line,MM_MAX_LINE_LENGTH,f) == NULL)
             return MM_PREMATURE_EOF;
     }while (line[0] == '%');
 
     /* line[] is either blank or has M,N, nz */
     if (sscanf(line, "%d %d", M, N) == 2)
         return 0;
-        
+
     else /* we have a blank line */
     do
-    { 
-        num_items_read = fscanf(f, "%d %d", M, N); 
+    {
+        num_items_read = fscanf(f, "%d %d", M, N);
         if (num_items_read == EOF) return MM_PREMATURE_EOF;
     }
     while (num_items_read != 2);
@@ -265,7 +267,7 @@ int mm_write_mtx_array_size(FILE *f, int M, int N)
 {
     if (fprintf(f, "%d %d\n", M, N) != 2)
         return MM_COULD_NOT_WRITE_FILE;
-    else 
+    else
         return 0;
 }
 
@@ -308,7 +310,7 @@ int mm_read_mtx_crd_data(FILE *f, int M,
         return MM_UNSUPPORTED_TYPE;
 
     return 0;
-        
+
 }
 
 int mm_read_mtx_crd_entry(FILE *f, int *I, int *J,
@@ -334,7 +336,7 @@ int mm_read_mtx_crd_entry(FILE *f, int *I, int *J,
         return MM_UNSUPPORTED_TYPE;
 
     return 0;
-        
+
 }
 
 
@@ -346,7 +348,7 @@ int mm_read_mtx_crd_entry(FILE *f, int *I, int *J,
                             (nz pairs of real/imaginary values)
 ************************************************************************/
 
-int mm_read_mtx_crd(char *fname, int *M, int *N, int *nz, int **I, int **J, 
+int mm_read_mtx_crd(char *fname, int *M, int *N, int *nz, int **I, int **J,
         double **val, MM_typecode *matcode)
 {
     int ret_code;
@@ -361,7 +363,7 @@ int mm_read_mtx_crd(char *fname, int *M, int *N, int *nz, int **I, int **J,
     if ((ret_code = mm_read_banner(f, matcode)) != 0)
         return ret_code;
 
-    if (!(mm_is_valid(*matcode) && mm_is_sparse(*matcode) && 
+    if (!(mm_is_valid(*matcode) && mm_is_sparse(*matcode) &&
             mm_is_matrix(*matcode)))
         return MM_UNSUPPORTED_TYPE;
 
@@ -376,21 +378,21 @@ int mm_read_mtx_crd(char *fname, int *M, int *N, int *nz, int **I, int **J,
     if (mm_is_complex(*matcode))
     {
         *val = (double *) malloc(*nz * 2 * sizeof(double));
-        ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, 
+        ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val,
                 *matcode);
         if (ret_code != 0) return ret_code;
     }
     else if (mm_is_real(*matcode))
     {
         *val = (double *) malloc(*nz * sizeof(double));
-        ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, 
+        ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val,
                 *matcode);
         if (ret_code != 0) return ret_code;
     }
 
     else if (mm_is_pattern(*matcode))
     {
-        ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, 
+        ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val,
                 *matcode);
         if (ret_code != 0) return ret_code;
     }
@@ -418,12 +420,12 @@ int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
     FILE *f;
     int i;
 
-    if (strcmp(fname, "stdout") == 0) 
+    if (strcmp(fname, "stdout") == 0)
         f = stdout;
     else
     if ((f = fopen(fname, "w")) == NULL)
         return MM_COULD_NOT_WRITE_FILE;
-    
+
     /* print banner followed by typecode */
     fprintf(f, "%s ", MatrixMarketBanner);
     fprintf(f, "%s\n", mm_typecode_to_str(matcode));
@@ -442,7 +444,7 @@ int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
     else
     if (mm_is_complex(matcode))
         for (i=0; i<nz; i++)
-            fprintf(f, "%d %d %20.16g %20.16g\n", I[i], J[i], val[2*i], 
+            fprintf(f, "%d %d %20.16g %20.16g\n", I[i], J[i], val[2*i],
                         val[2*i+1]);
     else
     {
@@ -454,7 +456,7 @@ int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
 
     return 0;
 }
-  
+
 
 /**
 *  Create a new copy of a string s.  mm_strdup() is a common routine, but
@@ -476,7 +478,7 @@ char  *mm_typecode_to_str(MM_typecode matcode)
     int error =0;
 
     /* check for MTX type */
-    if (mm_is_matrix(matcode)) 
+    if (mm_is_matrix(matcode))
         types[0] = MM_MTX_STR;
     else
         error=1;
@@ -512,10 +514,10 @@ char  *mm_typecode_to_str(MM_typecode matcode)
     else
     if (mm_is_symmetric(matcode))
         types[3] = MM_SYMM_STR;
-    else 
+    else
     if (mm_is_hermitian(matcode))
         types[3] = MM_HERM_STR;
-    else 
+    else
     if (mm_is_skew(matcode))
         types[3] = MM_SKEW_STR;
     else