>> Japanese

# Data Mapping

## nodes directive

The nodes directive declares a named node array.

 C ``````ex. 1 : #pragma xmp nodes p[4] ex. 2 :#pragma xmp nodes p[*] ex. 3 :#pragma xmp nodes p[2][2] ex. 4 :#pragma xmp nodes p[*][3][2]`````` Fortran ``````ex. 1 : !\$xmp nodes p(4) ex. 2 : !\$xmp nodes p(*) ex. 3 : !\$xmp nodes p(2,2) ex. 4 : !\$xmp nodes p(2,3,*)``````
• In ex. 1, the program is executed by four nodes.
• In ex. 2, processing is matched to the number of nodes specified when the program is executed.
• Multidimensional node sets, such as in ex. 3 and 4, can also be declared. The product of the number of nodes for each dimension must be the same as the number of computation nodes employed.
• In ex. 4, when the number of nodes at execution time is specified to be 12, "∗" would be 2. nodes-spec can be "∗" only in the last dimension.

## template directive

The template directive declares a template as a virtual index.

 C ``````ex. 1 : #pragma xmp template t[10] ex. 2 : #pragma xmp template t[20][10]`````` Fortran ``````ex. 1 : !\$xmp template t(10) ex. 2 : !\$xmp template t(10, 20)``````
• As in ex. 2, a two-dimensional (or larger) template can be declared.

## distribute directive

The distribute directive specifies distribution of a template.

 C ``````ex. 1 : #pragma xmp distribute t[block] onto p ex. 2 : #pragma xmp distribute t[cyclic][block] onto p ex. 3 : #pragma xmp distribute t[*][block] onto p`````` Fortran ``````ex. 1 : !\$xmp distribute t(block) onto p ex. 2 : !\$distribute t(block, cyclic) onto p ex. 3 : !\$xmp distribute t(block, *) onto p``````
• Possible distribution are "∗", "block", "block(n)", "cyclic", "cyclic(n)", and "gblock(m)".
• "∗" means that this particular dimension is duplicated.

### block distribution

C
``````#pragma xmp nodes p[4]
#pragma xmp template t[20]
#pragma xmp distribute t[block] onto p``````
Fortran
``````!\$xmp nodes p(4)
!\$xmp template t(20)
!\$xmp distribute t(block) onto p``````
nodeindexes of template
p[0] 0, 1, 2, 3, 4
p[1] 5, 6, 7, 8, 9
p[2] 10, 11, 12, 13, 14
p[3] 15, 16, 17, 18, 19
nodeindexes of template
p(1) 1, 2, 3, 4, 5
p(2) 6, 7, 8, 9, 10
p(3) 11, 12, 13, 14, 15
p(4) 16, 17, 18, 19, 20

### cyclic distribution

C
``````#pragma xmp nodes p[4]
#pragma xmp template t[20]
#pragma xmp distribute t[cyclic] onto p``````
Fortran
``````!\$xmp nodes p(4)
!\$xmp template t(20)
!\$xmp distribute t(cyclic) onto p``````
nodeindexes of template
p[0] 0, 4, 8, 12, 16
p[1] 1, 5, 9, 13, 17
p[2] 2, 6, 10, 14, 18
p[3] 3, 7, 11, 15, 19
nodeindexes of template
p(1) 1, 5, 9, 13, 17
p(2) 2, 6, 10, 14, 18
p(3) 3, 7, 11, 15, 19
p(4) 4, 8, 12, 16, 20

### block-cyclic distribution

C
``````#pragma xmp nodes p[4]
#pragma xmp template t[20]
#pragma xmp distribute t[cyclic(2)] onto p``````
Fortran
``````!\$xmp nodes p(4)
!\$xmp template t(20)
!\$xmp distribute t(cyclic(2)) onto p``````
nodeindexes of template
p[0] 0, 1, 8, 9, 16, 17
p[1] 2, 3, 10, 11, 18, 19
p[2] 4, 5, 12, 13
p[3] 6, 7, 14, 15
nodeindexes of template
p(1) 1, 2, 9, 10, 17, 18
p(2) 3, 4, 11, 12, 19, 20
p(3) 5, 6, 13, 14
p(4) 7, 8, 15, 16

### gblock(m) distribution

C
``````#pragma xmp nodes p[4]
#pragma xmp template t[20]
int m[4] = {3, 5, 8, 4};
#pragma xmp distribute t[gblock(m)] onto p``````
Fortran
``````!\$xmp nodes p(4)
!\$xmp template t(20)
integer :: m(4) = (/3, 5, 8, 4/)
!\$xmp distribute t(gblock(m)) onto p``````
nodeindexes of template
p[0] 0, 1, 2
p[1] 3, 4, 5, 6, 7
p[2] 8, 9, 10, 11, 12, 13, 14, 15
p[3] 16, 17, 18, 19
nodeindexes of template
p(1) 1, 2, 3
p(2) 4, 5, 6, 7, 8
p(3) 9, 10, 11, 12, 13, 14, 15, 16
p(4) 17, 18, 19, 20

