正如標題所說,我對數組本身和數組子集之間的類型差異感興趣。對於背景,我將數組傳遞給一個MPI函數,該函數在用零長度數組調用時會觸發'數組索引超出邊界'錯誤,但只能使用子集符號。這是問題的一個簡化的例子在眼前:在Fortran中,將myArray或myArray(:)傳遞給函數有什麼區別?
real(4), allocatable :: myData(:)
allocate(myData(numElements), STAT=iStat)
! The following calls only differ in the second argument
! Passing array itself always works (e.g. myData)
call MPI_FILE_WRITE_ALL(file, myData, MPI_REAL4, numElements, &
MPI_STATUS_IGNORE, mpiErr)
! Passing converted subset always works (e.g. real(myData(:), 4)
call MPI_FILE_WRITE_ALL(file, real(myData(:), 4), MPI_REAL4, numElements, &
MPI_STATUS_IGNORE, mpiErr)
! Passing subset works unless numElements is zero
call MPI_FILE_WRITE_ALL(file, myData(:), MPI_REAL4, numElements, &
MPI_STATUS_IGNORE, mpiErr)
這裏是對documentation for MPI_FILE_WRITE_ALL的鏈接,但它似乎只需要BUFFER(*)。任何想法爲什麼這些不同的調用行爲如此不同?
http://software.intel.com/zh-cn/blogs/2008/03/31/doctor-it-hurts-when-i-do-this/ –