# 64-bit medium memory model inconsistency

**URL:** <https://forums.developer.nvidia.com/t/64-bit-medium-memory-model-inconsistency/130418>\
**Category:** Legacy PGI Compilers (archived)\
**Created:** [July 27, 2006, 2:45pm UTC](https://forums.developer.nvidia.com/t/64-bit-medium-memory-model-inconsistency/130418 "2006-07-27T14:45:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![E\_Sumbar](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@E\_Sumbar](https://forums.developer.nvidia.com/u/E_Sumbar)\
**Post date:** [July 27, 2006, 2:45pm UTC](https://forums.developer.nvidia.com/t/64-bit-medium-memory-model-inconsistency/130418/1 "2006-07-27T14:45:09Z")

</div>

To compile the following Fortran code successfully with pgf77 version 6.1-6 on an Opteron, I have to specify -mcmodel=medium to accomodate the 3GB integer array; otherwise, I get “relocation truncated” errors.

```nohighlight
      program mem
      integer n, i
      parameter (n=750 000 000)
      integer x(n)
      common /global/ x
      do i = 1, n
         x(i) = 1
      end do
      print*, 'done'
      stop
      end

```

This is documented in the Release Notes. However, I don’t need the switch to compile and run the following C code that defines a similar 3GB global integer array.

```nohighlight
#include <stdio.h>
#define n 750000000

struct {int x[n];} global;

int main (int argc, char *argv[])
{
  for (int i = 0; i<n; i++)
    global.x[i] = 1;
  printf ("done\n");

  return (0);
}

```

Is this intended behaviour, or is the documentation slightly inconsistent?

By the way, the Intel compiler displays the same characteristic, but GCC doesn’t… strange.

Ed Sumbar

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [July 27, 2006, 5:30pm UTC](https://forums.developer.nvidia.com/t/64-bit-medium-memory-model-inconsistency/130418/2 "2006-07-27T17:30:54Z")

</div>

Hi Ed,

In both codes, “-mcmodel=medium” is not needed since the total size of your executable’s data section is less than 1GB. While you do use large arrays, the memory for these arrays is not allocated by the loader until runtime. If you had a very large program with many, many variables and thus a large binary, then you might needed it.

What you do need is to compile your program with is “-fpic”, since at runtime your program needs to address more than 2GB. For even larger arrays, you may also need “-Mlarge\_array” as well as using “integer\*8” and “long” for your index varaible’s data type.

Note that “-mcmodel=medium” implies “-fpic” and “-Mlarge\_arrays”.

- Mat

---

<div class="post-metadata">

**Author:** ![E\_Sumbar](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@E\_Sumbar](https://forums.developer.nvidia.com/u/E_Sumbar)\
**Post date:** [July 27, 2006, 7:26pm UTC](https://forums.developer.nvidia.com/t/64-bit-medium-memory-model-inconsistency/130418/3 "2006-07-27T19:26:31Z")

</div>

Thanks Mat. That clarifies the issue somewhat.

> [@mkcolg](#):
>
> In both codes, “-mcmodel=medium” is not needed since the total size of your executable’s data section is less than 1GB.

The PGI 6.1 Workstation Release Notes on page 35 defines DS, the maximum data size, as “all data objects in .bss”. I guess that should read .data not .bss… right?

> [@mkcolg](#):
>
> What you do need is to compile your program with is “-fpic”, since at runtime your program needs to address more than 2GB. For even larger arrays, you may also need “-Mlarge\_array” as well as using “integer\*8” and “long” for your index varaible’s data type.

The point is that although I need to specify -fpic (or mcmodel=medium) to compile and run the Fortran code, I don’t seem to need it for the equivalent C code.

```plaintext
$ pgcc -c9x mem.c
$ ./a.out
done

```

–  
Ed

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [July 27, 2006, 8:55pm UTC](https://forums.developer.nvidia.com/t/64-bit-medium-memory-model-inconsistency/130418/4 "2006-07-27T20:55:14Z")

</div>

> The PGI 6.1 Workstation Release Notes on page 35 defines DS, the maximum data size, as “all data objects in .bss”. I guess that should read .data not .bss… right?

It’s really the offset from the “.text” section to anywhere up to the end of “.bss”, which includes “.data”. I think our doc writers were trying to simplfy things. Although not technically correct either since there are other sections in there as well, would “all data objects in .data and .bss” more helpful?

> I don’t seem to need it for the equivalent C code.

You are correct that “-fpic” is not need here. I was using our development compiler and was getting a relocation truncation error without “-fpic”. Looks like a new part of our runtime was not being built correctly. Thanks for finding it!

- Mat

---

<div class="post-metadata">

**Author:** ![E\_Sumbar](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@E\_Sumbar](https://forums.developer.nvidia.com/u/E_Sumbar)\
**Post date:** [July 27, 2006, 9:35pm UTC](https://forums.developer.nvidia.com/t/64-bit-medium-memory-model-inconsistency/130418/5 "2006-07-27T21:35:31Z")

</div>

Hi Mat,

> [@mkcolg](#):
>
> > The PGI 6.1 Workstation Release Notes on page 35 defines DS, the maximum data size, as “all data objects in .bss”. I guess that should read .data not .bss… right?
> 
> It’s really the offset from the “.text” section to anywhere up to the end of “.bss”, which includes “.data”. I think our doc writers were trying to simplfy things. Although not technically correct either since there are other sections in there as well, would “all data objects in .data and .bss” more helpful?

The table on p. 35 says that “-tp k8-64 -fpic” supports a “data size” of 2GB max, while “-tp k8-64 -mcmodel=medium” supports \>2GB. When I do `size a.out` (or `objdump -h a.out`), the sum of .data and .bss is greater than 2GB. Therefore, based on the table, I’d expect to have to use -mcmodel=medium. But obviously, -fpic works. So, that table is a bit confusing.

In any event, is there any additional performance penalty in using -mcmodel=medium over -fpic?

Ed

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [July 27, 2006, 10:33pm UTC](https://forums.developer.nvidia.com/t/64-bit-medium-memory-model-inconsistency/130418/6 "2006-07-27T22:33:17Z")

</div>

> In any event, is there any additional performance penalty in using -mcmodel=medium over -fpic?

There can be due additional address calculation overhead.

- Mat
