1 #ifndef lint 2 static char vcid[] = "$Id: axpy.c,v 1.1 1995/05/09 02:08:00 bsmith Exp bsmith $"; 3 #endif 4 5 6 #include "matimpl.h" 7 #include "options.h" 8 9 /*@ 10 MatAXPY - Y = a*X + Y 11 12 Input Parameters: 13 . X,Y - the matrices 14 . a - the scalar multiple 15 16 .keywods: Mat, add 17 @*/ 18 19 int MatAXPY(Scalar *a,Mat X,Mat Y) 20 { 21 int m1,m2,n1,n2,i,*row,start,end,j,ncols,ierr; 22 Scalar *val,*vals; 23 24 VALIDHEADER(X,MAT_COOKIE); VALIDHEADER(Y,MAT_COOKIE); 25 MatGetSize(X,&m1,&n1); MatGetSize(X,&m2,&n2); 26 if (m1 != m2 || n1 != n2) SETERR(1,"Non conforming matrix add"); 27 vals = (Scalar *) MALLOC( n1*sizeof(Scalar) ); CHKPTR(vals); 28 MatGetOwnershipRange(X,&start,&end); 29 for ( i=start; i<end; i++ ) { 30 MatGetRow(X,i,&ncols,&row,&val); 31 for ( j=0; j<ncols; j++ ) { 32 vals[j] = (*a)*val[j]; 33 } 34 ierr = MatSetValues(Y,1,&i,ncols,row,vals,ADDVALUES); CHKERR(ierr); 35 MatRestoreRow(X,i,&ncols,&row,&val); 36 } 37 FREE(vals); 38 ierr = MatAssemblyBegin(Y,FINAL_ASSEMBLY); CHKERR(ierr); 39 ierr = MatAssemblyEnd(Y,FINAL_ASSEMBLY); CHKERR(ierr); 40 return 0; 41 } 42