diff --git a/src/mat/examples/tests/ex190.c b/src/mat/examples/tests/ex190.c index 909ce9c..6eeb41d 100644 --- a/src/mat/examples/tests/ex190.c +++ b/src/mat/examples/tests/ex190.c @@ -1,4 +1,4 @@ -static char help[] = "Tests MatLoad() with blocksize set in in program\n\n"; +static char help[] = "Tests MatLoad() with uneven dimensions set in program\n\n"; #include @@ -11,8 +11,10 @@ PetscInt main(PetscInt argc,char **args) char file[PETSC_MAX_PATH_LEN]; PetscErrorCode ierr; PetscBool flg; + PetscMPIInt rank; PetscInitialize(&argc,&args,(char*)0,help); + ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); /* Determine files from which we read the matrix */ ierr = PetscOptionsGetString(NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr); @@ -21,9 +23,13 @@ PetscInt main(PetscInt argc,char **args) /* Load matrices */ ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);CHKERRQ(ierr); ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr); - ierr = MatSetType(A,MATSBAIJ);CHKERRQ(ierr); ierr = MatSetFromOptions(A);CHKERRQ(ierr); ierr = MatSetBlockSize(A,2);CHKERRQ(ierr); + if (!rank) { + ierr = MatSetSizes(A, 4, PETSC_DETERMINE, PETSC_DETERMINE,PETSC_DETERMINE);CHKERRQ(ierr); + } else { + ierr = MatSetSizes(A, 8, PETSC_DETERMINE, PETSC_DETERMINE,PETSC_DETERMINE);CHKERRQ(ierr); + } ierr = MatLoad(A,fd);CHKERRQ(ierr); ierr = PetscViewerDestroy(&fd);CHKERRQ(ierr); ierr = MatDestroy(&A);CHKERRQ(ierr); diff --git a/src/mat/examples/tests/makefile b/src/mat/examples/tests/makefile index 59bc4a7..bfd6cf0 100644 --- a/src/mat/examples/tests/makefile +++ b/src/mat/examples/tests/makefile @@ -21,7 +21,7 @@ EXAMPLESC = ex1.c ex2.c ex3.c ex4.c ex5.c ex6.c ex7.c ex8.c ex9.c \ ex129.c ex130.c ex131.c ex132.c ex133.c ex134.c ex135.c \ ex136.c ex137.c ex138.c ex139.c ex140.c ex141.c ex142.c \ ex143.c ex144.c ex145.c ex146.c ex147.c ex148.c ex149.c \ - ex150.c ex151.c ex152.c ex153.c ex155.c ex157.c ex158.c ex159.c ex164.c ex169.c ex180.c + ex150.c ex151.c ex152.c ex153.c ex155.c ex157.c ex158.c ex159.c ex164.c ex169.c ex180.c ex190.c EXAMPLESF = ex16f90.F ex36f.F ex58f.F ex63f.F ex67f.F ex79f.F ex85f.F ex105f.F ex120f.F ex126f.F ex171f.F include ${PETSC_DIR}/conf/variables @@ -681,6 +681,10 @@ ex180: ex180.o chkopts -${CLINKER} -o ex180 ex180.o ${PETSC_MAT_LIB} ${RM} ex180.o +ex190: ex190.o chkopts + -${CLINKER} -o ex190 ex190.o ${PETSC_MAT_LIB} + ${RM} ex190.o + #----------------------------------------------------------------------------- NPROCS = 1 3 MATSHAPES = A B @@ -2038,6 +2042,14 @@ runex180: runex171f: -@${MPIEXEC} -n 1 ./ex171f +runex190: + -@${MPIEXEC} -n 2 ./ex190 -mat_type aij -mat_view -f ${PETSC_DIR}/share/petsc/datafiles/matrices/ns-real-int32-float64 > ex190.tmp 2>&1; \ + ${MPIEXEC} -n 2 ./ex190 -mat_type baij -mat_view -f ${PETSC_DIR}/share/petsc/datafiles/matrices/ns-real-int32-float64 >> ex190.tmp 2>&1; \ + ${MPIEXEC} -n 2 ./ex190 -mat_type sbaij -mat_view -f ${PETSC_DIR}/share/petsc/datafiles/matrices/ns-real-int32-float64 >> ex190.tmp 2>&1; \ + ${DIFF} output/ex190_1.out ex190.tmp || printf "${PWD}\nPossible problem with ex190, diffs above\n=========================================\n"; \ + ${RM} -f ex190.tmp + + TESTEXAMPLES_C = ex1.PETSc runex1 ex1.rm ex3.PETSc runex3 ex3.rm ex4.PETSc ex4.rm ex5.PETSc runex5 runex5_2 ex5.rm \ ex6.PETSc runex6 ex6.rm ex8.PETSc runex8 ex8.rm ex9.PETSc runex9 runex9_2 runex9_3 ex9.rm ex10.PETSc \ runex10 ex10.rm ex11.PETSc runex11 runex11_2 runex11_3 runex11_4 ex11.rm ex14.PETSc \ @@ -2098,7 +2110,7 @@ TESTEXAMPLES_DATAFILESPATH = ex40.PETSc runex40 ex40.rm ex41.PETSc runex41 e ex138.PETSc runex138_1 runex138_2 ex138.rm \ ex140.PETSc runex140 runex140_2 runex140_3 runex140_4 ex140.rm \ ex100.PETSc runex100 ex100.rm ex125.PETSc runex125 ex125.rm \ - ex163.PETSc runex163 runex163_2 ex163.rm ex169.PETSc runex169 ex169.rm ex180.PETSc runex180 ex180.rm + ex163.PETSc runex163 runex163_2 ex163.rm ex169.PETSc runex169 ex169.rm ex180.PETSc runex180 ex180.rm ex190.PETSc runex190 ex190.rm TESTEXAMPLES_FORTRAN_NOCOMPLEX = ex67f.PETSc runex67f ex67f.rm ex79f.PETSc runex79f ex79f.rm TESTEXAMPLES_F90 = ex16f90.PETSc runex16f90 ex16f90.rm TESTEXAMPLES_13 = ex58f.PETSc ex58f.rm ex70.PETSc ex70.rm ex72.PETSc ex72.rm diff --git a/src/mat/impls/aij/mpi/mpiaij.c b/src/mat/impls/aij/mpi/mpiaij.c index 88d7cf3..e00f0c1 100644 --- a/src/mat/impls/aij/mpi/mpiaij.c +++ b/src/mat/impls/aij/mpi/mpiaij.c @@ -3319,10 +3319,10 @@ PetscErrorCode MatLoad_MPIAIJ(Mat newMat, PetscViewer viewer) MPI_Comm comm; PetscErrorCode ierr; PetscMPIInt rank,size,tag = ((PetscObject)viewer)->tag; - PetscInt i,nz,j,rstart,rend,mmax,maxnz = 0,grows,gcols; + PetscInt i,nz,j,rstart,rend,mmax,maxnz = 0; PetscInt header[4],*rowlengths = 0,M,N,m,*cols; PetscInt *ourlens = NULL,*procsnz = NULL,*offlens = NULL,jj,*mycols,*smycols; - PetscInt cend,cstart,n,*rowners,sizesset=1; + PetscInt cend,cstart,n,*rowners; int fd; PetscInt bs = newMat->rmap->bs; @@ -3341,20 +3341,12 @@ PetscErrorCode MatLoad_MPIAIJ(Mat newMat, PetscViewer viewer) ierr = PetscOptionsEnd();CHKERRQ(ierr); if (bs < 0) bs = 1; - if (newMat->rmap->n < 0 && newMat->rmap->N < 0 && newMat->cmap->n < 0 && newMat->cmap->N < 0) sizesset = 0; - ierr = MPI_Bcast(header+1,3,MPIU_INT,0,comm);CHKERRQ(ierr); M = header[1]; N = header[2]; - /* If global rows/cols are set to PETSC_DECIDE, set it to the sizes given in the file */ - if (sizesset && newMat->rmap->N < 0) newMat->rmap->N = M; - if (sizesset && newMat->cmap->N < 0) newMat->cmap->N = N; /* If global sizes are set, check if they are consistent with that given in the file */ - if (sizesset) { - ierr = MatGetSize(newMat,&grows,&gcols);CHKERRQ(ierr); - } - if (sizesset && newMat->rmap->N != grows) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Inconsistent # of rows:Matrix in file has (%d) and input matrix has (%d)",M,grows); - if (sizesset && newMat->cmap->N != gcols) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Inconsistent # of cols:Matrix in file has (%d) and input matrix has (%d)",N,gcols); + if (newMat->rmap->N >= 0 && newMat->rmap->N != M) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,"Inconsistent # of rows:Matrix in file has (%D) and input matrix has (%D)",newMat->rmap->N,M); + if (newMat->cmap->N >=0 && newMat->cmap->N != N) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,"Inconsistent # of cols:Matrix in file has (%D) and input matrix has (%D)",newMat->cmap->N,N); /* determine ownership of all (block) rows */ if (M%bs) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Inconsistent # of rows (%d) and block size (%d)",M,bs); @@ -3458,9 +3450,7 @@ PetscErrorCode MatLoad_MPIAIJ(Mat newMat, PetscViewer viewer) for (i=0; i 1) {ierr = MatSetBlockSize(newMat,bs);CHKERRQ(ierr);} diff --git a/src/mat/impls/baij/mpi/mpibaij.c b/src/mat/impls/baij/mpi/mpibaij.c index 200b2c2..5bbb7bc 100644 --- a/src/mat/impls/baij/mpi/mpibaij.c +++ b/src/mat/impls/baij/mpi/mpibaij.c @@ -3405,7 +3405,7 @@ PetscErrorCode MatLoad_MPIBAIJ(Mat newmat,PetscViewer viewer) PetscInt jj,*mycols,*ibuf,bs = newmat->rmap->bs,Mbs,mbs,extra_rows,mmax; PetscMPIInt tag = ((PetscObject)viewer)->tag; PetscInt *dlens = NULL,*odlens = NULL,*mask = NULL,*masked1 = NULL,*masked2 = NULL,rowcount,odcount; - PetscInt dcount,kmax,k,nzcount,tmp,mend,sizesset=1,grows,gcols; + PetscInt dcount,kmax,k,nzcount,tmp,mend; PetscFunctionBegin; ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr); @@ -3421,22 +3421,12 @@ PetscErrorCode MatLoad_MPIBAIJ(Mat newmat,PetscViewer viewer) ierr = PetscBinaryRead(fd,(char*)header,4,PETSC_INT);CHKERRQ(ierr); if (header[0] != MAT_FILE_CLASSID) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,"not matrix object"); } - - if (newmat->rmap->n < 0 && newmat->rmap->N < 0 && newmat->cmap->n < 0 && newmat->cmap->N < 0) sizesset = 0; - ierr = MPI_Bcast(header+1,3,MPIU_INT,0,comm);CHKERRQ(ierr); M = header[1]; N = header[2]; - /* If global rows/cols are set to PETSC_DECIDE, set it to the sizes given in the file */ - if (sizesset && newmat->rmap->N < 0) newmat->rmap->N = M; - if (sizesset && newmat->cmap->N < 0) newmat->cmap->N = N; - /* If global sizes are set, check if they are consistent with that given in the file */ - if (sizesset) { - ierr = MatGetSize(newmat,&grows,&gcols);CHKERRQ(ierr); - } - if (sizesset && newmat->rmap->N != grows) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Inconsistent # of rows:Matrix in file has (%d) and input matrix has (%d)",M,grows); - if (sizesset && newmat->cmap->N != gcols) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Inconsistent # of cols:Matrix in file has (%d) and input matrix has (%d)",N,gcols); + if (newmat->rmap->N >= 0 && newmat->rmap->N != M) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,"Inconsistent # of rows:Matrix in file has (%D) and input matrix has (%D)",newmat->rmap->N,M); + if (newmat->cmap->N >= 0 && newmat->cmap->N != N) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,"Inconsistent # of cols:Matrix in file has (%D) and input matrix has (%D)",newmat->cmap->N,N); if (M != N) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Can only do square matrices"); @@ -3580,10 +3570,7 @@ PetscErrorCode MatLoad_MPIBAIJ(Mat newmat,PetscViewer viewer) for (j=0; jrmap->bs,Mbs,mbs,extra_rows; PetscInt *dlens,*odlens,*mask,*masked1,*masked2,rowcount,odcount; - PetscInt dcount,kmax,k,nzcount,tmp,sizesset=1,grows,gcols; + PetscInt dcount,kmax,k,nzcount,tmp; int fd; PetscFunctionBegin; @@ -2205,22 +2205,13 @@ PetscErrorCode MatLoad_MPISBAIJ(Mat newmat,PetscViewer viewer) if (header[3] < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED,"Matrix stored in special format, cannot load as MPISBAIJ"); } - if (newmat->rmap->n < 0 && newmat->rmap->N < 0 && newmat->cmap->n < 0 && newmat->cmap->N < 0) sizesset = 0; - ierr = MPI_Bcast(header+1,3,MPIU_INT,0,comm);CHKERRQ(ierr); M = header[1]; N = header[2]; - /* If global rows/cols are set to PETSC_DECIDE, set it to the sizes given in the file */ - if (sizesset && newmat->rmap->N < 0) newmat->rmap->N = M; - if (sizesset && newmat->cmap->N < 0) newmat->cmap->N = N; - /* If global sizes are set, check if they are consistent with that given in the file */ - if (sizesset) { - ierr = MatGetSize(newmat,&grows,&gcols);CHKERRQ(ierr); - } - if (sizesset && newmat->rmap->N != grows) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Inconsistent # of rows:Matrix in file has (%d) and input matrix has (%d)",M,grows); - if (sizesset && newmat->cmap->N != gcols) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Inconsistent # of cols:Matrix in file has (%d) and input matrix has (%d)",N,gcols); + if (newmat->rmap->N >= 0 && newmat->rmap->N != M) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Inconsistent # of rows:Matrix in file has (%D) and input matrix has (%D)",newmat->rmap->N,M); + if (newmat->cmap->N >= 0 && newmat->cmap->N != N) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_FILE_UNEXPECTED, "Inconsistent # of cols:Matrix in file has (%D) and input matrix has (%D)",newmat->cmap->N,N); if (M != N) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Can only do square matrices"); @@ -2352,9 +2343,7 @@ PetscErrorCode MatLoad_MPISBAIJ(Mat newmat,PetscViewer viewer) for (j=0; j 0) PetscValidLogicalCollectiveInt(A,N,5); if (M > 0 && m > M) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Local column size %D cannot be larger than global column size %D",m,M); if (N > 0 && n > N) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Local row size %D cannot be larger than global row size %D",n,N); - if ((A->rmap->n >= 0 || A->rmap->N >= 0) && (A->rmap->n != m || A->rmap->N != M)) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot change/reset row sizes to %D local %D global after previously setting them to %D local %D global",m,M,A->rmap->n,A->rmap->N); - if ((A->cmap->n >= 0 || A->cmap->N >= 0) && (A->cmap->n != n || A->cmap->N != N)) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot change/reset column sizes to %D local %D global after previously setting them to %D local %D global",n,N,A->cmap->n,A->cmap->N); + if ((A->rmap->n >= 0 && A->rmap->N >= 0) && (A->rmap->n != m || A->rmap->N != M)) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot change/reset row sizes to %D local %D global after previously setting them to %D local %D global",m,M,A->rmap->n,A->rmap->N); + if ((A->cmap->n >= 0 && A->cmap->N >= 0) && (A->cmap->n != n || A->cmap->N != N)) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot change/reset column sizes to %D local %D global after previously setting them to %D local %D global",n,N,A->cmap->n,A->cmap->N); A->rmap->n = m; A->cmap->n = n; A->rmap->N = M;