petsc-master 2014-12-24
Report Typos and Errors

PetscSynchronizedFlush

Flushes to the screen output from all processors involved in previous PetscSynchronizedPrintf() calls.

Synopsis

PetscErrorCode  PetscSynchronizedFlush(MPI_Comm comm,FILE *fd)
Collective on MPI_Comm

Input Parameters

comm - the communicator
fd - the file pointer (valid on process 0 of the communicator)

Notes

Usage of PetscSynchronizedPrintf() and PetscSynchronizedFPrintf() with different MPI communicators REQUIRES an intervening call to PetscSynchronizedFlush().

See Also

PetscSynchronizedPrintf(), PetscFPrintf(), PetscPrintf(), PetscViewerASCIIPrintf(),
PetscViewerASCIISynchronizedPrintf() C@*/ PetscErrorCode PetscSynchronizedFlush(MPI_Comm comm,FILE *fd) { PetscErrorCode ierr; PetscMPIInt rank,size,tag,i,j,n = 0,dummy = 0; char *message; MPI_Status status;

PetscFunctionBegin; ierr = PetscCommDuplicate(comm,&comm,&tag);CHKERRQ(ierr); ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);

/* First processor waits for messages from all other processors */ if (!rank) { if (!fd) fd = PETSC_STDOUT; for (i=1; i<size; i++) { /* to prevent a flood of messages to process zero, request each message separately */ ierr = MPI_Send(&dummy,1,MPI_INT,i,tag,comm);CHKERRQ(ierr); ierr = MPI_Recv(&n,1,MPI_INT,i,tag,comm,&status);CHKERRQ(ierr); for (j=0; j<n; j++) { PetscMPIInt size = 0;

ierr = MPI_Recv(&size,1,MPI_INT,i,tag,comm,&status);CHKERRQ(ierr); ierr = PetscMalloc1(size, &message);CHKERRQ(ierr); ierr = MPI_Recv(message,size,MPI_CHAR,i,tag,comm,&status);CHKERRQ(ierr); ierr = PetscFPrintf(comm,fd,"%s",message);CHKERRQ(ierr); ierr = PetscFree(message);CHKERRQ(ierr); } } } else { /* other processors send queue to processor 0 */ PrintfQueue next = petsc_printfqueuebase,previous;

ierr = MPI_Recv(&dummy,1,MPI_INT,0,tag,comm,&status);CHKERRQ(ierr); ierr = MPI_Send(&petsc_printfqueuelength,1,MPI_INT,0,tag,comm);CHKERRQ(ierr); for (i=0; i<petsc_printfqueuelength; i++) { ierr = MPI_Send(&next->size,1,MPI_INT,0,tag,comm);CHKERRQ(ierr); ierr = MPI_Send(next->string,next->size,MPI_CHAR,0,tag,comm);CHKERRQ(ierr); previous = next; next = next->next; ierr = PetscFree(previous->string);CHKERRQ(ierr); ierr = PetscFree(previous);CHKERRQ(ierr); } petsc_printfqueue = 0; petsc_printfqueuelength = 0; } ierr = PetscCommDestroy(&comm);CHKERRQ(ierr); PetscFunctionReturn(0); }

/* ---------------------------------------------------------------------------------------*/

#undef __FUNCT__ #define __FUNCT__ "PetscFPrintf" /*@C PetscFPrintf - Prints to a file, only from the first processor in the communicator.

Not Collective

Input Parameters

comm - the communicator
fd - the file pointer
format - the usual printf() format string

Fortran Note

This routine is not supported in Fortran.

See Also

PetscPrintf(), PetscSynchronizedPrintf(), PetscViewerASCIIPrintf(),
PetscViewerASCIISynchronizedPrintf(), PetscSynchronizedFlush()

Level:intermediate
Location:
src/sys/fileio/mprint.c
Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages

Examples

src/sys/classes/random/examples/tutorials/ex2.c.html
src/sys/examples/tutorials/ex2.c.html
src/vec/vec/examples/tutorials/ex9.c.html
src/dm/examples/tutorials/ex6.c.html
src/ts/examples/tutorials/ex10.c.html