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

memory mapping/copying?

Yong_Tang
Beginner
830 Views
I do not know how this should be called. But here is what I want to do. I need to read some input data into arrays from text files. Then these data will be used for calculations. During the calculation, the values in these arrays will be updated. However, the calculation will be carried out repeatedly using the originally data from the text files. But I don't want to read them from the text files again and again because it would slow down the simulation. Is there a technique to copy these input data to some temporary memoryand get them back quickly when I need them without creating new array variables?
0 Kudos
5 Replies
Arjen_Markus
Honored Contributor II
830 Views
Why do you not want to create new array variables?

One solution to keep the original data is to introduce a new dimension:

real, dimension(100,2) :: data

... read the original values into data(:,2)

do i = 1,process_steps
! Start processing
data(:,1) = data(:,2)

... process the values in data(:,1)
enddo

Just a sketch of course

Regards,

Arjen
0 Kudos
anthonyrichards
New Contributor III
830 Views
You cannot expect the sequence

REAL A
CALL READIN(A)
CALL MANIPULATE(A)
to miraculously preserve the original A somewhere.

As Arjen shows, you have to keep a copy of the original A somewhere.
If that counts as an 'extra' array, so be it.

REAL A, ACOPY
CALL READIN(A)
ACOPY=A
CALL MANIPULATE(ACOPY)
0 Kudos
Yong_Tang
Beginner
830 Views
Thank you guys for your reply. I don't want to do that because this is an old and large program which has hundreds of array variables. Which means I will need to create new variables for each of them. On the other hand, I am trying to find every possible way to cut the memory access time because I am going to call this program for thousands of times.
0 Kudos
jimdempseyatthecove
Honored Contributor III
830 Views
If this is an old program your input variables (if not a single array) might be located in COMMON. Can you (easily) collect all your input data into a same named COMMON. If so then you use the same named COMMON declared using a single array name (with proper size). Then use the array copy technique as previously mentioned in this forum.

CALL YourRead() ! into variables in same named common
YourSave = YourAlternateArrayName ! alternate mapping of same named common
CALL PART1()
YourAlternateArrayName = YourSave
CALL PART2()
YourAlternateArrayName = YourSave
call part3()
...

Jim Dempsey
0 Kudos
rwg
Novice
830 Views
In this special case an EQUIVALENCE may help:

REAL ARR1(100),B,C(20) ! your REAL Variables (121*4 Bytes)
INTEGER I1,IARR(200) !your INTEGERVariables (201*4 Bytes)
DOUBLE PRECISION DARR(20) ! your DOUBLE Variables (40*8 Bytes)
INTEGER MEM1(402) ! 121*4+201*4+40*8 = (121+201+80)*4 = 402*4Bytes
INTEGER MEM2(402) ! Array to save the variables
EQUIVALENCE(MEM1(1),ARR1(1)) ! Be careful: avoid overlapping and gaps
EQUIVALENCE(MEM1(101),B)
EQUIVALENCE(MEM1(102),C(1))
EQUIVALENCE(MEM1(122),I)
EQUIVALENCE(MEM1(123),IARR(1))
EQUIVALENCE(MEM1(323),DARR)

MEM2=MEM1 ! save variables
!do calculations
MEM1=MEM2 ! restore variables

But this will only work if all your Variables ARR1,B,C,I,IARR,DARR are local variables.
I don't recommand to use EQUIVALENCE because it makes programs hard to understand but in this special case it may help you.
0 Kudos
Reply