PetscPrintf/ifort 9.1

Barry Smith bsmith at mcs.anl.gov
Tue Aug 28 22:37:22 CDT 2007


  Paul,

   I have pushed a fix to petsc-dev that resolves this problem. If you are
not using petsc-dev you can simply replace the file 
src/sys/fileio/ftn-custom/zmprintf.c with the attached file then run 
make lib shared 
in that directory then relink your program.

   Barry


On Tue, 28 Aug 2007, Paul T. Bauman wrote:

> Hello,
> 
> Kind of a non-numerical question - sorry.  I'm using PetscPrintf from Fortran
> using the following calling sequence (for example):
> 
>     call PetscPrintf(PETSC_COMM_WORLD,
> "=============================================== \n", ierr)
>     call PetscPrintf(PETSC_COMM_WORLD, "               Beginning of Program
> \n", ierr)
>     call PetscPrintf(PETSC_COMM_WORLD,
> "=============================================== \n", ierr)
> 
> On my mac laptop (PowerPC) with PETSc 2.3.2-p7 compiled with gcc 4.0.1 and
> g95, this prints as expected:
> 
> ===============================================
>               Beginning of Program
> ===============================================
> 
> On a linux workstation (AMD Opteron) with PETSc 2.3.2-p7 compiled with icc,
> icxx, ifort 9.1, the "\n" is treated as a character and not treated as "move
> to new line" so the output is all on one line:
> 
> =============================================== \n               Beginning of
> Program \n=============================================== \n
> 
> While not the end of the world, it is a bit annoying. Am I screwing up the
> calling sequence and just got lucky with g95?  Or a bug (PETSc or Intel)?
> 
> Thanks,
> 
> Paul
> 
> P.S. The reason why I care is because on any compiler I've used (other than
> Intel), write(*,*) prints out at different times and not in sequence with
> PETSc so all my output comes out after PETSc is done outputting. Using
> PetscPrintf, I can have everything print out in order.
> 
> 
-------------- next part --------------
#include "zpetsc.h"
#include "petsc.h"

#if defined(PETSC_HAVE_FORTRAN_CAPS)
#define petscfprintf_              PETSCFPRINTF
#define petscprintf_               PETSCPRINTF
#define petscsynchronizedfprintf_  PETSCSYNCHRONIZEDFPRINTF
#define petscsynchronizedprintf_   PETSCSYNCHRONIZEDPRINTF
#elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
#define petscfprintf_                 petscfprintf
#define petscprintf_                  petscprintf
#define petscsynchronizedfprintf_     petscsynchronizedfprintf
#define petscsynchronizedprintf_      petscsynchronizedprintf
#endif

EXTERN_C_BEGIN

static PetscErrorCode PetscFixSlashN(const char *in, char **out)
{
  PetscErrorCode ierr;
  PetscInt       i;
  size_t         len;

  PetscFunctionBegin;
  ierr = PetscStrallocpy(in,out);CHKERRQ(ierr);
  ierr = PetscStrlen(*out,&len);CHKERRQ(ierr);
  for (i=0; i<len-1; i++) {
    if ((*out)[i] == '\\' && (*out)[i+1] == 'n') {(*out)[i] = ' '; (*out)[i+1] = '\n';}
  }
  PetscFunctionReturn(0);
}

void PETSC_STDCALL petscfprintf_(MPI_Comm *comm,FILE **file,CHAR fname PETSC_MIXED_LEN(len1),PetscErrorCode *ierr PETSC_END_LEN(len1))
{
  char     *c1,*tmp;

  FIXCHAR(fname,len1,c1);
  *ierr = PetscFixSlashN(c1,&tmp);if (*ierr) return;
  *ierr = PetscFPrintf((MPI_Comm)PetscToPointerComm(*comm),*file,tmp);if (*ierr) return;
  *ierr = PetscStrfree(tmp);if (*ierr) return;
  FREECHAR(fname,c1);
}

void PETSC_STDCALL petscprintf_(MPI_Comm *comm,CHAR fname PETSC_MIXED_LEN(len1),PetscErrorCode *ierr PETSC_END_LEN(len1))
{
  char *c1,*tmp;

  FIXCHAR(fname,len1,c1);
  *ierr = PetscFixSlashN(c1,&tmp);if (*ierr) return;
  *ierr = PetscPrintf((MPI_Comm)PetscToPointerComm(*comm),tmp);if (*ierr) return;
  *ierr = PetscStrfree(tmp);if (*ierr) return;
  FREECHAR(fname,c1);
}

void PETSC_STDCALL petscsynchronizedfprintf_(MPI_Comm *comm,FILE **file,CHAR fname PETSC_MIXED_LEN(len1),PetscErrorCode *ierr PETSC_END_LEN(len1))
{
  char *c1,*tmp;

  FIXCHAR(fname,len1,c1);
  *ierr = PetscFixSlashN(c1,&tmp);if (*ierr) return;
  *ierr = PetscSynchronizedFPrintf((MPI_Comm)PetscToPointerComm(*comm),*file,tmp);if (*ierr) return;
  *ierr = PetscStrfree(tmp);if (*ierr) return;
  FREECHAR(fname,c1);
}

void PETSC_STDCALL petscsynchronizedprintf_(MPI_Comm *comm,CHAR fname PETSC_MIXED_LEN(len1),PetscErrorCode *ierr PETSC_END_LEN(len1))
{
  char *c1,*tmp;

  FIXCHAR(fname,len1,c1);
  *ierr = PetscFixSlashN(c1,&tmp);if (*ierr) return;
  *ierr = PetscSynchronizedPrintf((MPI_Comm)PetscToPointerComm(*comm),tmp);if (*ierr) return;
  *ierr = PetscStrfree(tmp);if (*ierr) return;
  FREECHAR(fname,c1);
}

EXTERN_C_END


More information about the petsc-users mailing list