| 1 |
/* |
| 2 |
//@HEADER |
| 3 |
// *********************************************************************** |
| 4 |
// |
| 5 |
// AztecOO: An Object-Oriented Aztec Linear Solver Package |
| 6 |
// Copyright (2002) Sandia Corporation |
| 7 |
// |
| 8 |
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive |
| 9 |
// license for use of this work by or on behalf of the U.S. Government. |
| 10 |
// |
| 11 |
// Redistribution and use in source and binary forms, with or without |
| 12 |
// modification, are permitted provided that the following conditions are |
| 13 |
// met: |
| 14 |
// |
| 15 |
// 1. Redistributions of source code must retain the above copyright |
| 16 |
// notice, this list of conditions and the following disclaimer. |
| 17 |
// |
| 18 |
// 2. Redistributions in binary form must reproduce the above copyright |
| 19 |
// notice, this list of conditions and the following disclaimer in the |
| 20 |
// documentation and/or other materials provided with the distribution. |
| 21 |
// |
| 22 |
// 3. Neither the name of the Corporation nor the names of the |
| 23 |
// contributors may be used to endorse or promote products derived from |
| 24 |
// this software without specific prior written permission. |
| 25 |
// |
| 26 |
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY |
| 27 |
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 28 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 29 |
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE |
| 30 |
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 31 |
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 32 |
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 33 |
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 34 |
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 35 |
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 36 |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 37 |
// |
| 38 |
// Questions? Contact Michael A. Heroux ([email protected]) |
| 39 |
// |
| 40 |
// *********************************************************************** |
| 41 |
//@HEADER |
| 42 |
*/ |
| 43 |
|
| 44 |
#include <stdlib.h> |
| 45 |
#include <stdio.h> |
| 46 |
#include "az_aztec.h" |
| 47 |
|
| 48 |
void read_coo(char *data_file, int *proc_config, |
| 49 |
int *N_global, int *n_nonzeros, |
| 50 |
double **val, int **bindx, |
| 51 |
double **x, double **b, double **xexact) |
| 52 |
#undef DEBUG |
| 53 |
/* read ASCII data file: |
| 54 |
line 1: N_global, number of entries (%d,%d) |
| 55 |
line 2-...: i,j,real (%d, %d, %f) |
| 56 |
*/ |
| 57 |
|
| 58 |
{ |
| 59 |
FILE *data ; |
| 60 |
|
| 61 |
|
| 62 |
int i, n_entries, N_columns; |
| 63 |
int ii, jj ; |
| 64 |
int kk = 0; |
| 65 |
int max_ii = 0, max_jj = 0; |
| 66 |
int ione = 1; |
| 67 |
double value; |
| 68 |
double *cnt; |
| 69 |
int *pntr, *indx1, *pntr1; |
| 70 |
double *val1; |
| 71 |
|
| 72 |
int MAXBLOCKSIZE = 25; |
| 73 |
|
| 74 |
if(proc_config[AZ_node] == 0) |
| 75 |
{ |
| 76 |
|
| 77 |
|
| 78 |
data = fopen(data_file,"r") ; |
| 79 |
|
| 80 |
fscanf(data, "%d %d %d", N_global, &N_columns, &n_entries) ; |
| 81 |
if (N_columns != *N_global) |
| 82 |
perror("Matrix dimensions must be the same"); |
| 83 |
printf("Reading from file: %s\n",data_file); |
| 84 |
printf("Number of equations = %d\n",*N_global); |
| 85 |
printf("Number of entries = %d\n",n_entries); |
| 86 |
|
| 87 |
|
| 88 |
*bindx = (int *) calloc(n_entries+1,sizeof(int)) ; |
| 89 |
*val = (double *) calloc(n_entries+1,sizeof(double)) ; |
| 90 |
|
| 91 |
pntr1 = (int *) calloc(n_entries+1,sizeof(int)) ; |
| 92 |
indx1 = (int *) calloc(n_entries+1,sizeof(int)) ; |
| 93 |
val1 = (double *) calloc(n_entries+1,sizeof(double)) ; |
| 94 |
|
| 95 |
pntr = (int *) calloc(n_entries+1,sizeof(int)) ; |
| 96 |
|
| 97 |
if ((pntr) == NULL) |
| 98 |
perror("Error: Not enough space to create matrix"); |
| 99 |
|
| 100 |
while(!feof(data)) |
| 101 |
{ |
| 102 |
fscanf(data, "%d %d %lf", &ii, &jj, &value) ; |
| 103 |
max_ii = AZ_MAX(max_ii,ii); |
| 104 |
max_jj = AZ_MAX(max_jj,jj); |
| 105 |
#ifdef DEBUG |
| 106 |
printf("Entry %d, %d = %lf.\n",ii,jj,value); |
| 107 |
#endif |
| 108 |
(*bindx)[kk] = ii; |
| 109 |
pntr[kk] = jj; |
| 110 |
(*val)[kk] = value; |
| 111 |
kk++; |
| 112 |
} |
| 113 |
*n_nonzeros = kk-1; |
| 114 |
*N_global = max_ii; |
| 115 |
if (max_ii != max_jj) perror("Error: Number of rows and columns not equal"); |
| 116 |
|
| 117 |
printf("Number of nonzeros = %d\n",*n_nonzeros); |
| 118 |
|
| 119 |
/* Convert real part in the following way: |
| 120 |
- Convert COO to CSR |
| 121 |
- CSR to CSC |
| 122 |
- CSC to CSR (columns are now in ascending order) |
| 123 |
- CSR to MSR |
| 124 |
*/ |
| 125 |
coocsr_(N_global,n_nonzeros, *val, *bindx, pntr, val1, indx1, pntr1); |
| 126 |
|
| 127 |
csrcsc_(N_global,&ione,&ione, |
| 128 |
val1,indx1,pntr1, |
| 129 |
*val,*bindx,pntr); |
| 130 |
|
| 131 |
csrcsc_(N_global,&ione,&ione, |
| 132 |
*val,*bindx,pntr, |
| 133 |
val1,indx1,pntr1); |
| 134 |
|
| 135 |
csrmsr_(N_global,val1,indx1,pntr1, |
| 136 |
*val,*bindx, |
| 137 |
*val,*bindx); |
| 138 |
|
| 139 |
/* Finally, convert bindx vectors to zero base */ |
| 140 |
|
| 141 |
for (i=0;i<*n_nonzeros+1;i++) |
| 142 |
(*bindx)[i] -= 1; |
| 143 |
|
| 144 |
*b = (double *) calloc((*N_global)*MAXBLOCKSIZE,sizeof(double)) ; |
| 145 |
*x = (double *) calloc((*N_global)*MAXBLOCKSIZE,sizeof(double)) ; |
| 146 |
|
| 147 |
if ((*x) == NULL) |
| 148 |
perror("Error: Not enough space to create matrix"); |
| 149 |
|
| 150 |
|
| 151 |
/* Set RHS to a random vector, initial guess to zero */ |
| 152 |
for (i=0;i<*N_global;i++) |
| 153 |
{ |
| 154 |
(*b)[i] = drand48(); |
| 155 |
(*x)[i] = 0.0; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
/* Release unneeded space */ |
| 160 |
|
| 161 |
free((void *) pntr); |
| 162 |
free((void *) val1); |
| 163 |
free((void *) indx1); |
| 164 |
free((void *) pntr1); |
| 165 |
|
| 166 |
|
| 167 |
/* end read_coo */ |
| 168 |
} |