Fortran How to Retrieve the Value of MPI_TAG_UB in openmpi/2.1.1 Using Fortran?

  • Thread starter Thread starter pachomba
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The discussion revolves around retrieving the MPI_TAG_UB parameter using OpenMPI version 2.1.1 with Fortran. The user initially attempts to use the MPI_COMM_GET_ATTR routine but encounters errors related to undeclared parameters and linking issues. A key suggestion is to include "use mpi" at the beginning of the Fortran code to access MPI constants. The user later successfully compiles the program using mpifort instead of gfortran, which resolves the linking problem. However, they face a runtime error related to shared memory and are advised to use a parallel launcher like mpirun for execution. Additionally, it is noted that the program lacks output statements to display the value of MPI_TAG_UB, and there is a correction regarding the number of arguments in the MPI_COMM_GET_ATTR call, as well as clarification on the expected value of MPI_TAG_UB, which should be at least 32767, not 7.
pachomba
Messages
3
Reaction score
0
Hello,
I am trying to get the parameter MPI_TAG_UB for openmpi (I am using version 2.1.1). I know I need to use the routine MPI_COMM_GET_ATTR, but I have no idea how to do that, I never used fortran in my life. Following this link (https://www.mpi-forum.org/docs/mpi-2.2/mpi22-report/node369.htm) I tried this:

LOGICAL FLAG
INTEGER IERR
INTEGER (KIND=MPI_ADDRESS_KIND) VALUE

! Upon successful return, VALUE == 7 (sign extended)
CALL MPI_COMM_GET_ATTR(MPI_COMM_WORLD, KEYVAL, VALUE, FLAG, IERR)

I put that in a file test.f90, then did gfortran test.f90 -o test.out, but I got this error message:

Error: Parameter 'mpi_address_kind' at (1) has not been declared or is a variable, which does not reduce to a constant expression
Error: Unexpected end of file in 'test.f90'

So I have no idea what I'm doing. Did someone ever retrieved the value of MPI_TAG_UB for some MPI implementation?
Thanks!
 
Technology news on Phys.org
MPI constants are of course not part of Fortran, so the compiler doesn't know what to do with MPI_ADDRESS_KIND.

Try
Fortran:
use mpi
at the beginning of your code.
 
DrClaude said:
MPI constants are of course not part of Fortran, so the compiler doesn't know what to do with MPI_ADDRESS_KIND.

Try
Fortran:
use mpi
at the beginning of your code.

Thank you very much DrClaude, I tired that and I got this error:
Error: Unexpected end of file in 'test.f90'

Then I tried including "PROGRAM test" and "END PROGRAM test" at the beginning and end of the script, and I got this error:
~/tmp/cc3b6Lod.o: In function `MAIN__':
test.f90:(.text+0x34): undefined reference to `mpi_comm_get_attr_'
collect2: ld returned 1 exit status

I know it must be a very basic thing I'm not doing, I plan to learn some fortran in the future but for now I just need to get that MPI_TAG_UB value.
Truly appreciate any help.
 
pachomba said:
~/tmp/cc3b6Lod.o: In function `MAIN__':
test.f90:(.text+0x34): undefined reference to `mpi_comm_get_attr_'
collect2: ld returned 1 exit status
That's because your not linking to the MPI library. The easiest way to do this is to compile using mpifort instead of gfortran (it will still use gfortran, but will correctly link). See https://www.open-mpi.org/faq/?category=mpi-apps
 
DrClaude said:
That's because your not linking to the MPI library. The easiest way to do this is to compile using mpifort instead of gfortran (it will still use gfortran, but will correctly link). See https://www.open-mpi.org/faq/?category=mpi-apps

Thank you Dr, I was able to compile the program with mpifort, now the program looks like this:

PROGRAM test
include 'mpif.h'

LOGICAL FLAG
INTEGER IERR
INTEGER (KIND=MPI_ADDRESS_KIND) VALUE
! Upon successful return, VALUE == 7 (sign extended)
CALL MPI_INIT(IERR)
CALL MPI_COMM_GET_ATTR(MPI_COMM_WORLD, MPI_TAG_UB, MAXTAG, VALUE, FLAG, IERR)

END PROGRAM test

but when I run it I get this error now:

shmem: posix: file name search - max attempts exceeded.cannot continue with posix.

I guess I need to add an include 'something' line at the beginning? Also, is this going to actually tell me what the value of MPI_TAG_UB is?
 
pachomba said:
PROGRAM test
include 'mpif.h'

LOGICAL FLAG
INTEGER IERR
INTEGER (KIND=MPI_ADDRESS_KIND) VALUE
! Upon successful return, VALUE == 7 (sign extended)
CALL MPI_INIT(IERR)
CALL MPI_COMM_GET_ATTR(MPI_COMM_WORLD, MPI_TAG_UB, MAXTAG, VALUE, FLAG, IERR)

END PROGRAM test
That program has no output. you have to add a print (or write) statement to show the value of VALUE. Also, when posting code, please use CODE tags (you can get them automatically by clicking on the + in the bar above the text area and choosing </> Code.)
pachomba said:
shmem: posix: file name search - max attempts exceeded.cannot continue with posix.
This appears to be an implementation-dependent error. How are you launching the program? (Often, you need a launcher to execute correctly in parallel, such as mpirun.)

pachomba said:
Also, is this going to actually tell me what the value of MPI_TAG_UB is?
As I wrote above, the program as is will have no output. Looking at the specification soft MPI_COMM_GET_ATTR, you have one argument too many. You should remove MAXTAG. Also, I don't understand why you think that VALUE should be 7, because the MPI standard specifies that the upper bound on tags is never smaller than 32767.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
12
Views
3K
Replies
12
Views
7K
Replies
16
Views
2K
Replies
1
Views
2K
Replies
19
Views
6K
Replies
13
Views
3K
Replies
22
Views
5K
Replies
5
Views
2K
Back
Top