| Tim Prince 2007-06-14, 10:07 pm |
| Lynn McGuire wrote:
> Is there a fortran equivalent of the c memset function ? That you can
> use to very efficiently zero an array of memory ?
>
> Thanks,
> Lynn
>
For some targets where it can be done efficiently, Fortran does actually
compile code which zeroes a contiguous array into a memset() call.
On many targets, the extra overhead of dealing with odd byte alignments,
as memset() must do, is better avoided by simply assigning 0 to an
array, as suggested in another response. Nowadays, there is not even
any point in causing a 64-bit or greater data type to overlay a default
real data type. Not even in C. Vectorizing compilers will automatically
generate a multi-word zero in order to optimize such an operation.
ifort for Xeon/Opteron targets has the directive
!dir$ vector nontemporal
which will prevent a following assignment to an array from filling
cache. pgf90 has compile options which produce the same effect, whenever
the compiler deems it conceivable that it may help.
|