Commits

Hong Zhang committed 02e9429

cleanup MatGetMultiProcBlock_MPIBAIJ()

Comments (0)

Files changed (2)

src/ksp/ksp/examples/tutorials/makefile

                                  ex23.PETSc runex23 runex23_2 ex23.rm  ex25.PETSc runex25 runex25_2 ex25.rm \
                                  ex27.PETSc ex27.rm ex28.PETSc ex28.rm ex29.PETSc  ex29.rm \
                                  ex31.PETSc ex31.rm ex32.PETSc runex32 ex32.rm ex34.PETSc runex34 ex34.rm ex38.PETSc runex38 ex38.rm \
-                                 ex43.PETSc runex43 runex43_2 runex43_3 ex43.rm \
+                                 ex43.PETSc runex43 runex43_2 runex43_3 runex43_bjacobi runex43_bjacobi_baij ex43.rm \
                                  ex45.PETSc runex45 runex45_2 ex45.rm \
                                  ex49.PETSc runex49 runex49_2 runex49_3 ex49.rm ex53.PETSc runex53 ex53.rm ex55.PETSc runex55_SA ex55.rm\
                                  ex58.PETSc runex58 runex58_baij runex58_sbaij ex58.rm

src/mat/impls/baij/mpi/mpb_baij.c

   Mat_SeqBAIJ    *aijB = (Mat_SeqBAIJ*)aij->B->data;
   PetscMPIInt    commRank,subCommSize,subCommRank;
   PetscMPIInt    *commRankMap,subRank,rank,commsize;
-  PetscInt       *garrayCMap,col,i,j,*nnz,newRow,newCol;
+  PetscInt       *garrayCMap,col,i,j,*nnz,newRow,newCol,*newbRow,*newbCol,k,k1;
   PetscInt       bs=mat->rmap->bs;
-  PetscScalar    vals[bs*bs];
-  PetscInt       newbRow[bs],newbCol[bs],k,k1,k2;
+  PetscScalar    *vals,*aijBvals;
 
   PetscFunctionBegin;
   ierr = MPI_Comm_size(PetscObjectComm((PetscObject)mat),&commsize);CHKERRQ(ierr);
     for (subRank=0; subRank<subCommSize; subRank++) {
       rank = commRankMap[subRank];
       if ((col >= mat->cmap->range[rank]/bs) && (col < mat->cmap->range[rank+1]/bs)) {
-        garrayCMap[i] = ((*subMat)->cmap->range[subRank]/bs + col - mat->cmap->range[rank]/bs+1);
+        garrayCMap[i] = (((*subMat)->cmap->range[subRank]- mat->cmap->range[rank])/bs + col + 1);
         break;
       }
     }
   }
 
   /* Now traverse aij->B and insert values into subMat */
+  ierr = PetscMalloc3(bs,PetscInt,&newbRow,bs,PetscInt,&newbCol,bs*bs,PetscScalar,&vals);CHKERRQ(ierr);
   for (i=0; i<aij->B->rmap->n/bs; i++) {
     newRow = (*subMat)->rmap->range[subCommRank] + i*bs;
     for (j=aijB->i[i]; j<aijB->i[i+1]; j++) {
           newbCol[k] = newCol + k;
         }
         /* copy column-oriented aijB->a into row-oriented vals */
-        k=0;
+        aijBvals = aijB->a + j*bs*bs;
         for (k1=0; k1<bs; k1++) { 
-          for (k2=0; k2<bs; k2++) { 
-            vals[k1+k2*bs] = *(aijB->a+j*bs*bs + k); k++; 
+          for (k=0; k<bs; k++) { 
+            vals[k1+k*bs] = *aijBvals++; 
           }
         }
         ierr = MatSetValues(*subMat,bs,newbRow,bs,newbCol,vals,INSERT_VALUES);CHKERRQ(ierr); 
       }
     }
   }
-
-  /* assemble the submat */
   ierr = MatAssemblyBegin(*subMat,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
   ierr = MatAssemblyEnd(*subMat,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
 
   /* deallocate temporary data */
+  ierr = PetscFree3(newbRow,newbCol,vals);CHKERRQ(ierr);
   ierr = PetscFree(commRankMap);CHKERRQ(ierr);
   ierr = PetscFree(garrayCMap);CHKERRQ(ierr);
   if (scall == MAT_INITIAL_MATRIX) {