PetscErrorCode PetscSynchronizedFlush(MPI_Comm comm,FILE *fd)Collective on MPI_Comm
comm | - the communicator | |
fd | - the file pointer (valid on process 0 of the communicator) |
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
comm | - the communicator | |
fd | - the file pointer | |
format | - the usual printf() format string |
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