# THIS_IMAGE

Transformational Intrinsic Function (Generic): Returns the image index of the invoking image on the current or specified team, or the cosubscripts for the executing image on the current or specified team.

result = THIS_IMAGE ([ team ])

result = THIS_IMAGE (coarray [, team])

result = THIS_IMAGE (coarray, dim [, team])

team | (Input; optional) Must be a scalar of type TEAM_TYPE defined in the intrinsic module ISO_FORTRAN_ENV whose value describes the current team or an ancestor team. If team is not specified, the team is the current team.
coarray | (Input; optional) Must be a coarray; it can be of any type. If it is allocatable, it must be allocated. If team is specified, coarray must be established on that team.
dim | (Input; optional) Must be a scalar of type integer. coarray must be specified if dim is present. Its value must be in the range 1 <= dim <= n, where n is the corank of coarray. If the corresponding actual argument is an optional dummy argument, it must be present.

## Results

The result type is default integer. It is scalar if coarray is not specified or dim is specified; otherwise, the result has rank one and its size is equal to the corank of coarray.

The result depends on which arguments are specified:

- If no argument is specified, as in THIS_IMAGE ( ), the result is a scalar with a value equal to the index of the invoking image on the current team.

- If only the team argument is specified, the result is a scalar with a value equal to the index of the invoking image on the specified team.

- If coarray is specified and dim is not, the result is the sequence of cosubscript values for coarray that would specify the invoking image on the specified team, or the current team if team is not specified.

- If coarray and dim are specified, the result is the value of cosubscript dim in the sequence of cosubscript values for coarray that would specify the invoking image on the specified team, or the current team if team is not specified.

## Examples

Consider that coarray C is declared by the following statement:

    REAL C(5, 10) [10, 0:9, 0:*]

On image 5 of the current team, THIS_IMAGE ( ) has the value 5 and THIS IMAGE (C) has the value [5, 0, 0]. For the same coarray on image 213, THIS_IMAGE (C) has the value [3, 1, 2].

In the following example, image 1 on the current team is used to read data. The other images then copy the data:

    IF (THIS_IMAGE()==1) READ (*,*) P
    SYNC ALL
    P = P[1]

Consider the following program:

      PROGRAM main
      USE, INTRINSIC       :: ISO_FORTRAN_ENV
      TYPE (TEAM_TYPE)     :: initial, odd_even
      INTEGER coarray1[0:9, 10, *], coarray2 [10, 10, *]
      initial = GET_TEAM (CURRENT_TEAM)
      FORM TEAM (2-MOD(THIS_IMAGE(), 2), odd_even)
      PRINT *, THIS_IMAGE()
      PRINT *, THIS_IMAGE (coarray1)
      PRINT *, THIS_IMAGE (coarray2, 2)
      CHANGE TEAM (odd_even)
        . . .
        PRINT *, THIS_IMAGE(), THIS_IMAGE(initial)
        PRINT *, THIS_IMAGE(coarray1)
        PRINT *, THIS_IMAGE(coarry2,TEAM = initial)
        PRINT *, THIS_IMAGE(coarray2, 2)
        PRINT *, THIS_IMAGE(coarray2, 2, initial)
        . . .
      END TEAM
      . . .
      END PROGRAM

If there are 1024 images on the initial team, on image 8 of the initial team, the first print statement will print 8, the second print statement will print the value of the array [7, 1, 1], and the third print statement will print 1. On that same image, the first print statement inside the CHANGE TEAM construct prints 4, 8, the second prints the value of the array [7, 1, 1], the third prints the value of the array [8, 1, 1], and the fourth and fifth both print 1.

On image 512 of the original team, the first print statement will print 512, the second print statement will print the value of the array [1, 2, 6], and the third will print 2. On the same image inside the CHANGE team construct, the first print statement will print 256 and 512, the second prints the value of the array [1,2,6], the third prints the value of the array [2,2,6], and the fourth and fifth both print 2.

Parent topic: T to Z