I have been working with a Fortran program for some time now and was recently tasked with having it produce some HDF5 output. I created a subroutine to write the h5 file, and it requires some parameters to be passed from the original Fortran program. The Fortran program includes mpif.h and is compiled with mpif90 while the subroutine is compiled using h5fc (it is called in a parallelized loop in the main program if that matters).
I was getting incorrect log ouput from the hdf5 subroutine and went into totalview to try to find the problem and noticed that some (but not all) of the parameters were bad addresses once in the subroutine (everything was fine the main program). Whenever I comment out all the hdf5 functions and compile the subroutine with mpif90 as well, everything looks fine. This of course will not allow me to use any of the HDF5 routines I need to create the h5 file for output.
Here is the related code:
PROGRAM main_prog_mpif90
include "mpif.h"
integer(KIND=4) :: num_vert, num_theta, num_phi, datanum, fileunit
real(KIND=8) :: dist, az, el
real(KIND=8), ALLOCATABLE :: vertices(:), Data(:,:)
.
! initializations and mpi loops and other things that work just fine...
.
CALL HDF5_sub(vertices, Data, dist, num_vert, num_theta, num_phi, &
datanum, fileunit, az, el)
.
! MPI loop ends, things are closed and deallocated...
.
END PROGRAM main_prog_mpif90
SUBROUTINE HDF5_sub(vertices, Data, dist, num_vert, num_theta, num_phi, &
datanum, fileunit, az, el)
integer(KIND=4) :: fileunit, num_vert, num_theta, num_phi, datanum
real(KIND=8) :: dist, az, el
real(KIND=8) :: vertices(num_vert), Data(num_theta, num_phi)
.
! Code that doesn't matter yet since I can't even get this far
.
END SUBROUTINE HDF5_sub
I'm certain I've declared everything consistently, but Totalview will always come back with the following vaiables with bad addresses:
- vertices
- num_vert
- num_theta (but not num_phi)
- Data has the first entry only, but it is correct
One other thing that might be worth mentioning: In Totalview, the Type for the variables in the main program (mpif90) are written like:
INTEGER*4
while in the subroutine (h5fc), the types are displayed in Totalview like:
integer(kind=4)
(I'm guessing a compiler difference?)
Finally, here are the compile lines for the code in question:
h5fc -g -L/usr/lib64/ -lhdf5_fortran -lhdf5 -c HDF5_sub.F90
mpif90 -g -c main_prog_mpif90.F90
So I'm thinking there is an issue between a program and one of its subroutines having been compiled with different compilers (in this case mpif90 and h5fc). If that is the case, is there any kind of work around? To put it another way, can one compile a main program and its subroutine with different compilers and expect no issues with the data types of the parameters being passed? What precautions must one take?
Of course there is a very good chance I'm doing something else totally wrong (I am very much a novice with HDF5).
The simpler the explanation the better for me!
Thank you everyone in advance.
UPDATE1: @Vladimir F, h5fc -v gives a whole bunch of output, but I'm guessing it is gfortran (it reads Driving: gfortran -O2 ... on the first line). mpif90 -v says ifort 14.0.1. The system with this code is not connected to the internet so I can not copy and paste it here (sorry!). As for the integer*4 comment, we actually have a module for the data types, I just simplified it for the questions. The module used by the main program has the following:
integer(4), PARAMETER :: ksp = 4
integer(4), PARAMETER :: ksp = 8
This module is compiled with mpif90 as well, and when I try to USE it in the hdf5 subroutine, it won't compile. I also tried creating a hdf5 datatype module that was identical to the one used by the main program, except compiled that module with h5fc, but the parameters still come through as bad addresses. (What can I say, willing to try almost anything at this point).
UPDATE2: I just found this question (not sure how I missed it before) that I think answers my question about using two different compilers. The question is a couple years old, so if anyone thinks there is now a solution feel free to post it. For what it is worth, I will just have to have my main program write out some parameters to a file, and the hdf5 subroutine will become a stand alone program that will read the file and generate the h5 file from that data.
Thank you all again for taking the time to help.