Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29284 Discussions

Fortran Preprocessor Definition Failed in Makefile

danielsue
Beginner
909 Views

Dear All,

I have a cross-platform parallel program developed under windows, windows-cygwin and linux.

When use VS2010 to invoke the FPP and set the preprocessor definitions to "WINDOWS", the code can be compiled and works fine (result 1). But when use windows-cygwin, the Preprocessor Definition "CYGWIN" can not be recognized (result 2), but the code can be compiled to executable as well.

Maybe the configure in makefile is not corrected (It works fine if I have no preprocessor definition). I am not so familar with makefile's format.

Thanks.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Result!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Result 1:

Hello World

Solved in WINDOWS

Result 2:

Hello World

Unknow

!!!!!!!!!!!!!!!!!!!!!!!!!!Sample Codes!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!!Main

program Main

    use Solver    
    implicit none

    ! Variables

    ! Body of Main
    print *, 'Hello World'
    
    call Solve
        

end program Main

!!Module

Module Solver
    
    implicit none

#ifdef CYGWIN
#include <finclude/petscsys.h>
#include <finclude/petscvec.h>
#include <finclude/petscmat.h>
#include <finclude/petscpc.h>
#include <finclude/petscksp.h>

#include <finclude/petscvec.h90>
#include <finclude/petscmat.h90>
#include <finclude/petscksp.h90>
#include <finclude/petscpc.h90>
#endif
    
contains

subroutine Solve()
    implicit none
#ifdef WINDOWS    
    write(*,*) "Solved in WINDOWS"
#elif CYGWIN
    write(*,*) "Solved in CYGWIN"
#else
    write(*,*) "Unknow"
#endif
end subroutine Solve

end Module Solver

!!Makefile

# Makefile

include ${PETSC_DIR}/conf/variables
include ${PETSC_DIR}/conf/rules

#FC = ifort
MODEL =../Main/
# Additional flags that may be required by the compiler ...
# DFCFLAG = -em  # When using Cray Fortran compiler
#DFCFLAG =

FPPFLAGS = -fpp -DCYGWIN

# Additional libraries that may be required by the linker ...
# DLIB = -lmetis  # When METIS/ParMETIS are built or installed separately from PETSc
# DLIB = C:/cygwin/packages/metis-5.0.2/build/windows/libmetis/Release/libmetis.lib

SOURCES = $(MODEL)Solver.o    \
    $(MODEL)Main.o        

all: $(SOURCES) chkopts
    -${FLINKER} $(FPPFLAGS) -o Main $(SOURCES) ${PETSC_LIB} ${DLIB}
    ${RM} $(MODEL)*.o *.mod

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

0 Kudos
1 Reply
danielsue
Beginner
909 Views
Thanks to the PETSc-maint. Problem solved. Rename the sourcefiles to use .F90 suffix and remove '-fpp' from FPPFLAGS.
0 Kudos
Reply