# Elemtary matrix to CSR global matrix

 Register Blogs Members List Search Today's Posts Mark Forums Read

 September 19, 2002, 12:42 Elemtary matrix to CSR global matrix #1 xueying Guest   Posts: n/a How can I assemble elemtary matrix to global matrix in CSR format? If anybody has this subroutine, can you share it with me?

 September 22, 2002, 14:50 Re: Elemtary matrix to CSR global matrix #2 Wen Long Guest   Posts: n/a Here is my C progam, can you try it? //-------------- /*Using Compressed Row Storage method to represente a sparce matrix to do A*Vin=Vout (matrix vector multiplying) */ #include #include /*#define N 100; */ /*The maximum size of the matrix is N*N */ void main(void) { float E[10000]; long int C[10000],R[101]; /* E[]----Element value vector C[]----Column index vector R[]----Row position vector */ float Vin[100], Vout[100]; /* Vin[N]---Input vector */ /* Vout[N]---Output vector, Vout[]=A*Vin[] */ long int n; /*actual matrix size */ long int num; long int i; void multiply(float*,long int *, long int *, long int ,float *,float * ); Again: printf("Input size of matrix A, n=:\n"); scanf("%d",&n); if(n>100) {printf("n must < 100!, try again\n"); goto Again; } printf("Input total number of non-zero elements in A\n"); scanf("%d",&num); for(i=0;i

 September 24, 2002, 09:44 Re: Elemtary matrix to CSR global matrix #3 Wen Long Guest   Posts: n/a Sorry, some chars missing when I was copying it (seems funny). Here is the right one: /*Using Compressed Row Storage method to represente a sparce matrix to do A*Vin (matrix vector multiplying) */ #include #include /*#define N 100; */ /*The maximum size of the matrix is N*N */ void main(void) { float E[10000]; long int C[10000],R[101]; /* E[]----Element value vector C[]----Column index vector R[]----Row position vector */ float Vin[100], Vout[100]; /* Vin[N]---Input vector */ /* Vout[N]---Output vector, Vout[]=A*Vin[] */ long int n; /*actual matrix size */ long int num; long int i; void multiply(float*,long int *, long int *, long int ,float *,float * ); Again: printf("Input size of matrix A, n=:\n"); scanf("%d",&n); if(n>100) {printf("n must < 100!, try again\n"); goto Again; } printf("Input total number of non-zero elements in A\n"); scanf("%d",&num); for(i=0; i < num ; i++) /* input E[] and C[] */ { printf("E[%d]=\n",i); scanf("%f",&E[i]); printf("C[%d]=\n",i); scanf("%d",&C[i]); } for(i=0; i < = n; i++) /*input R[] */ { printf("R[%d]=\n",i); scanf("%d",&R[i]); } for(i=0; i < n; i++) /*input Vin[] */ { printf("Vin[%d]=\n",i); scanf("%f",&Vin[i]); } multiply(E,C,R,n,Vin,Vout); /*do the calculation */ printf("Vout[%d=",n); /* print Vout[n] */ for(i=0 ; i < n ; i++) { printf("%10f\n",Vout[i]); } } void multiply(float *pE, long int *pC, long int *pR, long int n, float *pVin, float *pVout) { /* pE----pointer to array E */ /* pC----pointer to array C */ /* pR----pointer to array R */ /* pVin---pointer to array Vin */ /* pVout---pointer to array Vout */ int i,j; for(i=0; i < n; i++) /* row i of A */ { pVout[i]=0; for(j=pR[i];j