- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Is passing a contiguous array section of an allocatable array to a subroutine where the corresponding dummy argument is an explicit shape array efficient? In other words, is a temporary array created?
Consider the following example:
PROGRAM PROG
INTEGER(4) N,P
REAL(8),ALLOCATABLE :: M(:,:)
! Allocate and initialize M(N,P)
CALL SUB(M(:,1),N)
END PROGRAM PROG
SUBROUTINE SUB(A,SIZE)
INTEGER(4) SIZE
REAL(8) A(SIZE)
! Do some work here...
END SUBROUTINE
Is this efficient? Is the array passed by address or by value in SUB (in the later case a copy of the array section would need to be done I suppose).
How does the compiler recognize that the data (the array section) is contiguous?
Thanks,
Olivier
Ссылка скопирована
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Olivier,
Consider using
CALL SUB(M(:,1), size(M(:,1)))
This reduces potential for error in the event the allocation is changed without changing N.
The is nothing wrong with using the N as you had before...
as long as the N isn't reused with different values for different arrays.
The above syntax should be within a few memory cycles of using N.
Jim Dempsey
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Thank you Jim and Steve for your help. I found the run-time check solution proposed by Steve a very valuable tool.
Olivier
- Подписка на RSS-канал
- Отметить тему как новую
- Отметить тему как прочитанную
- Выполнить отслеживание данной Тема для текущего пользователя
- Закладка
- Подписаться
- Страница в формате печати