Commits

Jed Brown  committed 2240d71

VecView_MPI_ASCII: avoid PetscObjectGetName unless really needed

Historically, VecView output has not included names, but the previous
change to eagerly call PetscObjectGetName() changed output like

-Vec Object: 2 MPI processes
+Vec Object:Vec_0x84000005_0 2 MPI processes

This commit reverts to only name vectors when necessary. It fixes the
previously-inconsistent behavior where ranks other than 0 neglected to
call PetscObjectGetName for PETSC_VIEWER_ASCII_VTK and
PETSC_VIEWER_ASCII_VTK_CELL.

Reported-by: Barry Smith <bsmith@mcs.anl.gov>

  • Participants
  • Parent commits 77ae766

Comments (0)

Files changed (2)

File src/vec/vec/examples/tests/output/ex3_2.out

 Vec Object: 2 MPI processes
   type: mpi
   length=10
-Vec Object:Vec_0x84000005_0 2 MPI processes
+Vec Object: 2 MPI processes
   type: mpi
 Process [0]
 1

File src/vec/vec/impls/mpi/pdvec.c

   ierr = MPI_Reduce(&work,&len,1,MPIU_INT,MPI_MAX,0,PetscObjectComm((PetscObject)xin));CHKERRQ(ierr);
   ierr = MPI_Comm_size(PetscObjectComm((PetscObject)xin),&size);CHKERRQ(ierr);
 
-  ierr = PetscObjectGetName((PetscObject)xin,&name);CHKERRQ(ierr);
   ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
   if (!rank) {
     ierr = PetscMalloc1(len,&values);CHKERRQ(ierr);
         MATLAB uses %18.16e format while ASCII uses %g
     */
     if (format == PETSC_VIEWER_ASCII_MATLAB) {
+      ierr = PetscObjectGetName((PetscObject)xin,&name);CHKERRQ(ierr);
       ierr = PetscViewerASCIIPrintf(viewer,"%s = [\n",name);CHKERRQ(ierr);
       for (i=0; i<xin->map->n; i++) {
 #if defined(PETSC_USE_COMPLEX)
       ierr = PetscObjectComposedDataGetInt((PetscObject) viewer, stateId, outputState, hasState);CHKERRQ(ierr);
       if (!hasState) outputState = 0;
 
+      ierr = PetscObjectGetName((PetscObject)xin,&name);CHKERRQ(ierr);
       ierr = VecGetLocalSize(xin, &nLen);CHKERRQ(ierr);
       ierr = PetscMPIIntCast(nLen,&n);CHKERRQ(ierr);
       ierr = VecGetBlockSize(xin, &bs);CHKERRQ(ierr);
     if (format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
       /* Rank 0 is not trying to receive anything, so don't send anything */
     } else {
+      if (format == PETSC_VIEWER_ASCII_MATLAB || format == PETSC_VIEWER_ASCII_VTK || format == PETSC_VIEWER_ASCII_VTK_CELL) {
+        /* this may be a collective operation so make sure everyone calls it */
+        ierr = PetscObjectGetName((PetscObject)xin,&name);CHKERRQ(ierr);
+      }
       ierr = MPI_Send((void*)xarray,xin->map->n,MPIU_SCALAR,0,tag,PetscObjectComm((PetscObject)xin));CHKERRQ(ierr);
     }
   }