gfortran currently implements the TRANSPOSE intrinsic by simply rearranging the array descriptor, which can save considerable time when passed to an assumed-shape argument. Two more intrinsics can be implemented in this way:
RESHAPE can check for contiguity of its argument and if so, only construct a new descriptor sharing the data. If, as I assume, the array element reference a(i1,i2,i3) is computed equivalently to: *((type *)(offset + i1*dim[0].stride + i2*dim[1].stride + i3*dim[2].stride) then one can also implement a fast version of SPREAD by using zero strides in the array descriptor (thus the array reference will ignore some of the indices). This also covers broadcasting a scalar to an array (all zero strides). For code using whole array manipulation intensively, I'd expect significant savings of both time and memory. Can't find at this moment how to attach a file in this form, so I'll post a test case afterwards. cheers to all gfortran developers, Jaroslav Hajek -- Summary: efficiency of RESHAPE and SPREAD Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: highegg at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32512