Ifpack Package Browser (Single Doxygen Collection) Development
read_coo.c
Go to the documentation of this file.
00001 /*@HEADER
00002 // ***********************************************************************
00003 // 
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 //@HEADER
00028 */
00029 
00030 #include <stdlib.h>
00031 #include <stdio.h>
00032 #include "paz_aztec.h"
00033 
00034 void read_coo(char *data_file, int *proc_config,
00035         int *N_global, int *n_nonzeros,
00036         double **val, int **bindx,
00037         double **x, double **b, double **xexact)
00038 #undef DEBUG 
00039      /*  read ASCII data file:
00040    line 1: N_global, number of entries (%d,%d)
00041    line 2-...: i,j,real (%d, %d, %f)
00042      */
00043 
00044 {
00045   FILE *data ;
00046 
00047 
00048   int i, n_entries, N_columns;
00049   int ii, jj ;
00050   int kk = 0;
00051   int max_ii = 0, max_jj = 0;
00052   int ione = 1;
00053   double value;
00054   double *cnt;
00055   int *pntr, *indx1, *pntr1;
00056   double *val1;
00057 
00058   int MAXBLOCKSIZE = 25;
00059   
00060   if(proc_config[PAZ_node] == 0) 
00061     { 
00062 
00063  
00064       data = fopen(data_file,"r") ;
00065  
00066       fscanf(data, "%d %d %d", N_global, &N_columns, &n_entries) ;
00067       if (N_columns != *N_global)
00068   perror("Matrix dimensions must be the same");
00069       printf("Reading from file: %s\n",data_file);
00070       printf("Number of equations = %d\n",*N_global);
00071       printf("Number of entries   = %d\n",n_entries);
00072     
00073 
00074       *bindx = (int   *) calloc(n_entries+1,sizeof(int)) ;
00075       *val = (double *) calloc(n_entries+1,sizeof(double)) ;
00076 
00077       pntr1 = (int   *) calloc(n_entries+1,sizeof(int)) ;
00078       indx1 = (int   *) calloc(n_entries+1,sizeof(int)) ;
00079       val1 = (double *) calloc(n_entries+1,sizeof(double)) ;
00080   
00081       pntr = (int   *) calloc(n_entries+1,sizeof(int)) ;
00082 
00083       if ((pntr) == NULL) 
00084   perror("Error: Not enough space to create matrix");
00085 
00086       while(!feof(data))
00087   {
00088     fscanf(data, "%d %d %lf", &ii, &jj, &value) ;
00089     max_ii = max(max_ii,ii);
00090     max_jj = max(max_jj,jj);
00091 #ifdef DEBUG
00092     printf("Entry %d, %d = %lf.\n",ii,jj,value);
00093 #endif
00094     (*bindx)[kk] = ii;
00095     pntr[kk] = jj;
00096     (*val)[kk] = value;
00097     kk++;
00098   }
00099       *n_nonzeros = kk-1;
00100       *N_global = max_ii;
00101       if (max_ii != max_jj) perror("Error: Number of rows and columns not equal");
00102 
00103       printf("Number of nonzeros = %d\n",*n_nonzeros);
00104 
00105       /* Convert real part in the following way:
00106    - Convert COO to CSR
00107    - CSR to CSC
00108    - CSC to CSR (columns are now in ascending order)
00109    - CSR to MSR
00110       */
00111       coocsr_(N_global,n_nonzeros, *val, *bindx, pntr, val1, indx1, pntr1);
00112 
00113       csrcsc_(N_global,&ione,&ione,
00114         val1,indx1,pntr1,
00115         *val,*bindx,pntr);
00116 
00117       csrcsc_(N_global,&ione,&ione,
00118         *val,*bindx,pntr,
00119         val1,indx1,pntr1);
00120 
00121       csrmsr_(N_global,val1,indx1,pntr1,
00122         *val,*bindx,
00123         *val,*bindx);
00124 
00125       /* Finally, convert bindx vectors to zero base */
00126 
00127       for (i=0;i<*n_nonzeros+1;i++)
00128   (*bindx)[i] -= 1;
00129 
00130       *b = (double   *) calloc((*N_global)*MAXBLOCKSIZE,sizeof(double)) ;
00131       *x = (double   *) calloc((*N_global)*MAXBLOCKSIZE,sizeof(double)) ;
00132 
00133       if ((*x) == NULL) 
00134   perror("Error: Not enough space to create matrix");
00135 
00136   
00137       /* Set RHS to a random vector, initial guess to zero */
00138       for (i=0;i<*N_global;i++)
00139   {
00140     (*b)[i] = drand48();
00141     (*x)[i] = 0.0;
00142   }
00143   }
00144    
00145       /* Release unneeded space */
00146 
00147   free((void *) pntr);
00148   free((void *) val1);
00149   free((void *) indx1);
00150   free((void *) pntr1);
00151   
00152   
00153   /* end read_coo */
00154 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines