syncffprintf.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 static char const Id[] = "$Id: syncffprintf.c 2962 2010-02-04 19:50:44Z scholz $\n\n";
00025 static char const Td[] = "$Today: " __FILE__ " " __DATE__ " " __TIME__ " $\n\n";
00026
00027 #include "util.h"
00028
00029 #ifdef ZLIB
00030 EXTERN_C_BEGIN
00031 #include "zlib.h"
00032 EXTERN_C_END
00033 #endif
00034
00035 int SynchronizedFastFPrintf(FILE *fd, int nchars, int nmax, char *wbufs, PetscTruth zip)
00036 {
00037 int i;
00038
00039 MPI_Status status;
00040
00041 MagparFunctionInfoBegin;
00042
00043 int rank,size;
00044 ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
00045 ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
00046
00047
00048 assert(nmax>0);
00049 if (nchars==0) {
00050 wbufs[0]=0;
00051 }
00052
00053
00054 nchars++;
00055
00056 if (!rank) {
00057 #ifdef ZLIB
00058 if (zip==PETSC_TRUE) {
00059 ierr = gzwrite(fd,wbufs,nchars-1);
00060
00061
00062
00063 }
00064 else {
00065 #endif
00066 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"%s",wbufs);CHKERRQ(ierr);
00067 #ifdef ZLIB
00068 }
00069 #endif
00070 for (i=1;i<size;i++) {
00071 ierr = MPI_Recv(&nchars,1,MPI_INT,i,0,PETSC_COMM_WORLD,&status);CHKERRQ(ierr);
00072
00073 assert(nchars<nmax);
00074 ierr = MPI_Recv(wbufs,nchars,MPI_CHAR,i,0,PETSC_COMM_WORLD,&status);CHKERRQ(ierr);
00075
00076 #ifdef ZLIB
00077 if (zip==PETSC_TRUE) {
00078 ierr = gzwrite(fd,wbufs,nchars-1);
00079
00080
00081
00082 }
00083 else {
00084 #endif
00085 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"%s",wbufs);CHKERRQ(ierr);
00086 #ifdef ZLIB
00087 }
00088 #endif
00089 }
00090 }
00091 else {
00092 ierr = MPI_Send(&nchars,1,MPI_INT,0,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
00093 ierr = MPI_Send(wbufs,nchars,MPI_CHAR,0,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
00094 }
00095
00096 MagparFunctionInfoReturn(0);
00097 }
00098