1

use f2py to connect python and Fortran language. f2py website https://docs.scipy.org/doc/numpy/f2py/

Fortran before used gfortran and pgfortran(PGI) integrate OpenMP both work.

makefile file is below

gfortran version

    gfortran -c -fopenmp mod_readfile.f90 -lgomp
    f2py -c  mod_readfile.f90 --f90flags="-fopenmp" -lgomp -m mod_readfile

pgfortran version

    pgfortran -c -mp mod_readfile.f90  -lgomp
    f2py -c  mod_readfile.f90 --fcompiler=pg --f90flags="-mp" -lgomp -m mod_readfile 

then !$omp direvative in Fortran was recognized

I want to extend it to OpenAcc, and !$acc is also be recognized, but it fails, because openacc is incorporated in pgfortran(PGI), so I use makefile as below

    pgfortran -c -acc mod_readfile.f90 -lcublas -lcudart -lgomp
    f2py -c  mod_readfile.f90 --fcompiler=pg --f90flags="-acc"  -m mod_readfile -lcublas -lcudart -lgomp

before I checked that

pgfortran -c -acc mod_readfile.f90

works well separately. but when it manipulated as module of python it has some problem. also confused these flags(-lcublas -lcudart -lgomp), below doesn't work because lacking -lgomp flag

    gfortran -c -fopenmp mod_readfile.f90 
    f2py -c  mod_readfile.f90 --f90flags="-fopenmp" -m mod_readfile

after google find Using F2Py with OpenACC gives import error in Python compiled with acc (gfortran)and f2py, but I still want to know is it possible to have pgfortran with acc to connect with python? which compile flags should I use? thanks

TianliBen
  • 11
  • 3
  • The name of the language is **Fortran**. It has been spelled as **Fortran** since 1990. – evets Oct 27 '19 at 22:57

1 Answers1

1

Try compiling with "-ta=tesla:nordc". RDC stands for relocatable device code which requires the device code to be linked with a device linker. While we (PGI) have added support for using RDC in shared objects, I'm not sure the process f2py uses so may not be using pgfortran to create the shared object and hence miss the device link step.

The caveat of using nordc is that you wont be able to use device module data (via the "declare" directive) outside of the module itself, nor call device routines (via the "routine" directive).

Mat Colgrove
  • 5,441
  • 1
  • 10
  • 11