Error with "open" subroutine usign nvfortran+mpif90

I have a numerical code that works with “gfortran” and “mpif90”. The code is parallelized with mpi.

I want the code to run on multiple CPUs-GPUs. The idea is to take advantage of CPU parallelization to split the work and associate a GPU to each CPU to accelerate the computations.

I am compiling the code with “nvfortran” and “mpif90” (NVIDIA HPC SDK Current Release Downloads | NVIDIA Developer, release 22.3, in Linux). At the moment, I just added “use cudafor” in the “main.cuf” and got the GPU characteristics, using:

type (cudaDeviceProp) :: prop

The code compiles and links, and identifies the GPUs. However, I cannot read the input files with the “open” subroutine (this works perfectly with the CPU version)

The compile flags I am using are:

FLAGS = -O2 -DCUDA -cuda -acc -Mfree -Mpreprocess

When executing the program, it generates an error in line:

open( newunit = funit, &
file = trim(adjustl(adjustl(fopen%fname)), &
form = trim(adjustl(adjustl(fopen%fform)), &
status = trim(adjustl(adjustl(fopen%fstat)), &
action = trim(adjustl(adjustl(fopen%factn)), &
position = trim(adjustl(adjustl(fopen%fpost)), &
access = trim(adjustl(adjustl(fopen%faccs)), &
convert = trim(adjustl(adjustl(fopen%fcnvt)), &
iostat = ioerr )

where ioerr = 201 or 202

I understand that it is a problem with the versions and that I can fix it by adding the appropriate flags in the compilation and linking.

I would appreciate it if anyone could help me, I have been dealing with this for days, and I am unable to get it to work.

Hi jomipp,

The error messages 201 and 202 means that the runtime is detecting an illegal or conflicting specifier.

It doesn’t quite make sense that simply adding the CUDA Fortran device property routines would cause this, so I suspect something else is causing this.

When you say that it works with the “CPU” version are you meaning that it woks with gfortran? Does the code prior to adding the CUDA Fortran properties and flagsets work with nvfortran as well?

Do you have a reproducing example I could use to investigate?


Good morning. I finally managed to run the code. Unfortunately, apart from the reading problems I mentioned, I had other problems.

Regarding the reading problem, it disappeared when I removed the argument convert = ‘NATIVE’ in the call of the open subroutine. This option is valid when I use the gnu compiler, but it seems that this is not the case with nvfortran.

Finally, in answer to your question, when I was talking about compiling on CPU I meant compiling with the gnu compiler, not nvfortran.

I think I solved the problem. Thank you very much for your help.

“convert” is a GNU extension and not supported by nvfortran. We use compiler flags, “-Mbyteswapio” to convert between big and little endian.

Though it looks like “native” is the default for GNU so removing it should have no impact.