# \-fPIC and -mcmodel=medium not supported together

**URL:** <https://forums.developer.nvidia.com/t/fpic-and-mcmodel-medium-not-supported-together/134944>\
**Category:** Legacy PGI Compilers (archived)\
**Created:** [June 16, 2016, 6:20am UTC](https://forums.developer.nvidia.com/t/fpic-and-mcmodel-medium-not-supported-together/134944 "2016-06-16T06:20:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NightsWatch1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@NightsWatch1](https://forums.developer.nvidia.com/u/NightsWatch1)\
**Post date:** [June 16, 2016, 6:20am UTC](https://forums.developer.nvidia.com/t/fpic-and-mcmodel-medium-not-supported-together/134944/1 "2016-06-16T06:20:31Z")

</div>

For the last a few days I was developing a project on my local machine with PGI 16.1 installed, and my compiling process was as follows:

mpifort -Mpreprocess -DTIME -fast -c emodule.cuf  
mpifort -Mpreprocess -DTIME -fast -c earthr1.cuf  
mpifort -Mpreprocess -DTIME -fast -mcmodel=medium earthr1.o emodule.o -o earthr1

Everything was just fine until I finally need to test my program on a cluster with PGI 15.9 installed. When I tried to compile the source on the cluster with the same command, the compiler gave me an error:

pgf90-Error-Switches -fPIC and -mcmodel=medium are not supported together

I’m not sure what is the wrong, I mean I didn’t put no -fPIC option in my compile command so why would the compiler give me such an error message?

The thing is I have to add this mcmodel=medium option in my compiling command because the total memory size exceeds 2GB, if I remove that option, I will get the following errors:

/home/XXX/earthr1.cuf:84:(.text+0xd8): relocation truncated to fit: R\_X86\_64\_PC32 against symbol `_zoner_0_' defined in COMMON section in emodule.o /home/XXX/./earthr1.cuf:87:(.text+0xe9): relocation truncated to fit: R_X86_64_PC32 against symbol `_zoner\_0_’ defined in COMMON section in emodule.o

Please tell me what I am supposed to do to solve this problem.

---

<div class="post-metadata">

**Author:** ![NightsWatch1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@NightsWatch1](https://forums.developer.nvidia.com/u/NightsWatch1)\
**Post date:** [June 16, 2016, 1:08pm UTC](https://forums.developer.nvidia.com/t/fpic-and-mcmodel-medium-not-supported-together/134944/2 "2016-06-16T13:08:07Z")

</div>

After searching a while, I finally realized that mpif90 is nothing but a script. So the pgi compiler has added the -fPIC to mpif90 script by default, the solution is to get a copy of the mpif90, and then delete all -fPIC options in the script.

---

<div class="post-metadata">

**Author:** ![tull](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tull](https://forums.developer.nvidia.com/u/tull)\
**Post date:** [June 17, 2016, 8:56pm UTC](https://forums.developer.nvidia.com/t/fpic-and-mcmodel-medium-not-supported-together/134944/3 "2016-06-17T20:56:21Z")

</div>

A better solution is to get rid of the -mcmodel=medium requirement by  
dynamically declaring the large arrays.

parameter (n4G=4294967296) ! 4 giga  
double precision, dimension(1),allocatable::a(:),b(:),c(:)  
allocate(a(n4G/4),b(n4G/4), c(n4G/4)) ! 3 8GB arrays  
! then assign values to the arrays  
!

and you can drop -mcmodel=medium. Your executable gets smaller,  
and you can link in code not compiled -fPIC (unlike with -mcmodel=medium).  
Since the optimization technology works better w/o -mcmodel=medium, the  
code may run faster as well, when compiled -fast.

---

<div class="post-metadata">

**Author:** ![tull](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tull](https://forums.developer.nvidia.com/u/tull)\
**Post date:** [June 17, 2016, 9:49pm UTC](https://forums.developer.nvidia.com/t/fpic-and-mcmodel-medium-not-supported-together/134944/4 "2016-06-17T21:49:17Z")

</div>

I just installed 16.5 workstation, and added  
$PGI/linux86-64/16.5/bin and $PGI/linux86-64/2016/mpi/openmpi/bin

to my $PATH.

I then found I had problems with mpif90 until I added

$PGI/linux86-64/16.5/lib to $LD\_LIBRARY\_PATH .

Then  
mpif90 -mcmodel=medium foo.f

compiled with incident.

Check your environment, and add -dryrun or -v to your  
compilation and see if you everything is coming from the correct  
directories.
