/
ch4-work.tex
1282 lines (1092 loc) · 37.5 KB
/
ch4-work.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\section{Work Mapping Construct}
\subsection{{\tt task} Construct}
\subsubsection*{Synopsis}
The {\tt \Directive{task}} construct defines a task that is executed by
a specified node set.
\subsubsection*{Syntax}
\Syntax{task}
\begin{tabular}{ll}
\verb![F]! & \verb|!$xmp| {\tt task on} \{{\it nodes-ref} $\vert$ {\it
template-ref}\} \\
& {\it structured-block} \\
& \verb|!$xmp| {\tt end task} \\
& \\
\verb![C]! & \verb|#pragma xmp| {\tt task on} \{{\it nodes-ref} $\vert$
{\it template-ref}\} \\
& {\it structured-block} \\
\end{tabular}
\subsubsection*{Description}
When a node encounters a {\tt task} construct at runtime, it executes
the associated block (called a {\it task}) if it is included by the node
set specified by the {\tt on} clause; otherwise, it skips the execution
of the block.
%This line was inserted by Sakagami for svn test.
Unless a {\tt task} construct is surrounded by a {\tt \Directive{tasks}}
construct, {\it nodes-ref} or {\it template-ref} in the {\tt on} clause
is evaluated by the executing node set at the start of the task;
otherwise, {\it nodes-ref} and {\it template-ref} of the {\tt task}
construct are evaluated by the executing node set at the entry of the
{\tt tasks} construct that immediately surrounds it.
%where the evaluation
%results must be the same in every node in the executing node set.
%
The current executing node set is set to be that specified by the {\tt
on} clause at the entry of the {\tt task} construct, and it is rewound
to the last one at the exit.
%When {\it nodes-ref} or {\it template-ref} is evaluated, the
%corresponding new executing node set is created conceptually.
%The former
%executing node set that includes the node encountering the {\tt task}
%construct is referred to as the ``\Term{parent executing node set}'' of
%the new executing node set.
\subsubsection*{Restrictions}
\begin{itemize}
\item The node set specified by {\it nodes-ref} or {\it template-ref}
in the {\tt on} clause must be a subset of the parent node set.
\end{itemize}
\subsubsection*{Example}
\Example{task}
\Example{end task}
\begin{description}
\item[Example 1]
In XcalableMP Fortran, copies of variables {\tt a} and {\tt b} are replicated on
nodes {\tt nd(1)} through {\tt nd(8)}.
A task defined by the {\tt task} construct is executed only on {\tt nd(1)}, and
defines the copies of {\tt a} and {\tt b} on a node {\tt nd(1)}.
The copies on nodes {\tt nd(2)} through {\tt nd(8)} are not defined.
In XcalableMP C, copies of variables {\tt a} and {\tt b} are replicated on
nodes {\tt nd[0]} through {\tt nd[7]}.
A task defined by the {\tt task} construct is executed only on {\tt nd[0]}, and
defines the copies of {\tt a} and {\tt b} on a node {\tt nd[0]}.
The copies on nodes {\tt nd[1]} through {\tt nd[7]} are not defined.
\hspace{\hsize}
\begin{minipage}{0.44\hsize}
\begin{center}
\begin{XFexample}
!$xmp nodes nd(8)
!$xmp template t(100)
!$xmp distribute t(block) onto nd
real a, b;
!$xmp task on nd(1)
read(*,*) a
b = a*1.e-6
!$xmp end task
\end{XFexample}
\end{center}
\end{minipage}
%
\begin{minipage}{0.51\hsize}
\begin{center}
\begin{XCexampleR}
#pragma xmp nodes nd[8]
#pragma xmp template t[100]
#pragma xmp distribute t[block] onto nd
float a, b;
#pragma xmp task on nd[0]
{
scanf ("%f", &a);
b = a*1.e-6;
}
\end{XCexampleR}
\end{center}
\end{minipage}
\vspace{1cm}
\item[Example 2]
According to the {\tt on} clause with a template reference,
an assignment statement in the {\tt task} construct is
executed by the owner of the array element {\tt a(:,j)} or {\tt a[j][:]}.
\hspace{\hsize}
\begin{minipage}{0.44\hsize}
\begin{center}
\begin{XFexample}
!$xmp nodes nd(8)
!$xmp template t(100)
!$xmp distribute t(block) onto nd
integer i,j
real a(200,100)
!$xmp align a(*,j) with t(j)
i = ...
j = ...
!$xmp task on t(j)
a(i,j) = 1.0
!$xmp end task
\end{XFexample}
\end{center}
\end{minipage}
%
\begin{minipage}{0.51\hsize}
\begin{center}
\begin{XCexampleR}
#pragma xmp nodes nd[8]
#pragma xmp template t[100]
#pragma xmp distribute t(block) onto nd
int i,j;
float a[100][200];
#pragma align a[j][*] with t[j]
i = ...;
j = ...;
#pragma xmp task on t[j]
a[j][i] = 1.0;
}
\end{XCexampleR}
\end{center}
\end{minipage}
\end{description}
\subsection{{\tt tasks} Construct}
\subsubsection*{Synopsis}
The {\tt \Directive{tasks}} construct is used to instruct the executing
nodes to execute the multiple tasks that it surrounds in an arbitrary
order.
\subsubsection*{Syntax}
\Syntax{tasks}
\begin{tabular}{ll}
\verb![F]! & \verb|!$xmp| {\tt tasks} \\
& {\it task-construct} \\
& ... \\
& \verb|!$xmp| {\tt end tasks} \\
& \\
\verb![C]! & \verb|#pragma xmp| {\tt tasks} \\
& {\tt \{} \\
& \hspace{0.5cm} {\it task-construct} \\
& \hspace{0.5cm} ... \\
& {\tt \}} \\
\end{tabular}
\subsubsection*{Description}
{\tt \Directive{task}} constructs surrounded by a {\tt tasks} construct
are executed in arbitrary order without implicit synchronization at the
start of each task.
%
As a result, if there are no overlaps between the executing node sets of
the adjacent tasks, they can be executed in parallel.
{\it nodes-ref} or {\it template-ref} of each task immediately
surrounded by a {\tt tasks} construct is evaluated by the executing node
set at the entry of the {\tt tasks} construct.
No implicit synchronization is performed at the start and end of the
{\tt tasks} construct.
%
%implicit synchronization is performed at the exit of the {\tt tasks}
%construct, which guarantees that all communications issued inside child
%tasks are completed, unless a {\tt nowait} clause is specified.
%When a {\tt nowait} clause is specified, implicit
%synchronization is not performed at the end of the {\tt tasks}
%construct. Without a {\tt nowait} clause, implicit synchronization is
%performed in order to guarantee that all communications issued inside
%child tasks are completed.
\subsubsection*{Example}
\Example{tasks}
\Example{task}
\Example{end tasks}
\Example{end task}
\begin{description}
\item[Example 1]
Three instances of subroutine {\tt task1} are concurrently
executed by node sets {\tt p(1:500)}, {\tt p(501:800)}, and
{\tt p(801:1000)}.
\hspace{\hsize}
\begin{minipage}{0.45\hsize}
\begin{center}
\begin{XFexample}
subroutine caller
!$xmp nodes p(1000)
!$xmp template tp(100)
!$xmp distribute t(block) onto p
real a(100,100)
!$xmp align a(*,k) with t(k)
...
!$xmp tasks
!$xmp task on p(1:500)
call task1(a)
!$xmp end task
!$xmp task on p(501:800)
call task1(a)
!$xmp end task
!$xmp task on p(801:1000)
call task1(a)
!$xmp end task
!$xmp end tasks
...
end subroutine
\end{XFexample}
\end{center}
\end{minipage}
%
\begin{minipage}{0.45\hsize}
\begin{center}
\begin{XFexampleR}
subroutine task1(a)
...
!$xmp nodes q(*)=*
!$xmp nodes p(1000)
!$xmp distribute t(block) onto p
real a(100,100)
!$xmp align a(*,k) with t(k)
...
end subroutine
\end{XFexampleR}
\end{center}
\end{minipage}
\vspace{1cm}
\item[Example 2]
The first node {\tt p(1)} executes the first and second
tasks, the final {\tt node p(8)} the second and the third
tasks, and the other nodes {\tt p(2)} through {\tt p(7)}
only the second task.
\hspace{\hsize}
\begin{XFexample}
!$xmp nodes p(8)
!$xmp template t(100)
!$xmp distribute t(block) onto p
real a(100)
!$xmp align a(i) with t(i)
...
!$xmp tasks
!$xmp task on t(1)
a(1) = 0.0
!$xmp end task
!$xmp task on t(2:99)
!$xmp loop on t(i)
do i=2,99
a(i) = foo(i)
enddo
!$xmp end task
!$xmp task on t(100)
a(100) = 0.0
!$xmp end task
!$xmp end tasks
\end{XFexample}
\end{description}
\subsection{{\tt loop} Construct}
\label{sub:loop_construct}
\subsubsection*{Synopsis}
The {\tt \Directive{loop}} construct specifies that each iteration of
the following loop is executed by a node set that is specified by the {\tt on}
clause, so the iterations are distributed among nodes and executed
in parallel.
% where the specified data is accessed locally.
% inserted by Sakagami,H. 09/11/13
%If the loop body includes reduction operations, then they must be
%specified in the {\tt loop} directive to obtain the correct results.
\subsubsection*{Syntax}
\Syntax{loop}
\begin{tabular}{ll}
\verb![F]! & \verb|!$xmp| {\tt loop} {\openb} \verb|(| {\it loop-index}
{\openb}, {\it loop-index}{\closeb}... \verb|)| {\closeb}
{\tt on} \{{\it nodes-ref} $\vert$ {\it template-ref}\} {\bsquare} \\
& \hspace{5cm}{\bsquare}
{\openb} \verb|expand(| {\it expand-width} {\openb}, {\it
expand-width}{\closeb}... \verb|)| {\closeb} {\bsquare} \\
& \hspace{5cm}{\bsquare}
{\openb} \verb|margin(| {\it margin-width} {\openb}, {\it
margin-width}{\closeb}... \verb|)| {\closeb} {\bsquare} \\
& \hspace{5cm}{\bsquare}
{\openb} {\it reduction-clause} {\closeb}... \\
% & \hspace{5cm}{\bsquare}
% {\openb} \verb|pipeline(| {\it pipeline-spec} {\openb}, {\it
% pipeline-spec}{\closeb}... \verb|)| {\closeb} {\bsquare} \\
& {\it do-loops} \\
& \\
\verb![C]! & \verb|#pragma xmp| {\tt loop} {\openb} \verb|(| {\it
loop-index} {\openb}, {\it loop-index}{\closeb}... \verb|)|
{\closeb} {\tt on} \{{\it nodes-ref} $\vert$ {\it template-ref}\} {\bsquare} \\
& \hspace{5cm}{\bsquare}
{\openb} \verb|expand(| {\it expand-width} {\openb}, {\it
expand-width}{\closeb}... \verb|)| {\closeb} {\bsquare} \\
& \hspace{5cm}{\bsquare}
{\openb} \verb|margin(| {\it margin-width} {\openb}, {\it
margin-width}{\closeb}... \verb|)| {\closeb} {\bsquare} \\
& \hspace{5cm}{\bsquare}
{\openb} {\it reduction-clause} {\closeb}... \\
% & \hspace{5cm}{\bsquare}
% {\openb} \verb|pipeline(| {\it pipeline-spec} {\openb}, {\it
% pipeline-spec}{\closeb}... \verb|)| {\closeb} {\bsquare} \\
& {\it for-loops} \\
\end{tabular}
%\vspace{0.3cm}
%
%where {\it on-ref} is one of:
%
%\vspace{0.3cm}
%
%\begin{tabular}{ll}
% \hspace{0.5cm} & {\it template-ref} \\
% & {\it nodes-ref} \\
%\end{tabular}
%
\vspace{0.3cm}
where {\it expand-width} and {\it margin-width} must be one of:
\vspace{0.3cm}
\begin{tabular}{ll}
\hspace{0.5cm} & {\openb}{\tt /unbound/}{\closeb} {\it int-expr} \\
& {\openb}{\tt /unbound/}{\closeb} {\it int-expr} : {\it int-expr}
\end{tabular}
\vspace{0.3cm}
{\it reduction-clause} is:
\vspace{0.3cm}
\begin{tabular}{ll}
\hspace{0.5cm} & \verb|reduction(| {\it reduction-kind} : {\it reduction-spec}
{\openb}, {\it reduction-spec} {\closeb}... \verb|)| \\
\end{tabular}
\vspace{0.3cm}
{\it reduction-kind} is one of:
%例えば,.AND.は,論理型の変数に対して,la = la .AND. lgcl(i)を,IANDは,
%整数型変数に対してia = IAND( ia, ib(i) ) とIAND関数を使うときです.
%HPFに入っています.元々,私は書かなかったのですが,岩下さんが削除する必
%要もないだろうとのことで入れました.
% Reduction指示文には入っていますので,追加しました.
\vspace{0.3cm}
\begin{tabular}{ll}
\verb![F]! & {\tt +} \\
& {\tt *} \\
& {\tt -} \\
& {\tt .and.} \\
& {\tt .or.} \\
& {\tt .eqv.} \\
& {\tt .neqv.} \\
& {\tt max} \\
& {\tt min} \\
& {\tt iand} \\
& {\tt ior} \\
& {\tt ieor} \\
& {\tt firstmax} \\
& {\tt firstmin} \\
& {\tt lastmax} \\
& {\tt lastmin} \\
& \\
\verb![C]! & {\tt +} \\
& {\tt *} \\
& {\tt -} \\
& {\tt \verb|&|} \\
& {\tt |} \\
& {\tt \verb|^|} \\
& {\tt \verb|&&|} \\
& {\tt ||} \\
& {\tt max} \\
& {\tt min} \\
& {\tt firstmax} \\
& {\tt firstmin} \\
& {\tt lastmax} \\
& {\tt lastmin} \\
\end{tabular}
\vspace{0.3cm}
and {\it reduction-spec} is:
\vspace{0.3cm}
\begin{tabular}{ll}
\hspace{0.5cm} & {\it reduction-variable} {\openb} {\tt /} {\it
location-variable} {\openb}, {\it location-variable}
{\closeb}... {\tt /} {\closeb} \\
\end{tabular}
% \vspace{0.3cm}
% and {\it pipeline-spec} is:
% \vspace{0.3cm}
% \begin{tabular}{ll}
% \hspace{0.5cm} & {\it array-name} {\tt /} {\it int-expr} {\openb}, {\it
% int-expr} {\closeb}... {\tt /} \\
% \end{tabular}
\subsubsection*{Description}
A {\tt loop} directive is associated with a loop nest
consisting of one or more tightly nested loops that follow the directive,
and it distributes the execution of their iterations onto the node set
specified by the {\tt on} clause.
% inserted by Sakagami,H. 09/11/13
%Since the iteration range of the loop for each node is determined before
%the loop is executed, efficient loop execution can be expected.
The sequence of {\it loop-indexes} in parenthesis denotes an index of
an iteration of the loop nests. If a control variable of a loop does
not appear in the sequence, it is assumed that each of its possible
values is specified in the sequence. The sequence can be considered to
denote a set of indices of iterations.
%
When the sequence is omitted, it is assumed that the control variables
of all the loops in the associated loop nests are specified.
When a {\it template-ref} is specified in the {\tt on} clause, the
associated loop is distributed so that the iteration (set) indexed by
the sequence of {\it loop-indexes} is executed by the node onto
which a template element specified by the {\it template-ref} is
distributed.
%Therefore, before the {\tt
%\Directive{loop}} construct is executed, the referenced template must be
%fixed.
%When {\it template-spec} is ``*'', the corresponding dimension is
%collapsed so that it is ignored for the distribution of the loop. When
%{\it template-spec} is ``:'', the nodes for all of the template elements
%in the corresponding dimension are assigned to iterations for execution.
% modified by Sakagami,H. 09/11/13
When a {\it nodes-ref} is specified in the {\tt on} clause, the
associated loop is distributed so that the iteration (set) indexed by
the sequence of {\it loop-indexes} is executed by a node
specified by the {\it nodes-ref}.
In addition, the executing node set is updated to the node set specified
by the {\tt on} clause at the beginning of every iteration, and it is
restored to the last one at the end of it.
% inserted and modified by Sakagami,H. 09/11/13
%When the loop includes reduction operations, proper {\it reduction-clause}
%must be specified in order to obtain semantically correct results,
%and
%the reduction operation is executed on the specified local reduction
%variable just after the execution of the loop.
When a {\it reduction-clause} is specified, a reduction operation of the
kind specified by {\it reduction-kind} for a variable specified by
{\it reduction-variable} is executed just after the execution of the loop
nest.
% inserted by Sakagami,H. 09/11/13
%The {\tt loop} construct that has {\it template-ref} as {\it
%on-ref} and the {\tt reduction} clause, except in cases with {\it
%reduction-kind} of {\tt FIRSTMAX}, {\tt FIRSTMIN}, {\tt LASTMAX}, or
%{\tt LASTMIN}, is equivalent to the {\tt \Directive{reduction}}
%construct with the following {\it template-spec} replacements:
When the {\tt expand} clause is specified, and is of the form ``{\it
int-expr} : {\it int-expr}'' in a dimension,
the first {\it int-expr} is subtracted from the local lower bound in
that dimension, and the second one is added to the local upper bound.
%
When the {\tt expand} clause is specified, and is of the form {\it int-expr},
the {\it int-expr} is subtracted from the local lower bound in that
dimension, and is added to the local upper bounds.
%
However, an ``expanded'' local iteration space does not spread out of
the original global iteration space unless the \Term{{\tt /unbound/}
modifier} is specified in {\it expand-width}.
When the {\tt margin} clause is specified, the loop is transformed so
that its local iteration space, $margin$, is:
$$margin = expand \bigtriangleup orig$$
where $expand$ is a local iteration space when an {\tt expand} clause
with the same argument(s) is specified,
$orig$ is a local iteration space when neither $expand$ nor $margin$,
and
$\bigtriangleup$ is the symmetric difference operator.
\begin{quotation}
(Advice to programmers and implementers) Using the {\tt expand} and
{\tt margin} clauses and asynchronous communication, programmers can
overlap computation and communication as in the code left
below. It is recommended for the implementation to support an
extension that is a syntactic sugar for those sequence of constructs,
such as the {\tt peel\_and\_wait} clause in the code immediately
following.
\end{quotation}
\vspace{1zw}
\begin{minipage}{0.45\hsize}
\begin{center}
\begin{XFexample}
!$xmp reflect (a) async(10)
!$xmp loop (i,j) on t(i,j)
!$xmp+ expand(-1,-1)
do j = 1, 16
do i = 1, 16
...
end do
end do
!$xmp wait_async (10)
!$xmp loop (i,j) on t(i,j)
!$xmp+ margin(-1,-1)
do j = 1, 16
do i = 1, 16
...
end do
end do
\end{XFexample}
\end{center}
\end{minipage}
%
\begin{minipage}{0.45\hsize}
\begin{center}
\begin{XFexampleR}
!$xmp reflect (a) async(10)
!$xmp loop (i,j) on t(i,j)
!$xmp+ peel_and_wait(10, -1,-1)
do j = 1, 16
do i = 1, 16
...
end do
end do
\end{XFexampleR}
\end{center}
\end{minipage}
\vspace{1zw}
The reduction operation that is executed, except in cases with {\it
reduction-kind} of {\tt FIRSTMAX}, {\tt FIRSTMIN}, {\tt LASTMAX}, or
{\tt LASTMIN},
is equivalent to the {\tt reduction}
construct with {\it reduction-kind} of ``{\tt +}'' for ``{\tt -}'' in
the clause and the same {\it reduction-kind} for the other kinds,
the same {\it
reduction-variable}, and an {\tt on} clause obtained from that of the
{\tt loop} directive by replacing each {\it loop-index} in the {\it
nodes-ref} or the {\it template-ref} with a triplet representing the
range of its value.
% replacing:
% %
% \begin{itemize}
% \item ``{\tt :}'' in the {\it nodes-ref} or the {\it template-ref} with
% ``{\tt *}'', and
% \item {\it loop-index} in the {\it nodes-ref} or the {\it template-ref}
% with a triplet representing the range of its value.
% \end{itemize}
%
As an example, the two codes below are therefore equivalent.
\vspace{1zw}
\Example{loop}
\begin{minipage}{0.45\hsize}
\begin{center}
\begin{XFexample}
!$xmp loop (j) on t(:,j)
!$xmp+ reduction(op:s)
do j = js, je
...
do i = 1, N
s = s op a(i,j)
end do
...
end do
\end{XFexample}
\end{center}
\end{minipage}
%
\begin{minipage}{0.46\hsize}
\begin{center}
\begin{XFexampleR}
! Initialize s_tmp to the identity
! element of the op operator
s_tmp = ...
!$xmp loop (j) on t(:,j)
do j = js, je
...
do i = 1, N
s_tmp = s_tmp op a(i,j)
end do
...
end do
!$xmp reduction(op:s_tmp)
!$xmp+ on t(*,js:je)
s = s op s_tmp
\end{XFexampleR}
\end{center}
\end{minipage}
\vspace{1zw}
In particular, for the reduction kinds of {\tt FIRSTMAX}, {\tt FIRSTMIN},
{\tt LASTMAX}, and {\tt LASTMIN}, in addition to a corresponding {\tt
MAX} or {\tt MIN} reduction operation, the {\it
location-variables}\index{location-variable} are set after executing the
{\tt loop} construct as follows:
%
\begin{itemize}
\item For {\tt FIRSTMAX} and {\tt FIRSTMIN}, they are set to their
values at the end of the {\it first} iteration in which
the {\it reduction-variable} takes the value of the reduction
result, where {\it first} refers to the first position in the
sequential order in
which iterations of the associated loop nest were executed
without parallelization.
\item For {\tt LASTMAX} and {\tt LASTMIN}, they are set to their
values at the end of the {\it last} iteration in which
the {\it reduction-variable} takes the value of the reduction
result, where {\it last} refers to the last position in the
sequential order in
which iterations of the associated loop nest were executed
without parallelization.
\end{itemize}
% inserted by Sakagami,H. 09/11/13 ----- start ---
%Note that, unlike a {\tt \Directive{loop}} construct with the {\tt
%reduction} clause, a {\tt \Directive{reduction}} construct does not
%consider initialization for the reduction variable. The following
%programs return different values of the {\tt sum} variable after the
%reduction operation. When {\tt sum} is initialized to zero, these
%programs return the same results.
%
%\vspace{1zw}
%
%\begin{minipage}{0.45\hsize}
%\begin{center}
%\begin{XFexample}
% sum = 123.45
%!$xmp loop (i) on t(i)
%!$xmp+ reduction(+:sum)
% do i = 1, N
% sum = sum + a(i)
% end do
%\end{XFexample}
%\end{center}
%\end{minipage}
%%
%\begin{minipage}{0.45\hsize}
%\begin{center}
%\begin{XFexampleR}
% sum = 123.45
%!$xmp loop (i) on t(i)
% do i = 1, N
% sum = sum + a(i)
% end do
%!$xmp reduction(+:sum) on t(1:N)
%\end{XFexampleR}
%\end{center}
%\end{minipage}
% inserted by Sakagami,H. 09/11/13 ----- end ---
% \mytextcolor{red}{
% When the {\tt pipeline} clause is specified, the distributed loop nest is
% executed by nodes in such a pipeline manner that
% %
% each node waits until recieving from, executes its own local part of the loop nest, and
% then sends, to resolve loop-carried dependence.
% }
\subsubsection*{Restrictions}
\begin{itemize}
\item {\it loop-index} must be a control variable of a loop in the
associated loop nest.
\item A control variable of a loop can appear as {\it loop-index} at
most once.
% \item {\it template-spec} appearing in {\it template-ref} must be
% either ``*'', ``:'', or {\it loop-index}.
% In the case of {\it
% loop-index}, the loop index must be the loop index of the outer
% loop of the loop.
% \item {\it nodes-ref} must reference different node sets for each {\it
% loop-index}. These node sets consist of different nodes. That is,
% a node must not be included in more than one node set.
\item The node set specified by {\it nodes-ref} or {\it template-ref}
in the {\tt on} clause must be a subset of the parent node set.
\item The template specified by {\it template-ref} must be fixed
before the {\tt loop} construct is executed.
% \item The {\tt loop} construct is global, which means that it must be
% executed by all of the executing nodes, and each local variable
% referenced in the directive must have the same value among all of
% them, and the lower bound, upper bound, and step of the
% associated loop must have the same value among all of them.
\item The {\tt loop} construct is global, which means that it must be
executed by all of the executing nodes with the same values for
each local variable referenced in the directive, and the lower
bound, upper bound, and step of the associated loop.
\item Either of the {\tt expand} or {\tt margin} clause,
if any, can be specified.
\item The number of {\it expand-width}, if any, must be equal to the
number of dimensions (or rank) of the template specified by {\it
template-ref} or of the node array specified by {\it node-ref}.
\item The number of {\it margin-width}, if any, must be equal to the
number of dimensions (or rank) of the template specified by {\it
template-ref} or of the node array specified by {\it node-ref}.
\mycolor{black}{}
% modified by Sakagami,H. 09/11/13
\item {\it reduction-spec} must have one or more {\it
location-variable}'s if and only if {\it reduction-kind} is
either {\tt FIRSTMAX}, {\tt FIRSTMIN}, {\tt LASTMAX}, or {\tt
LASTMIN}.
% \item \mycolor{red}{The array specified by {\it array-name} in {\it
% pipeline-spec} must be mapped onto the executing node set.}
% \item \mycolor{red}{The number of {\it int-expr} in {\it pipeline-spec}
% must be equal to the number of dimensions (or rank) of the array
% specified by {\it array-name} in {\it pipeline-spec}.}
% inserted by Sakagami,H. 09/11/13
%\item {\it reduction-clause} must reference the reduction operations
% associated with the loop after the directive or the loops nested
% by the loop.
% \item {\it location-variable} must be fixed in the loop after the
% directive or the loops nested by the loop.
%\item {\it reduction-variable} must not be referred at a certain
% iteration in the loop, except for updating itself.
% \item {\it reduction-variable} and {\it location-variable} must not
% exist in {\it reduction-clause} of nested loops.
\end{itemize}
\subsubsection*{Examples}
\Example{loop}
\begin{description}
\item[Example 1]
\hspace{\hsize}
\begin{XFexample}
!$xmp distribute t(block) onto p
!$xmp align (i) with t(i) :: a, b
...
!$xmp loop (i) on t(i)
do i = 1, N
a(i) = 1.0
b(i) = a(i)
end do
\end{XFexample}
The {\tt loop} construct determines the node that executes each
of the iterations, according to the distribution of template {\tt t}, and
distributes
the execution. This example is syntactically equivalent to the one
shown below, but will be faster because the iterations to be executed by
each node can be determined before executing the loop.
\Example{task}
\begin{XFexample}
!$xmp distribute t(block) onto p
!$xmp align (i) with t(i) :: a, b
...
do i = 1, N
!$xmp task on t(i)
a(i) = 1.0
b(i) = a(i)
!$xmp end task
end do
\end{XFexample}
\item[Example 2]
\hspace{\hsize}
\begin{XFexample}
!$xmp distribute t(*,block) onto p
!$xmp align (i,j) with t(i,j) :: a, b
...
!$xmp loop (i,j) on t(i,j)
do j = 1, M
do i = 1, N
a(i,j) = 1.0
b(i,j) = a(i,j)
end do
end do
\end{XFexample}
Because the first dimension of template {\tt t} is not
distributed, only the {\tt j} loop, which is aligned with the
second dimension of {\tt t}, is distributed. This example is
syntactically equivalent to the {\tt task} construct shown
below.
\Example{task}
\begin{XFexample}
!$xmp distribute t(*,block) onto p
!$xmp align (*,j) with t(*,j) :: a, b
...
do j = 1, M
!$xmp task on t(*,j)
do i = 1, N
a(i,j) = 1.0
b(i,j) = a(i,j)
end do
!$xmp end task
end do
\end{XFexample}
\item[Example 3]
\hspace{\hsize}
\begin{XFexample}
!$xmp distribute t(block,block) onto p
!$xmp align (i,j) with t(i,j) :: a, b
...
!$xmp loop (i,j) on t(i,j)
do j = 1, M
do i = 1, N
a(i,j) = 1.0
b(i,j) = a(i,j)
end do
end do
\end{XFexample}
% modified by Sakagami,H. 09/11/13
The distribution of loops in the nested loop can be specified
using the sequence of {\it loop-indexes} in one {\tt loop}
construct. This example is equivalent to the loop shown
below, but will run faster because the iterations
to be executed by each node can be determined outside of the nested
loop. Note that the node set specified by the inner {\tt on}
clause is a subset of that specified by the outer one.
\begin{XFexample}
!$xmp distribute t(block,block) onto p
!$xmp align (i,j) with t(i,j) :: a, b
...
!$xmp loop (j) on t(:,j)
do j = 1, M
!$xmp loop (i) on t(i,j)
do i = 1, N
a(i,j) = 1.0
b(i,j) = a(i,j)
end do
end do
\end{XFexample}
\item[Example 4]
\hspace{\hsize}
\begin{XFexample}
!$xmp nodes p(10,3)
...
!$xmp loop on p(:,i)
do i = 1, 3
call subtask ( i )
end do
\end{XFexample}
Three node sets {\tt p(:,1)}, {\tt p(:,2)}, and {\tt p(:,3)}
are created as the executing node sets, and each of them
executes iterations {\tt 1}, {\tt 2}, and {\tt 3} of the
associated loop, respectively.
%
This example is equivalent to the loop
% modified by Sakagami,H. 09/11/13
containing {\tt task} constructs (below left) or static {\tt tasks/task}
constructs (below right).
\vspace{0.5cm}
\begin{minipage}{0.45\hsize}
\begin{center}
\begin{XFexample}
!$xmp nodes p(10,3)
...
do i = 1, 3
!$xmp task on p(:,i)
call subtask ( i )
!$xmp end task
end do
\end{XFexample}
\end{center}
\end{minipage}
\begin{minipage}{0.45\hsize}
\begin{center}
\begin{XFexampleR}
!$xmp nodes p(10,3)
...
!$xmp tasks
!$xmp task on p(:,1)
call subtask ( 1 )
!$xmp end task
!$xmp task on p(:,2)
call subtask ( 2 )
!$xmp end task
!$xmp task on p(:,3)
call subtask ( 3 )
!$xmp end task
!$xmp end tasks
\end{XFexampleR}
\end{center}
\end{minipage}
\vspace{1cm}
\item[Example 5]
\hspace{\hsize}
\begin{XFexample}
...