Note the code in the example

  /* Open viewer for binary output */
  ierr = 
PetscViewerBinaryOpen(PETSC_COMM_SELF,"input.dat",FILE_MODE_WRITE,&view_out);CHKERRQ(ierr);
  ierr = PetscViewerBinaryGetDescriptor(view_out,&fd);CHKERRQ(ierr);

  /* Write binary output */
  ierr = PetscBinaryWrite(fd,&m,1,PETSC_INT,PETSC_FALSE);CHKERRQ(ierr);
  ierr = PetscBinaryWrite(fd,array,m,PETSC_SCALAR,PETSC_FALSE);CHKERRQ(ierr);

  this means each process is opening the same file for writing (because the 
argument to PetscViewerBinaryOpen() is PETSC_COMM_SELF) and then all of the 
processes are writing to this same file (completely uncoordinated). In general 
this won't work, it will just make a mess of things. This is why this example 
has the line

> if (size != 1) SETERRQ(PETSC_COMM_SELF,1,"This is a uniprocessor example 
> only!");

   Barry


> On Nov 17, 2018, at 1:12 PM, Fazlul Huq via petsc-users 
> <petsc-users@mcs.anl.gov> wrote:
> 
> Hello PETSc developers,
> 
> In example 6 or vec section I don't understand this line:
> if (size != 1) SETERRQ(PETSC_COMM_SELF,1,"This is a uniprocessor example 
> only!");
> 
> I tried to run the code with "mpiexec -n 2 ./ex6" or "mpiexec -n 4 ./ex6" or 
> even "mpiexec -n 1 ./ex6" it the code runs properly.
> 
> Thanks.
> 
> Sincerely,
> Huq
> 
> -- 
> 
> Fazlul Huq
> Graduate Research Assistant
> Department of Nuclear, Plasma & Radiological Engineering (NPRE)
> University of Illinois at Urbana-Champaign (UIUC)
> E-mail: huq2...@gmail.com

Reply via email to