- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am working on a shared code in Fortran. The code is used by multiple groups, and not everyone have the latest MPI libraries and compilers.
Now I want to use a feature from MPI-3, however, I cannot rely on everyone having this yet (yes, I know it's sad). In C this would have been trivial, in 'mpi.h' there is something like '#define MPI_VERSION 3' I could have used to switch to the new MPI-3 functions in the code, like:
#if MPI_VERSION >= 3 mpi_new_v3_function() #else mpi_send() mpi_recv() #endif
In the MPI module (or mpif.h) there is only a PARAMETER with the same information.
So I made a test, and the following works great in gfortran:
PROGRAM main USE mpi IMPLICIT NONE IF (mpi_version == 4) CALL mpi_nonexisting_call() WRITE(*,*) mpi_version END PROGRAM main
I can compile this with both -O0 and -O3, with and without the -g flag. It execute perfectly and print the current MPI version.
With Intel Fortran I get the error "undefined reference to `mpi_nonexisting_call_'" when trying to compile with -O0. With higher optimizations, I don't get this error.
I could of course give a define-directive to the compiler manually, and use the preprocessor like in C, but this require some effort from the users side, or it require me to use some build system like autoconf or cmake (currently we only have a hand-written makefile). We already use some define directives in our Fortran code, so it would not change any compilation workflow.
Do you have any ideas on how I can get the desired behaviour in this case working with the Intel Fortran compiler?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Intel compiler with "-O0" gives undefined reference error because "-O0" disable all optimizations including the removal of the false branch of the IF statement at compilation time. gfortran always do that regardless of "-O" level.
I think the call to "mpi_nonexisting_call" in the code is a compilation time check on purpose so ifort's behavior shouldn't be an issue.
Thanks,
Xiaoping Duan
Intel Customer Support
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Xiaoping D. (Intel) wrote:
Intel compiler with "-O0" gives undefined reference error because "-O0" disable all optimizations including the removal of the false branch of the IF statement at compilation time. gfortran always do that regardless of "-O" level.
Yes, I understand that.
Xiaoping D. (Intel) wrote:
I think the call to "mpi_nonexisting_call" in the code is a compilation time check on purpose so ifort's behavior shouldn't be an issue.
What do you mean? My only goal is to be able to write a code where I can use "modern" MPI-3 functions if the MPI implementation support this, and fall back to "old" functions if the support for MPI-3 is not present. Like I can with C and the define-directives. How it is done is not important, but it would be nice if it were transparent to the users. Is this at all possible in Fortran?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hakostra wrote:
Quote:
Xiaoping D. (Intel) wrote:
I think the call to "mpi_nonexisting_call" in the code is a compilation time check on purpose so ifort's behavior shouldn't be an issue.
What do you mean? My only goal is to be able to write a code where I can use "modern" MPI-3 functions if the MPI implementation support this, and fall back to "old" functions if the support for MPI-3 is not present. Like I can with C and the define-directives. How it is done is not important, but it would be nice if it were transparent to the users. Is this at all possible in Fortran?
You can use fpp preprocessor with Intel fortran compiler: https://software.intel.com/en-us/node/581531
For your case:
PROGRAM main
USE mpi IMPLICIT NONE #if mpi_version == 4 CALL mpi_nonexisting_call() #endif WRITE(*,*) mpi_version END PROGRAM main
Compile it with fpp option as:
$ mpiifort -fpp -O0 test.f90
$./a.out
3
Thanks,
Xiaoping Duan
Intel Customer Support
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh... It's that simple. I didn't try that. Sorry for bothering you. Thanks.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page