extra memory used for intermediate calculations

I’m using pgi fortran 90 on a linux machine and would like to know how to determine if the compiler is using extra memory for intermediate calculations.

For example, if a and b are arrays then


does not use an extra array to store a+b before copying it to a. but if a,b,c,d,e are arrays then


would require extra memory for the two intermediate arrays. How would I check to see if this happens for less obvious cases (and to what extent)?


Xi Lin

Hi Xi Lin,

If you are familiar with the assembly, you can look at the generated code. Not sure what you are trying to get. You can also use top command to use at memory use and compare to the size of your binary.

What is your experience with other compilers?


thanks for the quick reply.

I have very little experience with compilers, much less assembly.

I have a fixed cluster with a fixed amount of memory and would like to be able to solve as large as problems as possible. In order words, it is easy to keep track of the memory i statically and dynamically allocate, but I wish to know what other memory fortran uses for intermediate calculations.

because if i calculate


and I stay safe, then I would have to declare a third variable:


Thus increasing the amount of memory used by 50%.

I am not sure what you mean by top command and size of binary?


top command is a unix top command.

Type: top

You will see that what is total memory, how much it is used, and other information. You can do that before you run a binary and then once you run a binary you can see how much memory is used for your program based on the information printing by top. You will need to consider the size of your binary when looking at memory used that it is not an extra memory.

Hope this helps.

OK i see. That helps me see the total memory occupied, but does not give me any details on a specific line of the code. There is no other way than looking at the assembly??


Sorry, as far as I know there is no easy way to do.