## align directive

The align directive specifies that an array is to be mapped in the same way as a specified template.

### A one-dimensional array and a one-dimensional template

 C ``````#pragma xmp nodes p[4] #pragma xmp template t[20] #pragma xmp distribute t[block] onto p int a[20]; #pragma xmp align a[i] with t[i]`````` Fortran ``````!\$xmp nodes p(4) !\$xmp template t(20) !\$xmp distribute t(block) onto p integer :: a(20) !\$xmp align a(i) with t(i)``````

Each node processes the index of the array a[] below.

nodeindexes
p[0] 0, 1, 2, 3, 4
p[1] 5, 6, 7, 8, 9
p[2] 10, 11, 12, 13, 14
p[3] 15, 16, 17, 18, 19
nodeindexes
p(1) 1, 2, 3, 4, 5
p(2) 6, 7, 8, 9, 10
p(3) 11, 12, 13, 14, 15
p(4) 16, 17, 18, 19, 20

### A two-dimensional array and a two-dimensional template

 C ``````#pragma xmp nodes p[2][2] #pragma xmp template t[10][10] #pragma xmp distribute t[block][block] onto p int a[10][10]; #pragma xmp align a[i][j] with t[i][j]`````` Fortran ``````!\$xmp nodes p(2,2) !\$xmp template t(10,10) !\$xmp distribute t(block,block) onto p integer :: a(10,10) !\$xmp align a(j,i) with t(j,i)``````

Each node processes the indices of array a[][] below.

node1st indexes of a[][]2nd indexes of a[][]
p[0][0] 0, 1, 2, 3, 4 0, 1, 2, 3, 4
p[0][1] 0, 1, 2, 3, 4 5, 6, 7, 8, 9
p[1][0] 5, 6, 7, 8, 9 0, 1, 2, 3, 4
p[1][1] 5, 6, 7, 8, 9 5, 6, 7, 8, 9
node1st indexes of a()2nd indexes of a()
p(1,1) 1, 2, 3, 4, 5 1, 2, 3, 4, 5
p(2,1) 6, 7, 8, 9, 10 1, 2, 3, 4, 5
p(1,2) 1, 2, 3, 4, 5 6, 7, 8, 9, 10
p(2,2) 6, 7, 8, 9, 10 6, 7, 8, 9, 10
 C ``````#pragma xmp nodes p[2][2] #pragma xmp template t[10][10] #pragma xmp distribute t[block][cyclic] onto p int a[10][10]; #pragma xmp align a[i][j] with t[i][j]`````` Fortran ``````!\$xmp nodes p(2,2) !\$xmp template t(10,10) !\$xmp distribute t(cyclic,block) onto p integer :: a(10,10) !\$xmp align a(j,i) with t(j,i)``````

Each node processes the indices of array a[][] below.

node1st indexes of a[][]2nd indexes of a[][]
p[0][0] 0, 1, 2, 3, 4 0, 2, 4, 6, 8
p[0][1] 0, 1, 2, 3, 4 1, 3, 5, 7, 9
p[1][0] 5, 6, 7, 8, 9 0, 2, 4, 6, 8
p[1][1] 5, 6, 7, 8, 9 1, 3, 5, 7, 9
node1st indexes of a()2nd indexes of a()
p(1,1) 1, 3, 5, 7, 9 1, 2, 3, 4, 5
p(2,1) 2, 4, 6, 8, 10 1, 2, 3, 4, 5
p(1,2) 1, 2, 3, 4, 5 6, 7, 8, 9, 10
p(2,2) 2, 4, 6, 8, 10 6, 7, 8, 9, 10

### A two-dimensional array and a one-dimensional template

 C ``````#pragma xmp nodes p[4] #pragma xmp template t[20] #pragma xmp distribute t[block] onto p int a[10][20]; #pragma xmp align a[*][i] with t[i]`````` Fortran ``````!\$xmp nodes p(4) !\$xmp template t(20) !\$xmp distribute t(block) onto p integer :: a(20,10) !\$xmp align a(i,*) with t(i)``````
• C : The first dimension of array a[][] is "∗, and so it is not divided, and only the second dimension index is divided among each of nodes and processed.
• Fortran : The second dimension of array a(,) is "∗, and so it is not divided, and only the first dimension index is divided among each of nodes and processed.

### A one-dimensional array and a two-dimensional template

 C ``````#pragma xmp nodes p[2][2] #pragma xmp template t[10][10] #pragma xmp distribute t[block][block] onto p int a[10]; #pragma xmp align a[i] with t[*][i]`````` Fortran ``````!\$xmp nodes p(2,2) !\$xmp template t(10,10) !\$xmp distribute t(block,block) onto p integer :: a(10) !\$xmp align a(i) with t(i,*)``````
• C：p[0][0] and p[1][0] have indices from 0 to 4, p[0][1] and p[1][1] have indices from 5 to 9.
• Fortran：p(1,1) and p(1,2) have indices from 1 to 5, p(2,1) and p(2,2) have indices from 6 to 10.