XcalableMP Programming Model and Language
25
3 Work Mapping
3.1 task and tasks Construct
The task construct defines a task that is executed by a specified node set. The
tasks construct asserts that the task constructs it surrounds can be executed in
parallel.
3.1.1 task Construct
When a node encounters a task construct at runtime, it executes the associated block
(called a task) if it is included by the node set specified by the on clause; otherwise,
it skips the execution of the block (Fig. 19).
XcalableMP C
#include
#pragma xmp nodes p[4]
int main(){
5
int num = xmpc_node_num();
#pragma xmp task on p[1:3]
{
printf("%d: Hello\n", num);
}
10
return 0;
}
XcalableMP Fortran
program main
!$xmp nodes p(4)
integer :: num
5
num = xmp_node_num()
!$xmp task on p(2:4)
write( * , * ) num, ": Hello"
!$xmp end task
10 end program main
In the above example, nodes p[1], p[2], and p[3] invoke the printf()
function, and p[1] outputs “1: Hello” in XMP/C; p(2), p(3), and p(4) execute
the write statement, and p(2) outputs “2: Hello” in XMP/Fortran.
Note that a new node set is generated by each task construct. Let’s consider
inserting a bcast construct into the task.
25
3 Work Mapping
3.1 task and tasks Construct
The task construct defines a task that is executed by a specified node set. The
tasks construct asserts that the task constructs it surrounds can be executed in
parallel.
3.1.1 task Construct
When a node encounters a task construct at runtime, it executes the associated block
(called a task) if it is included by the node set specified by the on clause; otherwise,
it skips the execution of the block (Fig. 19).
XcalableMP C
#include
#pragma xmp nodes p[4]
int main(){
5
int num = xmpc_node_num();
#pragma xmp task on p[1:3]
{
printf("%d: Hello\n", num);
}
10
return 0;
}
XcalableMP Fortran
program main
!$xmp nodes p(4)
integer :: num
5
num = xmp_node_num()
!$xmp task on p(2:4)
write( * , * ) num, ": Hello"
!$xmp end task
10 end program main
In the above example, nodes p[1], p[2], and p[3] invoke the printf()
function, and p[1] outputs “1: Hello” in XMP/C; p(2), p(3), and p(4) execute
the write statement, and p(2) outputs “2: Hello” in XMP/Fortran.
Note that a new node set is generated by each task construct. Let’s consider
inserting a bcast construct into the task.
