We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
f2py undefined symbol with PGI fortran compiler and MPI calls
<!-- Please describe the issue in detail here, and fill in the fields below -->
I am trying to wrap fortran code with f2py. The fortran code includes some MPI calls and is compiled with the PGI compiler.
When importing the wrapped module in python I get this error: `undefined symbol: mpi_comm_rank_`

### Reproducing code example:

<!-- A short code example that reproduces the problem/missing feature. It should be
self-contained, i.e., possible to run as-is via 'python myproblem.py' -->

```
1 ! file: helloworld.f90
2 subroutine sayhello(comm)
3   use mpi
4   implicit none
5   integer :: comm, rank, size, ierr
6   call MPI_Comm_size(comm, size, ierr)
7   call MPI_Comm_rank(comm, rank, ierr)
8   print *, 'Hello, World! I am process ',rank,' of ',size,'.'
9 end subroutine sayhello
```
### Compilation
`CC=gcc f2py --verbose --f90exec=mpif90 --fcompiler=pg -c helloworld.f90 -m helloworld`

### Partial output
```
[...]
<class 'numpy.distutils.fcompiler.pg.PGroupFCompiler'>
version_cmd     = ['***/pgi/linuxpower/19.9/bin/pgfortran', '-V']
compiler_f77    = ['***/pgi/linuxpower/19.9/bin/pgfortran', '-fpic', '-Minform=inform', '-Mnosecond_underscore', '-fast']
compiler_fix    = ['***/spectrum_mpi/10.03.00.01rtm3-rh7_20190611/bin/mpif90', '-Mfixed', '-fpic', '-Minform=inform', '-Mnosecond_underscore', '-fast']
compiler_f90    = ['***/spectrum_mpi/10.03.00.01rtm3-rh7_20190611/bin/mpif90', '-fpic', '-Minform=inform', '-Mnosecond_underscore', '-fast']
linker_so       = ['***/pgi/linuxpower/19.9/bin/pgfortran', '-shared', '-fpic']
archiver        = None
ranlib          = None
linker_exe      = None
version         = LooseVersion ('19.9-0')
libraries       = []
library_dirs    = []
object_switch   = '-o '
compile_switch  = '-c'
include_dirs    = ['***/python_venv/python_numpy_pgi_reproducer/include', '***/anaconda3/2019.03/include/python3.7m']
[...]
***/pgi/linuxpower/19.9/bin/pgfortran -shared -fpic /tmp/tmpfy731xy8/tmp/tmpfy731xy8/src.linux-ppc64le-3.7/helloworldmodule.o /tmp/tmpfy731xy8/tmp/tmpfy731xy8/src.linux-ppc64le-3.7/fortranobject.o /tmp/tmpfy731xy8/helloworld.o -o ./helloworld.cpython-37m-powerpc64le-linux-gnu.so
Removing build directory /tmp/tmpfy731xy8
```
The "linker_so" executable is chosen to be the pgfortran executable, whereas I would like to use the mpif90 executable instead.
This leads to the following error when importing the wrapped module from python:

```
$ python -c "import helloworld"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: ***/helloworld.cpython-37m-powerpc64le-linux-gnu.so: undefined symbol: mpi_comm_rank_
```

### System informations

```
$ mpif90 --version
pgf90 19.9-0 linuxpower target on Linuxpower
```

