Skip to content

Limited Fortran Intrinsics Library

Matt Norman edited this page Apr 29, 2022 · 4 revisions

YAKL contains a limited library of Fortran intrinsic functions. Currently, they include the functions below. All computations-based (e.g., not tiny or epsilon) intrinsics called on SArray and FSArray objects are done in serial and can be performed inside parallel_for kernels. All computations-based intrinsics called on memDevice Array objects will invoke a kernel and cannot per performed inside parallel_for kernels.

  • abs: Absolute value (element-wise) of an array
    • Same as the Fortran intrinsic. Works on all Array, SArray, and FSArray objects.
  • all: Determines if all of the elements of a bool array are true
    • Same as the Fortran intrinsic except without the optional dim argument. Works on all Array, SArray, and FSArray objects.
  • allocated: Determines if an array has been allocated
    • Same as the Fortran intrinsic. Works on all Array, SArray, and FSArray objects.
  • any: Determines if any of the elements of a bool array are true
    • Same as the Fortran intrinsic except without the optional dim argument. Works on all Array, SArray, and FSArray objects.
  • associated: Determines if an array has been allocated (same spirit as Fortran given different C++ semantics)
    • Same as the Fortran intrinsic. Works on all Array, SArray, and FSArray objects.
    • Recall that with YAKL Array objects, there is little meaningful difference between allocated and associated.
  • count: Gives the number of true elements in a bool array
    • Same as the Fortran intrinsic except without the optional dim and kind arguments. Works on all Array, SArray, and FSArray objects.
  • epsilon: Gives machine epsilon for the floating point type of the array or scalar passed in
    • Same as the Fortran intrinsic. Works on all Array, SArray, and FSArray, and scalar objects.
  • huge: Gives the largest representable value for the arithmetic type of the array or scalar passed in
    • Same as the Fortran intrinsic. Works on all Array, SArray, and FSArray, and scalar objects.
  • lbound: Gives the lower bound of the array passed in
    • Same as the Fortran intrinsic. Works on all Array, SArray, and FSArray objects.
    • For styleC Array objects and SArray objects: Without the dim argument, this returns an SArray object of rank 1. With the dim argument, zero-based indexing is expected.
    • For styleFortran Array objects and FSArray objects: Without the dim argument, this returns an FSArray object of rank 1 and lower bound of 1. With the dim argument, one-based indexing is expected.
  • matinv: Matrix inverse for small arrays using Gaussian Elimination
    • This is not a Fortran intrinsic function, but it provides the inverse of square rank-2 SArray and FSArray matrix objects.
  • matmul_cr and matmul_rc: Matrix multiplication using (column,row) and (row,column) format matrices
    • Same as the Fortran intrinsic. Works on SArray and FSArray objects only. FSArray objects must have the default lower bounds of 1 to be accepated by these routines.
  • maxloc and minloc: Index of maximum and minimum value in an array
    • Same as the Fortran intrinsic without the optional dim, mask, kind, and back arguments. Only works on Array, SArray, and FSArray objects of rank 1.
    • When -DYAKL_B4B is turned on, device maxloc calculations are done serially on the host to preserve determinism
  • maxval and minval: Maximum and minimum value in an array
    • Same as the Fortran intrinsic without the optional dim and mask arguments. Works on all Array, SArray, and FSArray objects.
  • merge: Merge two arrays based on a bool mask array
    • Same as the Fortran intrinsic. Works on all Array, SArray, FSArray, and scalar objects.
  • mod: Computes integer mod: a % b = a - ((int)(a/b) * b
    • Same as the Fortran intrinsic.
  • pack: Packs an array into a single dimension with an optional mask.
    • Same as the Fortran intrinsic without the optional vector argument and only for rank-1 arrays. Works for all rank-1 Arrayobjects.
    • Does not work on SArray and FSArray objects because those require compile-time-known sizes, and the dimension sizes of the result of a pack operation cannot be known at compile time.
    • Calling pack on a memDevice Array leads to copying the inputs to the host, running pack on the host, and copying the results back to the device. This is because it is largely a serial operation.
  • product: Computes the product over all elements of an array
    • Same as the Fortran intrinsic without the optional dim and mask parameters. Works on all Array, SArray, and FSArray objects.
  • shape: Returns the shape an array as a rank-1 array of dimension sizes
    • Same as the Fortran intrinsic . Works on all Array, SArray, and FSArray objects.
    • For styleC Array objects and SArray objects, this returns an SArray object of rank 1.
    • For styleFortran Array objects and FSArray objects, this returns an FSArray object of rank 1 and lower bound of 1.
  • sign: Applies the sign of the second argument to the first argument
    • Same as the Fortran intrinsic . Works on all Array, SArray, and FSArray objects.
  • size: Gives the total elements of an array or the number of elements in a given dimension
    • Same as the Fortran intrinsic . Works on all Array, SArray, and FSArray objects.
    • For styleC Array objects and SArray objects: Without the dim argument, this returns an SArray object of rank 1. With the dim argument, zero-based indexing is expected.
    • For styleFortran Array objects and FSArray objects: Without the dim argument, this returns an FSArray object of rank 1 and lower bound of 1. With the dim argument, one-based indexing is expected.
  • sum: Gives the sum of all elements in an array
    • Same as the Fortran intrinsic without the optional dim and mask parameters. Works on all Array, SArray, and FSArray objects.
  • tiny: For floating point types, gives the smallest positive representable number. For integer types, gives the smallest overall representable number.
    • Same as the Fortran intrinsic for floating point types. Works on all Array, SArray, and FSArray objects.
  • transpose: Transposes a rank-2 matrix
    • Same as the Fortran intrinsic. Works on all Array, SArray, and FSArray objects.
  • ubound: Gives the upper bound of the array passed in
    • Same as the Fortran intrinsic. Works on all Array, SArray, and FSArray objects.
    • For styleC Array objects and SArray objects: Without the dim argument, this returns an SArray object of rank 1. With the dim argument, zero-based indexing is expected.
    • For styleFortran Array objects and FSArray objects: Without the dim argument, this returns an FSArray object of rank 1 and lower bound of 1. With the dim argument, one-based indexing is expected.
Clone this wiki locally