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

how to extend array bounds

jackmwl
Beginner
484 Views
Hi everyone,

There is an allocatable array Ap(100000) required to be extended to A(1000000).
The code is used to do this as follows,

ALLOCATE(A(1000000))
A(:100000)=Ap
DEALLOCATE(Ap)

But I am not sure this is an efficient way. So how to extend the allocatable arraysize from 100,000 to 1000,000 more efficiently?

Any help would be highly appreciated!

Best regards

Jack

0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
484 Views
Check out MOVE_ALLOC in your manual. There is also a reallocation sample.
0 Kudos
jackmwl
Beginner
484 Views
Hi Jugoslav,

Thanks for your reply!
I am sorry that I didn'tdescribe thequestion clearly.

A(:) is an allocatable array of workspace, but it's uncertain about its size.
Before evaluating the size of A, Ap(:) is used as an temporary allocatable array to store some information instead of A , of which the size is assumed to be 100,000, as shown in the following code.

After evaluating the size of A, A needs to be allocated and store the information as workspace; Ap is not used anymore.

Mycode is used to do this with the size of A 1000,000 as follows,
! Ap is temporary workspace, A does not exist
! evaluate the size of A, then do

ALLOCATE(A(1000000))

A(:100000)=Ap

DEALLOCATE(Ap)
! A is workspace now, Ap is not used

This code works, but I thought that A(:100000)=Ap in this code may be not efficient. So I am trying to find a more efficient way in which maybe Ap or copying values of Ap to A not be needed, and the bounds of A(:) could just be extended from 100,000 to 1000,000 efficiently.

MOVE_ALLOC doesmore than what i need, as follows

! Ap is temporary workspace, A does not exist

! evaluate the size of A, then do

ALLOCATE(A(1000000))

A(:100000)=Ap
MOVE_ALLOC(A,Ap) ! this is not necessary
! Ap is still workspace here, A is not used



Best regards

Jack

0 Kudos
Reply