```
$ python --version
Python 3.7.3
```
```
$ python -c "import sys, numpy; print(numpy.__version__, sys.version)"
1.18.4 3.7.3 (default, Mar 27 2019, 22:31:02)
[GCC 7.3.0]
```
### Workarround
This solves the problem in my case:
In file numpy/distutils/fcompiler/pg.py - line 36 (numpy installed version)
```
-'linker_so': ["pgfortran"],
+'linker_so': ["<F90>"],
```
The executable supplied with the `--f90exec` option is then the one picked to be the linker executable and the ImportError does not occur.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `numpy/distutils/fcompiler/pg.py`
Content:
```
1 # http://www.pgroup.com
2 import sys
3 
4 from numpy.distutils.fcompiler import FCompiler
5 from sys import platform
6 from os.path import join, dirname, normpath
7 
8 compilers = ['PGroupFCompiler', 'PGroupFlangCompiler']
9 
10 
11 class PGroupFCompiler(FCompiler):
12 
13     compiler_type = 'pg'
14     description = 'Portland Group Fortran Compiler'
15     version_pattern = r'\s*pg(f77|f90|hpf|fortran) (?P<version>[\d.-]+).*'
16 
17     if platform == 'darwin':
18         executables = {
19             'version_cmd': ["<F77>", "-V"],
20             'compiler_f77': ["pgfortran", "-dynamiclib"],
21             'compiler_fix': ["pgfortran", "-Mfixed", "-dynamiclib"],
22             'compiler_f90': ["pgfortran", "-dynamiclib"],
23             'linker_so': ["libtool"],
24             'archiver': ["ar", "-cr"],
25             'ranlib': ["ranlib"]
26         }
27         pic_flags = ['']
28     else:
29         executables = {
30             'version_cmd': ["<F77>", "-V"],
31             'compiler_f77': ["pgfortran"],
32             'compiler_fix': ["pgfortran", "-Mfixed"],
33             'compiler_f90': ["pgfortran"],
34             'linker_so': ["pgfortran"],
35             'archiver': ["ar", "-cr"],
36             'ranlib': ["ranlib"]
37         }
38         pic_flags = ['-fpic']
39 
40     module_dir_switch = '-module '
41     module_include_switch = '-I'
42 
43     def get_flags(self):
44         opt = ['-Minform=inform', '-Mnosecond_underscore']
45         return self.pic_flags + opt
46 
47     def get_flags_opt(self):
48         return ['-fast']
49 
50     def get_flags_debug(self):
51         return ['-g']
52 
53     if platform == 'darwin':
54         def get_flags_linker_so(self):
55             return ["-dynamic", '-undefined', 'dynamic_lookup']
56 
57     else:
58         def get_flags_linker_so(self):
59             return ["-shared", '-fpic']
60 
61     def runtime_library_dir_option(self, dir):
62         return '-R%s' % dir
63 
64 
65 import functools
66 
67 class PGroupFlangCompiler(FCompiler):
68     compiler_type = 'flang'
69     description = 'Portland Group Fortran LLVM Compiler'
70     version_pattern = r'\s*(flang|clang) version (?P<version>[\d.-]+).*'
71 
72     ar_exe = 'lib.exe'
73     possible_executables = ['flang']
74 
75     executables = {
76         'version_cmd': ["<F77>", "--version"],
77         'compiler_f77': ["flang"],
78         'compiler_fix': ["flang"],
79         'compiler_f90': ["flang"],
80         'linker_so': [None],
81         'archiver': [ar_exe, "/verbose", "/OUT:"],
82         'ranlib': None
83     }
84 
85     library_switch = '/OUT:'  # No space after /OUT:!
86     module_dir_switch = '-module '  # Don't remove ending space!
87 
88     def get_libraries(self):
89         opt = FCompiler.get_libraries(self)
90         opt.extend(['flang', 'flangrti', 'ompstub'])
91         return opt
92 
93     @functools.lru_cache(maxsize=128)
94     def get_library_dirs(self):
95         """List of compiler library directories."""
96         opt = FCompiler.get_library_dirs(self)
97         flang_dir = dirname(self.executables['compiler_f77'][0])
98         opt.append(normpath(join(flang_dir, '..', 'lib')))
99 
100         return opt
101 
102     def get_flags(self):
103         return []
104 
105     def get_flags_free(self):
106         return []
107 
108     def get_flags_debug(self):
109         return ['-g']
110 
111     def get_flags_opt(self):
112         return ['-O3']
113 
114     def get_flags_arch(self):
115         return []
116 
117     def runtime_library_dir_option(self, dir):
118         raise NotImplementedError
119 
120 
121 if __name__ == '__main__':
122     from distutils import log
123     log.set_verbosity(2)
124     from numpy.distutils import customized_fcompiler
125     if 'flang' in sys.argv:
126         print(customized_fcompiler(compiler='flang').get_version())
127     else:
128         print(customized_fcompiler(compiler='pg').get_version())
129
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/numpy/distutils/fcompiler/pg.py b/numpy/distutils/fcompiler/pg.py
--- a/numpy/distutils/fcompiler/pg.py
+++ b/numpy/distutils/fcompiler/pg.py
@@ -31,7 +31,7 @@
             'compiler_f77': ["pgfortran"],
             'compiler_fix': ["pgfortran", "-Mfixed"],
             'compiler_f90': ["pgfortran"],
-            'linker_so': ["pgfortran"],
+            'linker_so': ["<F90>"],
             'archiver': ["ar", "-cr"],
             'ranlib': ["ranlib"]
         }

{"golden_diff": "diff --git a/numpy/distutils/fcompiler/pg.py b/numpy/distutils/fcompiler/pg.py\n--- a/numpy/distutils/fcompiler/pg.py\n+++ b/numpy/distutils/fcompiler/pg.py\n@@ -31,7 +31,7 @@\n             'compiler_f77': [\"pgfortran\"],\n             'compiler_fix': [\"pgfortran\", \"-Mfixed\"],\n             'compiler_f90': [\"pgfortran\"],\n-            'linker_so': [\"pgfortran\"],\n+            'linker_so': [\"<F90>\"],\n             'archiver': [\"ar\", \"-cr\"],\n             'ranlib': [\"ranlib\"]\n         }\n", "issue": "f2py undefined symbol with PGI fortran compiler and MPI calls\n<!-- Please describe the issue in detail here, and fill in the fields below -->\r\nI am trying to wrap fortran code with f2py. The fortran code includes some MPI calls and is compiled with the PGI compiler.\r\nWhen importing the wrapped module in python I get this error: `undefined symbol: mpi_comm_rank_`\r\n\r\n### Reproducing code example:\r\n\r\n<!-- A short code example that reproduces the problem/missing feature. It should be\r\nself-contained, i.e., possible to run as-is via 'python myproblem.py' -->\r\n\r\n```\r\n1 ! file: helloworld.f90\r\n2 subroutine sayhello(comm)\r\n3   use mpi\r\n4   implicit none\r\n5   integer :: comm, rank, size, ierr\r\n6   call MPI_Comm_size(comm, size, ierr)\r\n7   call MPI_Comm_rank(comm, rank, ierr)\r\n8   print *, 'Hello, World! I am process ',rank,' of ',size,'.'\r\n9 end subroutine sayhello\r\n```\r\n### Compilation\r\n`CC=gcc f2py --verbose --f90exec=mpif90 --fcompiler=pg -c helloworld.f90 -m helloworld`\r\n\r\n### Partial output\r\n```\r\n[...]\r\n<class 'numpy.distutils.fcompiler.pg.PGroupFCompiler'>\r\nversion_cmd     = ['***/pgi/linuxpower/19.9/bin/pgfortran', '-V']\r\ncompiler_f77    = ['***/pgi/linuxpower/19.9/bin/pgfortran', '-fpic', '-Minform=inform', '-Mnosecond_underscore', '-fast']\r\ncompiler_fix    = ['***/spectrum_mpi/10.03.00.01rtm3-rh7_20190611/bin/mpif90', '-Mfixed', '-fpic', '-Minform=inform', '-Mnosecond_underscore', '-fast']\r\ncompiler_f90    = ['***/spectrum_mpi/10.03.00.01rtm3-rh7_20190611/bin/mpif90', '-fpic', '-Minform=inform', '-Mnosecond_underscore', '-fast']\r\nlinker_so       = ['***/pgi/linuxpower/19.9/bin/pgfortran', '-shared', '-fpic']\r\narchiver        = None\r\nranlib          = None\r\nlinker_exe      = None\r\nversion         = LooseVersion ('19.9-0')\r\nlibraries       = []\r\nlibrary_dirs    = []\r\nobject_switch   = '-o '\r\ncompile_switch  = '-c'\r\ninclude_dirs    = ['***/python_venv/python_numpy_pgi_reproducer/include', '***/anaconda3/2019.03/include/python3.7m']\r\n[...]\r\n***/pgi/linuxpower/19.9/bin/pgfortran -shared -fpic /tmp/tmpfy731xy8/tmp/tmpfy731xy8/src.linux-ppc64le-3.7/helloworldmodule.o /tmp/tmpfy731xy8/tmp/tmpfy731xy8/src.linux-ppc64le-3.7/fortranobject.o /tmp/tmpfy731xy8/helloworld.o -o ./helloworld.cpython-37m-powerpc64le-linux-gnu.so\r\nRemoving build directory /tmp/tmpfy731xy8\r\n```\r\nThe \"linker_so\" executable is chosen to be the pgfortran executable, whereas I would like to use the mpif90 executable instead.\r\nThis leads to the following error when importing the wrapped module from python:\r\n\r\n```\r\n$ python -c \"import helloworld\"\r\nTraceback (most recent call last):\r\n  File \"<string>\", line 1, in <module>\r\nImportError: ***/helloworld.cpython-37m-powerpc64le-linux-gnu.so: undefined symbol: mpi_comm_rank_\r\n```\r\n\r\n### System informations\r\n\r\n```\r\n$ mpif90 --version\r\npgf90 19.9-0 linuxpower target on Linuxpower\r\n```\r\n\r\n```\r\n$ python --version\r\nPython 3.7.3\r\n```\r\n```\r\n$ python -c \"import sys, numpy; print(numpy.__version__, sys.version)\"\r\n1.18.4 3.7.3 (default, Mar 27 2019, 22:31:02)\r\n[GCC 7.3.0]\r\n```\r\n### Workarround\r\nThis solves the problem in my case:\r\nIn file numpy/distutils/fcompiler/pg.py - line 36 (numpy installed version)\r\n```\r\n-'linker_so': [\"pgfortran\"],\r\n+'linker_so': [\"<F90>\"],\r\n```\r\nThe executable supplied with the `--f90exec` option is then the one picked to be the linker executable and the ImportError does not occur.\r\n\n", "before_files": [{"content": "# http://www.pgroup.com\nimport sys\n\nfrom numpy.distutils.fcompiler import FCompiler\nfrom sys import platform\nfrom os.path import join, dirname, normpath\n\ncompilers = ['PGroupFCompiler', 'PGroupFlangCompiler']\n\n\nclass PGroupFCompiler(FCompiler):\n\n    compiler_type = 'pg'\n    description = 'Portland Group Fortran Compiler'\n    version_pattern = r'\\s*pg(f77|f90|hpf|fortran) (?P<version>[\\d.-]+).*'\n\n    if platform == 'darwin':\n        executables = {\n            'version_cmd': [\"<F77>\", \"-V\"],\n            'compiler_f77': [\"pgfortran\", \"-dynamiclib\"],\n            'compiler_fix': [\"pgfortran\", \"-Mfixed\", \"-dynamiclib\"],\n            'compiler_f90': [\"pgfortran\", \"-dynamiclib\"],\n            'linker_so': [\"libtool\"],\n            'archiver': [\"ar\", \"-cr\"],\n            'ranlib': [\"ranlib\"]\n        }\n        pic_flags = ['']\n    else:\n        executables = {\n            'version_cmd': [\"<F77>\", \"-V\"],\n            'compiler_f77': [\"pgfortran\"],\n            'compiler_fix': [\"pgfortran\", \"-Mfixed\"],\n            'compiler_f90': [\"pgfortran\"],\n            'linker_so': [\"pgfortran\"],\n            'archiver': [\"ar\", \"-cr\"],\n            'ranlib': [\"ranlib\"]\n        }\n        pic_flags = ['-fpic']\n\n    module_dir_switch = '-module '\n    module_include_switch = '-I'\n\n    def get_flags(self):\n        opt = ['-Minform=inform', '-Mnosecond_underscore']\n        return self.pic_flags + opt\n\n    def get_flags_opt(self):\n        return ['-fast']\n\n    def get_flags_debug(self):\n        return ['-g']\n\n    if platform == 'darwin':\n        def get_flags_linker_so(self):\n            return [\"-dynamic\", '-undefined', 'dynamic_lookup']\n\n    else:\n        def get_flags_linker_so(self):\n            return [\"-shared\", '-fpic']\n\n    def runtime_library_dir_option(self, dir):\n        return '-R%s' % dir\n\n\nimport functools\n\nclass PGroupFlangCompiler(FCompiler):\n    compiler_type = 'flang'\n    description = 'Portland Group Fortran LLVM Compiler'\n    version_pattern = r'\\s*(flang|clang) version (?P<version>[\\d.-]+).*'\n\n    ar_exe = 'lib.exe'\n    possible_executables = ['flang']\n\n    executables = {\n        'version_cmd': [\"<F77>\", \"--version\"],\n        'compiler_f77': [\"flang\"],\n        'compiler_fix': [\"flang\"],\n        'compiler_f90': [\"flang\"],\n        'linker_so': [None],\n        'archiver': [ar_exe, \"/verbose\", \"/OUT:\"],\n        'ranlib': None\n    }\n\n    library_switch = '/OUT:'  # No space after /OUT:!\n    module_dir_switch = '-module '  # Don't remove ending space!\n\n    def get_libraries(self):\n        opt = FCompiler.get_libraries(self)\n        opt.extend(['flang', 'flangrti', 'ompstub'])\n        return opt\n\n    @functools.lru_cache(maxsize=128)\n    def get_library_dirs(self):\n        \"\"\"List of compiler library directories.\"\"\"\n        opt = FCompiler.get_library_dirs(self)\n        flang_dir = dirname(self.executables['compiler_f77'][0])\n        opt.append(normpath(join(flang_dir, '..', 'lib')))\n\n        return opt\n\n    def get_flags(self):\n        return []\n\n    def get_flags_free(self):\n        return []\n\n    def get_flags_debug(self):\n        return ['-g']\n\n    def get_flags_opt(self):\n        return ['-O3']\n\n    def get_flags_arch(self):\n        return []\n\n    def runtime_library_dir_option(self, dir):\n        raise NotImplementedError\n\n\nif __name__ == '__main__':\n    from distutils import log\n    log.set_verbosity(2)\n    from numpy.distutils import customized_fcompiler\n    if 'flang' in sys.argv:\n        print(customized_fcompiler(compiler='flang').get_version())\n    else:\n        print(customized_fcompiler(compiler='pg').get_version())\n", "path": "numpy/distutils/fcompiler/pg.py"}], "after_files": [{"content": "# http://www.pgroup.com\nimport sys\n\nfrom numpy.distutils.fcompiler import FCompiler\nfrom sys import platform\nfrom os.path import join, dirname, normpath\n\ncompilers = ['PGroupFCompiler', 'PGroupFlangCompiler']\n\n\nclass PGroupFCompiler(FCompiler):\n\n    compiler_type = 'pg'\n    description = 'Portland Group Fortran Compiler'\n    version_pattern = r'\\s*pg(f77|f90|hpf|fortran) (?P<version>[\\d.-]+).*'\n\n    if platform == 'darwin':\n        executables = {\n            'version_cmd': [\"<F77>\", \"-V\"],\n            'compiler_f77': [\"pgfortran\", \"-dynamiclib\"],\n            'compiler_fix': [\"pgfortran\", \"-Mfixed\", \"-dynamiclib\"],\n            'compiler_f90': [\"pgfortran\", \"-dynamiclib\"],\n            'linker_so': [\"libtool\"],\n            'archiver': [\"ar\", \"-cr\"],\n            'ranlib': [\"ranlib\"]\n        }\n        pic_flags = ['']\n    else:\n        executables = {\n            'version_cmd': [\"<F77>\", \"-V\"],\n            'compiler_f77': [\"pgfortran\"],\n            'compiler_fix': [\"pgfortran\", \"-Mfixed\"],\n            'compiler_f90': [\"pgfortran\"],\n            'linker_so': [\"<F90>\"],\n            'archiver': [\"ar\", \"-cr\"],\n            'ranlib': [\"ranlib\"]\n        }\n        pic_flags = ['-fpic']\n\n    module_dir_switch = '-module '\n    module_include_switch = '-I'\n\n    def get_flags(self):\n        opt = ['-Minform=inform', '-Mnosecond_underscore']\n        return self.pic_flags + opt\n\n    def get_flags_opt(self):\n        return ['-fast']\n\n    def get_flags_debug(self):\n        return ['-g']\n\n    if platform == 'darwin':\n        def get_flags_linker_so(self):\n            return [\"-dynamic\", '-undefined', 'dynamic_lookup']\n\n    else:\n        def get_flags_linker_so(self):\n            return [\"-shared\", '-fpic']\n\n    def runtime_library_dir_option(self, dir):\n        return '-R%s' % dir\n\n\nimport functools\n\nclass PGroupFlangCompiler(FCompiler):\n    compiler_type = 'flang'\n    description = 'Portland Group Fortran LLVM Compiler'\n    version_pattern = r'\\s*(flang|clang) version (?P<version>[\\d.-]+).*'\n\n    ar_exe = 'lib.exe'\n    possible_executables = ['flang']\n\n    executables = {\n        'version_cmd': [\"<F77>\", \"--version\"],\n        'compiler_f77': [\"flang\"],\n        'compiler_fix': [\"flang\"],\n        'compiler_f90': [\"flang\"],\n        'linker_so': [None],\n        'archiver': [ar_exe, \"/verbose\", \"/OUT:\"],\n        'ranlib': None\n    }\n\n    library_switch = '/OUT:'  # No space after /OUT:!\n    module_dir_switch = '-module '  # Don't remove ending space!\n\n    def get_libraries(self):\n        opt = FCompiler.get_libraries(self)\n        opt.extend(['flang', 'flangrti', 'ompstub'])\n        return opt\n\n    @functools.lru_cache(maxsize=128)\n    def get_library_dirs(self):\n        \"\"\"List of compiler library directories.\"\"\"\n        opt = FCompiler.get_library_dirs(self)\n        flang_dir = dirname(self.executables['compiler_f77'][0])\n        opt.append(normpath(join(flang_dir, '..', 'lib')))\n\n        return opt\n\n    def get_flags(self):\n        return []\n\n    def get_flags_free(self):\n        return []\n\n    def get_flags_debug(self):\n        return ['-g']\n\n    def get_flags_opt(self):\n        return ['-O3']\n\n    def get_flags_arch(self):\n        return []\n\n    def runtime_library_dir_option(self, dir):\n        raise NotImplementedError\n\n\nif __name__ == '__main__':\n    from distutils import log\n    log.set_verbosity(2)\n    from numpy.distutils import customized_fcompiler\n    if 'flang' in sys.argv:\n        print(customized_fcompiler(compiler='flang').get_version())\n    else:\n        print(customized_fcompiler(compiler='pg').get_version())\n", "path": "numpy/distutils/fcompiler/pg.py"}]}