Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

## best option to deallocate an dimension of an array

Beginner
847 Views

hello!

I have an  four dimension array for describing particles vectors varying on time. "real(kind=16), dimension(time,particle,vectors,components)"

i generating an array for every 0.00001s, from 0 to 60s, for 300000 different particles, with minimum 4 vectors and 4 components. in other words is a very big array which will be allocated for weeks. but i dont need the allocation of entire array, is required just the actual time which is generating (t) and before (t-1) because every timestep will be printed in a file and will not be anymore used on calculations.

there is an way to deallocate just one dimension of an array for example: (t-2,all vectors,all particles, all components)?

if not there is a better option?

1 Solution
Honored Contributor III
847 Views

It would help to see the whole of your program to offer any meaningful response.

Bear in mind that there is:

a) the abstract description of an algorithm, this generally leans towards Object Oriented Programming viewpoint.
b) computational efficiency of producing a solution using a reformulation of the algorithm without any adverse consequences.

Method a) is normally called Array of Structures (AOS)
Method b) rearranges the data such that you have arrays of properties. Otherwise known as Structure of Arrays (SOA)

Method a) is generally not vectorizable excepting for the use of scatter/gather instructions
Method b) is generally fully vectorizable, though in some cases there may be some difficulties.
Scatter/gather is not as efficient as contiguous vector operations.

*** When the problem is simple and has low computational requirements, method a) is acceptable.
*** When the problem has high computational requirements vectorization usually results in much higher performance (2x, 4x, ...)

>>In addition, is there an array that can refer to either a value or a character set from a name?

I do not understand. Do you mean a polymorphous type?

If this is to be manipulated in the non-performance critical area of your program, then store/present the value as text. And then let the reader decide if the content is value or name.

Jim Dempsey

12 Replies
Honored Contributor III
847 Views

>>but i dont need the allocation of entire array, is required just the actual time which is generating (t) and before (t-1) because every timestep will be printed in a file and will not be anymore used on calculations

`real(kind=16), dimension(-1:0,particle,vectors,components) :: data`

IOW use data(-1,p,v,c) to produce data(0,p,v,c) and after you write  data(0,p,v,c) issue

data(-1,:,:,:) = data(0,:,:,:)

The time need not be maintained nor written to the output file (other than in header that may hold dT).

Jim Dempsey

Beginner
847 Views

it seens that arrays have some limit of dimension number, for example 10000000 starts a compilation error, there is some way to handle without creating another array?

for naming my output file i have to adequate format descriptor, there is a way less "ugly" and compact for naming?

IF (step < 10) THEN
format_string = "(A7,I1)"
ELSE IF ((step > 9) .and. (step < 100)) THEN
format_string = "(A7,I2)"
ELSE IF ((step > 99) .and. (step < 1000)) THEN
format_string = "(A7,I3)"
ELSE IF ((step > 999) .and. (step < 10000)) THEN
format_string = "(A7,I4)"
ELSE IF ((step > 9999) .and. (step < 100000)) THEN
format_string = "(A7,I5)"
ELSE IF ((step > 99999) .and. (step < 1000000)) THEN
format_string = "(A7,I6)"
ELSE IF ((step > 999999) .and. (step < 10000000)) THEN
format_string = "(A7,I7)"
ELSE IF ((step > 9999999) .and. (step < 100000000)) THEN
format_string = "(A7,I8)"
ELSE IF ((step > 99999999) .and. (step < 1000000000)) THEN
format_string = "(A7,I9)"
END IF
WRITE (filename,format_string) "results", step
filename = TRIM(filename)//".vtk"

Thank you!! it really helped

Honored Contributor II
847 Views

The '(I0)' format is what you need to use, the width you get is the minimum width needed for the size of integer you are formating. Or use i9.9 to pad with leading zeros making all the strings the same length.

Honored Contributor II
847 Views

What is the exact compile error message at #3?

Honored Contributor III
847 Views

>>it seens that arrays have some limit of dimension number, for example 10000000 starts a compilation error, there is some way to handle without creating another array?

The limit applies to statically declared arrays. This is a Linker issue. The way to work around this is to make the array allocatable, then allocate it to the larger size at the start of your program.

An issue I find with using the file naming approach as listed in #3 is that the resulting file names produced are not alphabetically in order. Consider using 9 (worst case) digits with leading 0's. This way your file manager can view and sort the files in order. Sorting by date modified may be inadequate.

Jim Dempsey

Beginner
847 Views

Thank you very much Jim Dempsey and andrew_4619 for your attention and patience.

I have a last question, what is the difference of using an variable and a pointer to address dimensions of an array?

e.g.

!taking as an example the array mentioned in my first post of this topic

integer, parameter :: force = 1, step = 2, component_i =3

Or

integer, pointer :: force....

Has any difference in terms of performance? There is a better way?

Honored Contributor III
847 Views

I would suggest you not use pointer. Use an array

```integer, allocatable :: force(:,:) ! allocate to (3,Nparticles)
.OR.
integer, allocatable :: forceX(:), forceY(:), forceZ(:) ! allocate to (Nparticles)...

```

The choice, for performance reasons, depends on how your algorithms manipulate the data. When the algorithms can be written to exploit the processor's vector capability, then the second method is better.

The first rule of optimization is:

vectorize inner - parallel outer

Treating "particles" as a collection of singular typed objects (OOP) does .NOT. permit vectorizaton. Vectorization is possible when you have arrays of individual properties. Note, individual is at finest partitioning: forceX, forceY, forceZ as opposed to three component vector.

Using the parameters, as in your first proposition in #7 requires a selection of and array of particles, with the member variables referenced via different indicies into that multi-dimensional array.

Jim Dempsey

Honored Contributor III
847 Views

RE: vectorization

Assume your are a small business where it snows in the winter. You hire four strong teenagers to shovel your parking lot. Do you give them 12" wide shovels, or 36" wide shovels? The 12" case is analogous to scalar operations, and the 36" case is vector operations.

Jim Dempsey

Valued Contributor III
847 Views

Or you hire a young lady and a snow blower and you now have the beauty of Lisp.

Beginner
847 Views

ok, i understand

For my use I have made the vectors twice the size needed to be able to store two different times, also using vector(...) =vector(...)

Is it possible to do arrays with names and values ​​referenced to these? to avoid having to reference an integer to an array and thus get a value? for example a array with all properities, like delta time, time final, number of particles

In addition, is there an array that can refer to either a value or a character set from a name?

thank you guys for help

Honored Contributor III
848 Views

It would help to see the whole of your program to offer any meaningful response.

Bear in mind that there is:

a) the abstract description of an algorithm, this generally leans towards Object Oriented Programming viewpoint.
b) computational efficiency of producing a solution using a reformulation of the algorithm without any adverse consequences.

Method a) is normally called Array of Structures (AOS)
Method b) rearranges the data such that you have arrays of properties. Otherwise known as Structure of Arrays (SOA)

Method a) is generally not vectorizable excepting for the use of scatter/gather instructions
Method b) is generally fully vectorizable, though in some cases there may be some difficulties.
Scatter/gather is not as efficient as contiguous vector operations.

*** When the problem is simple and has low computational requirements, method a) is acceptable.
*** When the problem has high computational requirements vectorization usually results in much higher performance (2x, 4x, ...)

>>In addition, is there an array that can refer to either a value or a character set from a name?

I do not understand. Do you mean a polymorphous type?

If this is to be manipulated in the non-performance critical area of your program, then store/present the value as text. And then let the reader decide if the content is value or name.

Jim Dempsey

Beginner
847 Views

thank you all for help and patience!! i learned a lot from all your answers!