Steve,
This method looks promising. Is this type of pointer specific to the intel compiler or will it work with others as well (I am trying to make the code as portable as possible and avoid using compiler specific code)?
Also I have tested this out on a simple case and it seems to work for me. But here is the real question.
My common block is not as simple as a single array. It is instead a mix of anywhere from 6 to 20 arrays of various ranks and sizes (different declarations of the common block have differing numbers of arrays and different ranks of arrays, and there are 12 unique uses of the same common block, with dozens of overall uses). To make matters worse each array does not necessarily have the same memory footprint. An extremely simplified example would be:
/cblock/array1(n,j+1,k,L),array2(k),array3(n,j+1),array4(k,l,n,m,o,j),array5(i,i,n,j),rjnkm(1)
in one routine
/cblock/array6(n,k,L),array7(k,n,i),array8(l),array9(k,l,o,j),array10(i,j),rjnkm(n*k*l*j+...+i*n*j)
in another
The array rjnkm is a "junk" memory placeholder added at the end of each common block version to ensure that each one had the same overall memory footprint (the length of the rjnkm array is determined by a very mathematically simple yet drawn out calculation which I have only alluded to in the above example).
From my understanding a common block acts as a pointer to the first memory location of a block of contiguous memory which is accessed in each routine based on the variables declared in the common block declaration of that routine. Thus in the above example array7 in the second usage would really overlap a lot of the memory of array 1 from the first usage. Luckily in this case they at least used all of the memory as reals and not some real and some integers and some logicals (I hate to think what is really going on with the memory in that case).
From what I can tell the code was written in this manner to reuse the memory for machines that had limited resources. I understand this is horrible coding practice but it would be nye impossible to correct the code at this point. I want to mimic the old common block behavior so as to avoid any unintended changes to the code behavior.
Based on your previous response it seems like an option might be to define a 1D array in the module, lets call it Rmem(:)
and I allocate it to be of the length of the longest of any of the common blocks without the rjnkm array included.
in this example it would be of length (n*(j+1)*k*L+k+n*(j+1)+(k*l*n*m*o*j)+(i*i*n*j)) (you should see what it really looks like with the non-simplified example)
then in each routine I carve up the memory according to how the usage is in that common block
i.e. in the first routine I have pointers
real, pointer:: array1(:,:,:,:),array2(:),array3(:,:),array4(:,:,:,:,:,:),array5(:,:,:,:)
array1(1:n,1:j+1,1:k,1:L)=>Rmem(1:n*(j+1)*k*L)
array2(1:k)=>Rmem(n*(j+1)*k*L+1:n*(j+1)*k*L+k)
array3(1:n,1:j+1)=>Rmem(n*(j+1)*k*L+k+1:n*(j+1)*k*L+k+n*(j+1))
array4(1:k,1:l,1:n,1:m,1:o,1:j)=>Rmem(n*(j+1)*k*L+k+n*(j+1)+1:n*(j+1)*k*L+k+n*(j+1)+(k*l*n*m*o*j))
array5(1:i,1:i,1:n,1:j)=>Rmem(n*(j+1)*k*L+k+n*(j+1)+(k*l*n*m*o*j)+1:n*(j+1)*k*L+k+n*(j+1)+(k*l*n*m*o*j)+(i*i*n*j))
and the other routine would have different pointers and limits.
1 Would this even work in theory (it will take me days to implement if so)?
2 Is this really the best way to mimic the old behavior? It seems like there should be some workaround that allows each routine to work off of a single memory pointer like with the common blocks and let the routine determine the starting index and shape/size of each array.
Thanks again,
~Tim