Programming in *.f90 free format with PETSc
Ok, I understand now. I just tested your recommended code on my school's linux server which uses ifort. It works w/o any error. Here's the code: #define PETSC_AVOID_DECLARATIONS #include include/finclude/petsc.h #include include/finclude/petscvec.h #undef PETSC_AVOID_DECLARATIONS module foobar Vec abc contains subroutine xyz() implicit none #include include/finclude/petsc.h #include include/finclude/petscvec.h Vec fbar integer ierr call PetscInitialize(PETSC_NULL_CHARACTER,ierr) end subroutine end module Everything is similar to your recommended format except the use foobar is removed. The strange thing is when I try to compile on my windows's visual fortran, it gives lots of error. The errors all point to mpif.h. Some errors are: d:\cygwin\codes\MPICH\SDK\include\mpif.h(1) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: ( : % . = = C -^ d:\cygwin\codes\MPICH\SDK\include\mpif.h(2) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: ( : % . = = C -^ d:\cygwin\codes\MPICH\SDK\include\mpif.h(3) : Error: Syntax error, found INTEGER_CONSTANT '1993' when expecting one of: ( % . = = C (C) 1993 by Argonne National Laboratory and Mississipi State University. ---^ My include directory uses d:\cygwin\codes\MPICH\SDK\include. So how should I deal with this mistake? I do all my code writing and basic debugging on the visual fortran and I only run my working code on linux. Hence, I did not try your recommendation on the linux. When I reduced the errors to just 3 (none explicit declaration of PETSC_NULL_CHARACTER etc), I thought I'm going in the right direction. But in fact I was on the wrong track. Thank you very much and sorry for the inconvenience. Satish Balay wrote: However, doing this gave me more errors. Hence, I've followed another If you get errors with the recommended model - you sould report the erros [not silently try something else - and then report erros with this something else] I can't help you anymore unless you can report problems with a reproduceable test code that I can comiile locally. Satish On Thu, 9 Aug 2007, Ben Tay wrote: Hi Satish, I am sorry if I have made you angry. I may have missed out some important points which you tried to highlight. I was converting several of my .F fixed format files to .f90 (or .F90) free format and some files which don't need declaration of PETSc type variable worked while some don't. However, I must clarify that the .f90 or .F90 did not bother me after a while since in visual fortran or ifort, using the option -fpp enables the .f90 files to be preprocessed too. Of course, if .F90 was used, -fpp is not required. In my sample file shown just now, I did not have any include statments in my subroutine. They're only present in the module 's section. Checking your prev. email, you indeed mention that the PETSc includes files must be in each and every subroutine. However, doing this gave me more errors. Hence, I've followed another user (Paul T Bauman) 's recommendation which states that only preprocessed statements not inside the module needs to be placed inside the subroutine. With this, I only has 3 errors, which concerns PETSC_COMM_SELF, PETSC_NULL_INTEGER and PETSC_NULL_CHARACTER not having an explicit type. I figured out that using: MPI_Comm PETSC_COMM_SELF will eliminate 1 error, although it was not required before. However, what about the other 2? Should I defined them as integer or character and give them a value using parameter? What value should I give them? You mention this in your prev email: integer NORM_MAX parameter NORM_MAX=3 You also give a template to follow. I also tried to cut and paste and use it but it gave lots of error. I had used it in visual fortran : #define PETSC_AVOID_DECLARATIONS #include include/finclude/petsc.h #include include/finclude/petscvec.h #undef PETSC_AVOID_DECLARATIONS module foobar Vec abc contains subroutine xyz() use foobar implicit none #include include/finclude/petsc.h #include include/finclude/petscvec.h #include include/finclude/petscvec.h90 Vec fbar end subroutine end module As said above, upon removing the include files in the subroutine and the use foobar statement, everything's ok. You can give it a try too. Lastly, I understand that you have been helping a lot of users and there's really a lot of stupid users around (I know I'm one of them ;-) ). Thank you for your patience. Satish Balay wrote: On Thu, 9 Aug 2007, Ben Tay wrote: Hi, Guess I'm too used to typing .f90 ;-) I've changed it to .F90 before but perhaps at that time the error I got didn't disappear so I didn't bother after that. I'm sorry - but you can't keep silently discarding the sugestions we make and keep reporting the same issues multiple times.. This is frustrating. I'm working in windows so I thought the capital
Programming in *.f90 free format with PETSc
Sorry - I don't know enough about these f90 intricacies with 'DEC$ ATTRIBUTES DLLIMPORT' Looks like you can't include mpif.h inside a module-subroutine. I'll have to check up on this tomorrow. Satish On Fri, 10 Aug 2007, Ben Tay wrote: Thank you Satish. I followed what you recommended exactly and used sed -e 's/^C/\!/g' With the new mpif.h, I got the following error: global.i90 d:\cygwin\codes\MPICH\SDK\include\mpif.h(174) : Error: DEC$ ATTRIBUTES DLLIMPORT attribute can appear only in an interface-body. [MPIPRIV] !DEC$ ATTRIBUTES DLLIMPORT :: /MPIPRIV/ It points to this error in mpif.h ! Intel compiler import specification !MS$ATTRIBUTES DLLIMPORT :: /MPIPRIV/ ! Visual Fortran import specification !DEC$ ATTRIBUTES DLLIMPORT :: /MPIPRIV/- in here COMMON /MPIPRIV/ MPI_BOTTOM,MPI_STATUS_IGNORE,MPI_STATUSES_IGNORE PARAMETER (MPI_MAX=100,MPI_MIN=101,MPI_SUM=102,MPI_PROD=103) PARAMETER (MPI_LAND=104,MPI_BAND=105,MPI_LOR=106,MPI_BOR=107) Hope you can help again. Thank you very much. Satish Balay wrote: On Fri, 10 Aug 2007, Ben Tay wrote: The strange thing is when I try to compile on my windows's visual fortran, it gives lots of error. The errors all point to mpif.h. Some errors are: d:\cygwin\codes\MPICH\SDK\include\mpif.h(1) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: ( : % . = = C -^ d:\cygwin\codes\MPICH\SDK\include\mpif.h(2) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: ( : % . = = C -^ d:\cygwin\codes\MPICH\SDK\include\mpif.h(3) : Error: Syntax error, found INTEGER_CONSTANT '1993' when expecting one of: ( % . = = C (C) 1993 by Argonne National Laboratory and Mississipi State University. ---^ Some f90/free-form compilers don't like 'C' for comments. They need '!' in the first columns. To fix this - you'll have to follow instructions from mpif.h C It really is not possible to make a perfect include file that can C be used by both F77 and F90 compilers, but this is close. We have removed C continuation lines (allows free form input in F90); systems whose C Fortran compilers support ! instead of just C or * for comments can C globally replace a C in the first column with !; the resulting file C should work for both Fortran 77 and Fortran 90. C C If your Fortran compiler supports ! for comments, you can run this C through sed with C sed -e 's/^C/\!/g' Satish
Programming in *.f90 free format with PETSc
For now, you can try the following alternative: remove the !MS and !DEC lines from mpif.h COMMON /MPIPRIV/ MPI_BOTTOM,MPI_STATUS_IGNORE,MPI_STATUSES_IGNORE I think this should be ok - as long as you don't use the above MPI flags in your code. Satish On Fri, 10 Aug 2007, Satish Balay wrote: Sorry - I don't know enough about these f90 intricacies with 'DEC$ ATTRIBUTES DLLIMPORT' Looks like you can't include mpif.h inside a module-subroutine. I'll have to check up on this tomorrow. Satish On Fri, 10 Aug 2007, Ben Tay wrote: Thank you Satish. I followed what you recommended exactly and used sed -e 's/^C/\!/g' With the new mpif.h, I got the following error: global.i90 d:\cygwin\codes\MPICH\SDK\include\mpif.h(174) : Error: DEC$ ATTRIBUTES DLLIMPORT attribute can appear only in an interface-body. [MPIPRIV] !DEC$ ATTRIBUTES DLLIMPORT :: /MPIPRIV/ It points to this error in mpif.h ! Intel compiler import specification !MS$ATTRIBUTES DLLIMPORT :: /MPIPRIV/ ! Visual Fortran import specification !DEC$ ATTRIBUTES DLLIMPORT :: /MPIPRIV/- in here COMMON /MPIPRIV/ MPI_BOTTOM,MPI_STATUS_IGNORE,MPI_STATUSES_IGNORE PARAMETER (MPI_MAX=100,MPI_MIN=101,MPI_SUM=102,MPI_PROD=103) PARAMETER (MPI_LAND=104,MPI_BAND=105,MPI_LOR=106,MPI_BOR=107) Hope you can help again. Thank you very much. Satish Balay wrote: On Fri, 10 Aug 2007, Ben Tay wrote: The strange thing is when I try to compile on my windows's visual fortran, it gives lots of error. The errors all point to mpif.h. Some errors are: d:\cygwin\codes\MPICH\SDK\include\mpif.h(1) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: ( : % . = = C -^ d:\cygwin\codes\MPICH\SDK\include\mpif.h(2) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: ( : % . = = C -^ d:\cygwin\codes\MPICH\SDK\include\mpif.h(3) : Error: Syntax error, found INTEGER_CONSTANT '1993' when expecting one of: ( % . = = C (C) 1993 by Argonne National Laboratory and Mississipi State University. ---^ Some f90/free-form compilers don't like 'C' for comments. They need '!' in the first columns. To fix this - you'll have to follow instructions from mpif.h C It really is not possible to make a perfect include file that can C be used by both F77 and F90 compilers, but this is close. We have removed C continuation lines (allows free form input in F90); systems whose C Fortran compilers support ! instead of just C or * for comments can C globally replace a C in the first column with !; the resulting file C should work for both Fortran 77 and Fortran 90. C C If your Fortran compiler supports ! for comments, you can run this C through sed with C sed -e 's/^C/\!/g' Satish
Programming in *.f90 free format with PETSc
Thanks Satish. It worked. Satish Balay wrote: For now, you can try the following alternative: remove the !MS and !DEC lines from mpif.h COMMON /MPIPRIV/ MPI_BOTTOM,MPI_STATUS_IGNORE,MPI_STATUSES_IGNORE I think this should be ok - as long as you don't use the above MPI flags in your code. Satish On Fri, 10 Aug 2007, Satish Balay wrote: Sorry - I don't know enough about these f90 intricacies with 'DEC$ ATTRIBUTES DLLIMPORT' Looks like you can't include mpif.h inside a module-subroutine. I'll have to check up on this tomorrow. Satish On Fri, 10 Aug 2007, Ben Tay wrote: Thank you Satish. I followed what you recommended exactly and used sed -e 's/^C/\!/g' With the new mpif.h, I got the following error: global.i90 d:\cygwin\codes\MPICH\SDK\include\mpif.h(174) : Error: DEC$ ATTRIBUTES DLLIMPORT attribute can appear only in an interface-body. [MPIPRIV] !DEC$ ATTRIBUTES DLLIMPORT :: /MPIPRIV/ It points to this error in mpif.h ! Intel compiler import specification !MS$ATTRIBUTES DLLIMPORT :: /MPIPRIV/ ! Visual Fortran import specification !DEC$ ATTRIBUTES DLLIMPORT :: /MPIPRIV/- in here COMMON /MPIPRIV/ MPI_BOTTOM,MPI_STATUS_IGNORE,MPI_STATUSES_IGNORE PARAMETER (MPI_MAX=100,MPI_MIN=101,MPI_SUM=102,MPI_PROD=103) PARAMETER (MPI_LAND=104,MPI_BAND=105,MPI_LOR=106,MPI_BOR=107) Hope you can help again. Thank you very much. Satish Balay wrote: On Fri, 10 Aug 2007, Ben Tay wrote: The strange thing is when I try to compile on my windows's visual fortran, it gives lots of error. The errors all point to mpif.h. Some errors are: d:\cygwin\codes\MPICH\SDK\include\mpif.h(1) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: ( : % . = = C -^ d:\cygwin\codes\MPICH\SDK\include\mpif.h(2) : Error: Syntax error, found END-OF-STATEMENT when expecting one of: ( : % . = = C -^ d:\cygwin\codes\MPICH\SDK\include\mpif.h(3) : Error: Syntax error, found INTEGER_CONSTANT '1993' when expecting one of: ( % . = = C (C) 1993 by Argonne National Laboratory and Mississipi State University. ---^ Some f90/free-form compilers don't like 'C' for comments. They need '!' in the first columns. To fix this - you'll have to follow instructions from mpif.h C It really is not possible to make a perfect include file that can C be used by both F77 and F90 compilers, but this is close. We have removed C continuation lines (allows free form input in F90); systems whose C Fortran compilers support ! instead of just C or * for comments can C globally replace a C in the first column with !; the resulting file C should work for both Fortran 77 and Fortran 90. C C If your Fortran compiler supports ! for comments, you can run this C through sed with C sed -e 's/^C/\!/g' Satish
Bug in documentation for SETERRQ
SETERRQ is documented to not return a value: Synopsis: void SETERRQ(PetscErrorCode errorcode,char *message) but it is defined in petscerror.h in terms of a return statement: #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);} which causes a compilation error when it is called in a C++ constructor/destructor, for example. A truly void error check, such as: #define ckPetscErr(n, s) {if(0!=n) PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);} or: #define ckPetscErr(stmnt, s) {PetscErrorCode ierr=stmnt;if(0!=ierr) PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,ierr,1,s);} would be helpful.
Bug in documentation for SETERRQ
On 8/10/07, John R. Wicks jwicks at cs.brown.edu wrote: SETERRQ is documented to not return a value: Synopsis: void SETERRQ(PetscErrorCode errorcode,char *message) I have corrected this documentation. but it is defined in petscerror.h in terms of a return statement: #define SETERRQ(n,s) {return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);} which causes a compilation error when it is called in a C++ constructor/destructor, for example. A truly void error check, such as: This does not make sense, unfortunately. SETERRQ is a C exception and thus returns as a matter of definition. Thanks, Matt #define ckPetscErr(n, s) {if(0!=n) PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,n,1,s);} or: #define ckPetscErr(stmnt, s) {PetscErrorCode ierr=stmnt;if(0!=ierr) PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,ierr,1,s);} would be helpful. -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener