6.7. SUBNETWORKS


6.6. NETWORK FUNCTIONS

The library function MPC_Barrier allows the synchronization of the abstract processors of the specified mpC network. The next program demonstrates how this function is used:

#include <mpc.h> #define N 5 int [*]main() {    net SimpleNet(N) mynet;    int [mynet]my_coordinate;    my_coordinate = I coordof mynet;    if(my_coordinate%2==0)       [mynet]MPC_Printf("Hello, even world! My coordinate is %d.\n",                   my_coordinate);    ([(N)mynet])MPC_Barrier();    if(my_coordinate%2==1)       [mynet]MPC_Printf("Hello, odd world! My coordinate is %d.\n",                   my_coordinate);    }

Note that in this program only the processes that implement network mynet participate in the barrier synchronization. A call to function MPC_Barrier looks unusual in that it differs from all functions we have dealt with before. It is an example of a network function.

Unlike the basic functions, which are always executed by all processes of the parallel program, a network function is executed on a network. Therefore network functions can be executed in parallel with other network or nodal functions.

Unlike the nodal functions, which can also be executed in parallel by abstract processors of a network, the network function can in its execution include data transfer between abstract processors. This makes the network functions somewhat similar to the basic functions.

Function MPC_Barrier is declared in the header file mpc.h as

 int [net SimpleNet(n) w] MPC_Barrier(void);

The network function has a special network parameter that represents the network executing the function. In the declaration of the network function, the specification of its network parameter is in brackets just before the name of the function. This specification looks like a network definition.

In the declaration of function MPC_Barrier, the network parameter is specified as

 net SimpleNet(n) w

In addition to formal network w executing function MPC_Barrier, this declaration introduces parameter n of this network. Like “normal” function parameters, this parameter is available in the body of the function as if it were declared with the specifiers repl and const. Since in the definition of the network type SimpleNet, parameter n is declared of type int, it is treated in the body of function MPC_Barrier as if it were a normal parameter of this function declared as follows:

 repl int const n

All “normal” parameters of a network function are considered distributed over the network specified by its special network parameter. Thus the integer constant parameter n replicated over network w determines the number of abstract processors of this network.

If function MPC_Barrier were not a library function, it might be defined as in the following mpC application:

#include <mpc.h> #define N 5 int [net SimpleNet(n) w] MPC_Barrier(void)    {       int [w:parent]bs[n], [w]b=1;       bs[]=b;       b=bs[];    } int [*]main() {    net SimpleNet(N) mynet;    int [mynet]my_coordinate;    my_coordinate = I coordof mynet;    if(my_coordinate%2==0)       [mynet]MPC_Printf("Hello, even world! My coordinate is %d.\n",                   my_coordinate);    ([(N)mynet])MPC_Barrier();    if(my_coordinate%2==1)       [mynet]MPC_Printf("Hello, odd world! My coordinate is %d.\n",                   my_coordinate); }

The body of the function MPC_Barrier defines array bs of n elements and variable b. Array bs is located on the parent of network w, which is specified with construct [w:parent] before the name of this array. Variable b is distributed over network w. The two statements that follow the definition implement a barrier for abstract processors of network w.

In the program above, a call to function MPC_Barrier passes network mynet as an argument for network parameter w. It also passes a value for parameter n of network type SimpleNet. At a first glance the latter may look redundant, since a data structure that represents network mynet is supposed to keep all essential information about this network, including its parameters. Therefore one could presume that a value for parameter n is available in function MPC_Barrier via the data structure assigned to its network parameter. But the fact is that a network of any type, not only of type SimpleNet, may be passed to this function as a network argument. The next mpC program demonstrates this possibility:

#include <mpc.h> nettype Mesh(int m, int n) {    coord I=m, J=n;    parent [0,0]; }; #define M 2 # define N 3 int [*]main() {    net Mesh(M,N) [host]mynet;    [mynet]:    {       char *nodename;       int namelen;       MPC_Processor_name(&nodename, &namelen);       if(I coordof mynet == 0)          MPC_Printf("I’m on \"%s\" and have coordinates (%d, %d).\n",                      nodename, I coordof mynet,              J coordof mynet);       ([(M*N)mynet])MPC_Barrier();       if(I coordof mynet != 0)          MPC_Printf("I’m on \"%s\" and have coordinates (%d, %d).\n",                      nodename, I coordof mynet,              J coordof mynet);    } }

Network mynet of type Mesh is used in this program as a network argument in a call to function MPC_Barrier. However, function MPC_Barrier only treats the group of processes, on which it is called, as representing an mpC network of type SimpleNet. Data passed to function MPC_Barrier with network argument mynet, such as values for parameters m and n of network type Mesh, cannot help to calculate the value for parameter n of this function. Therefore this value must be explicitly provided as a part of the function call.

In general, a network argument in a call to a network function may be an mpC network of any network type that is different from the network type Tp of the network parameter of this function. There may be many different ways to interpret abstract processors passed via the network argument as a network of type Tp. Explicit provision in the function call values of the Tp parameters specifies how exactly these abstract processors are interpreted as abstract processors constituting a network of type Tp.

The next program demonstrates a situation where different values for network-type parameters in a call to a network function interpret differently the abstract processors of the passed network argument in this function:

#include <mpc.h> #define N 6 nettype Mesh(int m, int n) {    coord I=m, J=n;    parent [0,0]; }; int [net Mesh(m,n) w] My_Barrier( void ) {    int [w:parent]bs[m*n], [w]b=1;    MPC_Printf("Regards from My_Barrier. "             "My coordinates here are (%d, %d).\n",             I coordof w, J coordof w);    bs[]=b;    b=bs[]; } int [*]main() {    net SimpleNet(N) mynet;    int [mynet]my_coordinate;    my_coordinate = I coordof mynet;    ([(1,N)mynet])My_Barrier();    if(my_coordinate%2==0)       mynet]MPC_Printf("Hello, even world!\n");    ([(3,N/3)mynet])My_Barrier();    if(my_coordinate%2==1)       [mynet]MPC_Printf("Hello, odd world!\n"); }

The abstract processors of network mynet will be arranged differently inside function My_Barrier during two calls to this network function. During the first call, they are interpreted as a 1 x 6 processor arrangement. During the second call, they are interpreted as a 3 x 2 processor arrangement. Therefore these two calls will result in different messages coming to the user’s terminal from the same abstract processor.

In general, different values for network-type parameters of a network function will result in different computations performed by the function.




Parallel Computing on Heterogeneous Networks
Parallel Computing on Heterogeneous Networks (Wiley Series on Parallel and Distributed Computing)
ISBN: B000W7ZQBO
EAN: N/A
Year: 2005
Pages: 95

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net