[petsc-users] block size

Anton Popov popov at uni-mainz.de
Wed Jul 18 07:54:56 CDT 2012


Dear petsc team,

could you please tell me what's wrong with the attached example file?
I run it on 4 processors with petsc-3.3-p1.

What could error message "Local size 1000 not compatible with block size 
3!" mean?

I've another question related to this issue. What is the real purpose of 
PetscViewerBinarySkipInfo function?
I see no reason to skip creating "info" file, because the file produced 
by the attached example seems to be correct.

Moreover, similar block size error occurs in our code while reading file 
with multiple vectors, irrespective whether "info" file exists or not.

Thank you,

Anton

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120718/cd65a159/attachment.html>
-------------- next part --------------
//----------------------------------------------------------------------------------------

#include <petscvec.h>
#include <petscdmda.h>   

//----------------------------------------------------------------------------------------

#undef __FUNCT__
#define __FUNCT__ "SaveVector"

PetscErrorCode SaveVector(Vec V3, Vec V1)
{
	PetscErrorCode ierr;
	PetscViewer    view_out;
	char           SaveFileName[PETSC_MAX_PATH_LEN]="vec.dat";

	ierr = PetscViewerCreate(PETSC_COMM_WORLD, &view_out);  	CHKERRQ(ierr);
	ierr = PetscViewerSetType(view_out, PETSCVIEWERBINARY);		CHKERRQ(ierr);
	ierr = PetscViewerFileSetMode(view_out, FILE_MODE_WRITE); 	CHKERRQ(ierr);
	ierr = PetscViewerFileSetName(view_out, SaveFileName); 		CHKERRQ(ierr);

	ierr = VecView(V1, view_out);                               CHKERRQ(ierr);
	ierr = VecView(V3, view_out);                               CHKERRQ(ierr);

	ierr = PetscViewerDestroy(&view_out);                       CHKERRQ(ierr);

	PetscFunctionReturn(0);
}

//----------------------------------------------------------------------------------------

#undef __FUNCT__
#define __FUNCT__ "ReadVector"

PetscErrorCode ReadVector(Vec V3, Vec V1)
{
	PetscErrorCode ierr;
	PetscViewer	   view_in;
	char           LoadFileName[PETSC_MAX_PATH_LEN]="vec.dat";

	printf("Reading vector\n");

	ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD, LoadFileName,
		FILE_MODE_READ, &view_in); CHKERRQ(ierr);


	ierr = VecLoad(V1, view_in);	CHKERRQ(ierr);
	ierr = VecLoad(V3, view_in);	CHKERRQ(ierr);


	ierr = PetscViewerDestroy(&view_in); CHKERRQ(ierr);

	PetscFunctionReturn(0);
}

//----------------------------------------------------------------------------------------

#undef __FUNCT__
#define __FUNCT__ "main"

int main(int argc,char **argv)
{

	PetscErrorCode   ierr;
	PetscInt         dof, s = 1;	
	PetscInt         M = 20, N = 20, P = 20;
	PetscScalar      cf = 1.0;
	DM               da3, da1;
	Vec              V3w, V3r, V1w, V1r;

	ierr = PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); CHKERRQ(ierr);

	dof = 3;
	ierr = DMDACreate3d(PETSC_COMM_WORLD,
		DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE, DMDA_STENCIL_BOX,
		M, N, P, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, dof, s,
		PETSC_NULL, PETSC_NULL, PETSC_NULL, &da3); CHKERRQ(ierr);

 	dof = 1;
 	ierr = DMDACreate3d(PETSC_COMM_WORLD,
		DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE, DMDA_STENCIL_BOX,
		M, N, P, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, dof, s,
		PETSC_NULL, PETSC_NULL, PETSC_NULL, &da1); CHKERRQ(ierr);

 
	ierr = DMCreateGlobalVector(da3, &V3w); CHKERRQ(ierr);
	ierr = DMCreateGlobalVector(da3, &V3r); CHKERRQ(ierr);

	ierr = DMCreateGlobalVector(da1, &V1w); CHKERRQ(ierr);
	ierr = DMCreateGlobalVector(da1, &V1r); CHKERRQ(ierr);

	ierr = VecSet(V3w, cf);  CHKERRQ(ierr);
	ierr = VecSet(V1w, cf);  CHKERRQ(ierr);

	ierr = SaveVector(V3w, V1w);  CHKERRQ(ierr);

	ierr = ReadVector(V3r, V1r);  CHKERRQ(ierr);


	ierr = DMDestroy(&da3);  CHKERRQ(ierr);
	ierr = DMDestroy(&da1);  CHKERRQ(ierr);

	ierr = VecDestroy(&V3w); CHKERRQ(ierr);
	ierr = VecDestroy(&V3r); CHKERRQ(ierr);

	ierr = VecDestroy(&V1w); CHKERRQ(ierr);
	ierr = VecDestroy(&V1r); CHKERRQ(ierr);

	ierr = PetscFinalize(); CHKERRQ(ierr);

	return 0;

}
//----------------------------------------------------------------------------------------


More information about the petsc-users mailing list