C/C++ and Fortran

 View Only

ALLOCATE enhancements

By Archive User posted Fri April 26, 2013 10:14 PM


Originally posted by: Yvonne Ma

XL Fortran V14.1 supports the Fortran 2008 enhancements to the ALLOCATE statement.

The first enhancement has to do with the SOURCE= specifier.  In Fortran 2003, you are not allowed to omit the bounds information when allocating an array in the ALLOCATE statement. In Fortran 2008, when you use an ALLOCATE statement without specifying the bounds for an array, the bounds of source_expr in the SOURCE= specifier determine the bounds of the array.

The second enhancement is the addition of the MOLD= specifier.  The MOLD= specifier works almost in the same way as SOURCE=.  Like SOURCE=, MOLD= causes the object to be allocated to have the same type and type parameters as the source_expr specified in the MOLD= specifier.  Similarly, if you don't specify the bounds for an array in the ALLOCATE statement, the bounds of source_expr in the MOLD= specifier determine the bounds of the array. Unlike SOURCE=, MOLD= does not copy the value of source_expr to the variable to be allocated. Because no copying takes place, if source_expr in MOLD= is a variable, its value need not be defined.

In the same ALLOCATE statement, you can specify only one of SOURCE= or MOLD=.

For more information about the updates, visit ALLOCATE.

Authors: Rafik Zurob, Yvonne Ma

1 comment



Fri January 12, 2018 11:28 PM

Originally posted by: DavidAppelhans

MOLD works with well with CUDA fortran, is SOURCE supported? For example if I want to allocate a device array of the same size as the host array I can do: allocate( devarray, MOLD=hostarray). If I want to copy the host array to the device array, can I accomplish this with allocate( devarray, SOURCE=hostarray )?