Change default mpif90 compiler to pgf90

Dear all,
I want to change default compiler of mpif90 to pg90 and this error happened:
[/code]
/opt/pgi/linux86-64/18.10/lib/f90main.o In function ‘main’ :
f90mqin.c:(.text+0x40): undefined reference to ‘MAIN_’

Hi tohidfla,

This typically occurs when link an object(s) without a “program”.

Is your “main” written in C or C++? If so, add “-Mnomain”.

Otherwise, can you confirm that you indeed have a main program in your Fortran code?

-Mat

Hi Mat
Thank you for your replying.
I am trying to compile Fortran code that has created Makefile with regard to PGI compilers.

include Makefile.local
OBJDIR = ./objs/3D_MT/PGIReleaseMPI
F90 = mpif90 
FFLAGS = -O3 -fastsse -mp -tp=istanbul-64
MPIFLAGS = -Bstatic  -Mipa=fast  -Mextend  -Kieee -Mpreprocess -DMPI
MODULE = -module $(OBJDIR)
LIBS_PATH = -L${PGI}/linux86-64/current/lib
LIBS = -llapack -lblas -lpgftnrtl

So I tried to change default Fortran compiler of mpif90 with this:

~/Desktop/f90$ mpif90 -fc=pgfortran
/opt/pgi/linux86-64/18.10/lib/f90main.o: In function `main':
f90main.c:(.text+0x40): undefined reference to `MAIN_'

And this error happened.

Cheers

I’m not seeing the “-c” flag (i.e. only create an object, and don’t link) on your compilation flags. Again, this error occurs when trying to link an object(s) without a main program, Assuming that you have multiple source files in your project, if you compile without “-c”, the compiler will attempt to link and you would get this error for all but the one object that have “program” in it.

Do you have multiple source files?
Are you adding “-c” by some other means not shown?

-Mat

Hi Mat,
Thank you again for replying.
For your question yes my code include multiple source files.
But my main problem is change mpif90 default Fortran compiler.

But my main problem is change mpif90 default Fortran compiler.

Yes, but the error you posted has nothing to do with this. The mpif90 driver is using PGI and the link is failing since the object does not contain a main program. Again, the most likely cause of the error you posted is because you’re missing the “-c” flag when compiling which tells the compiler to stop after compilation and not link.

-Mat

In previous post I mentioned that I am trying to change default Fortran compiler of mpif90 that this error happened:

~/Desktop/f90$ mpif90 -fc=pgfortran 
/opt/pgi/linux86-64/18.10/lib/f90main.o: In function `main': 
f90main.c:(.text+0x40): undefined reference to `MAIN_'

until the default Fortran of mpi90 deos not change when I make the code this error will happen:

mpif90  -c -module ./objs/3D_MT/PGIReleaseMPI -O3  -c -fastsse -mp -tp=istanbul-64 -Bstatic  -Mipa=fast  -Mextend  -Kieee -Mpreprocess -DMPI UTILS/math_constants.f90 -o ./objs/3D_MT/PGIReleaseMPI/math_constants.o
gfortran: error: unrecognized command line option ‘-module’
gfortran: error: unrecognized command line option ‘-fastsse’
gfortran: error: unrecognized command line option ‘-mp’
gfortran: error: unrecognized command line option ‘-tp=istanbul-64’
gfortran: error: unrecognized command line option ‘-Mipa=fast’
gfortran: error: unrecognized command line option ‘-Mextend’
gfortran: error: unrecognized command line option ‘-Kieee’
gfortran: error: unrecognized command line option ‘-Mpreprocess’
make: *** [objs/3D_MT/PGIReleaseMPI/math_constants.o] Error 1

because mpif90 use the gfortran and gfortran can not recognizes the FFLAGS parameters.

Cheers
Tohidfla

In previous post I mentioned that I am trying to change default Fortran compiler of mpif90 that this error happened:

Correct and by adding “-fc=pgfortran” it looks like you have successfully changed the MPI mpif90 driver to use pgfortran.

The error:

/opt/pgi/linux86-64/18.10/lib/f90main.o: In function main': f90main.c:(.text+0x40): undefined reference to MAIN_’

Is a PGI error that occurs when trying to link an object file or multiple object files without a main program. The most common cause of this error is when compiling a single object without the “-c” flag.

One point of confusion is that you posted:

~/Desktop/f90$ mpif90 -fc=pgfortran

I assumed you were just showing us the “-fc” command you were using, but now see this is what you’re actually running.

The mpif90 driver is trying to link using pgfortran, but since you don’t have any source files, it’s just linking in the implicit libraries. The libraries don’t have a main and hence the error.

Try running " mpif90 -fc=pgfortran -V". “-V” will have the PGI print out the compiler version.

Then try adding “-fc=pgfortran” to your compile flags:

mpif90  -fc=pgfortran -c -module ./objs/3D_MT/PGIReleaseMPI -O3  -c -fastsse -mp -tp=istanbul-64 -Bstatic  -Mipa=fast  -Mextend  -Kieee -Mpreprocess -DMPI UTILS/math_constants.f90 -o ./objs/3D_MT/PGIReleaseMPI/math_constants.o

Alternatively, you can use the OpenMPI version that PGI ship with the compilers. If installed, they be under “/opt/pgi/linux86-64/2018/mpi/openmpi”.

-Mat