Memory alignment in Fortran

I’ve got a hankering to align my allocatable arrays in Fortran on 16-byte boundaries (i.e., the first address ends in binary 0000). There doesn’t seem to be any simple way to do this with pgfxx (or any other Fortran compiler, given what I’ve found on Google).

Any chance there is a pgfxx compiler option or non-standard version of ALLOCATE that I just don’t know about?

If not, does anyone out there have good workaround suggestions for how to accomplish this?

So far, the only way I’ve been able to get this done is pretty ugly: call a C program from Fortran, create the variable and allocate it’s memory in C, then pass that variable back to Fortran. It’s hideous because you can’t simply return from C to the original Fortran routine. You’ve got to go another layer deep to hold onto the new block of memory. It just feels wrong.

Any thoughts, anyone?

-Matt

Hi Matt,

Memory alignment is determined by the OS and on 64-bit Linux and Windows it should be 16-byte aligned. A 32-bit OS should be 8-byte aligned. Are you using a 32 or 64-bit system?

  • Mat

Mat,

It is a 64-bit operating system. And you’re right — I put in some checks, and I am getting 16-byte alignment. I think my problem may be some indexing that’s too clever for its own good.

Chalk this one up to user error.

Thanks,

-Matt