- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page