6.4. NETWORK PARENT


6.3. NETWORK TYPE

By now in our mpC programs all abstract processors of the same network have performed the same computations. Therefore there was no need to separate the different abstract processors inside the network. But, if a parallel algorithm needs different processes to execute differrent computations, means to separate abstract processors inside the network are needed.

The mpC language provides the programmer with such means. In particular, it allows the programmer to associate abstract processors of any network with a coordinate system and identify a single abstract processor by specifying its coordinates in this coordinate system.

Generally speaking, in mpC one cannot simply define a network but only a network of a type. Type is the most important attribute of a network. In particular, it determines how to access separate abstract processors of the network.

The type specification is a mandatory part of any network definition. Therefore any network definition should be preceded by a definition of the corresponding network type. In all of the mpC programs considered so far, the network type SimpleNet was used in the network definitions. A definition of this network type is in the header file mpc.h among other standard definitions of the mpC language, and it was included in these programs with the include directive. This definition appears as follows:

 nettype SimpleNet(int n) {    coord I=n; };

It introduces name SimpleNet of the network, whose type is parame-terized with the integer parameter n. The body of the definition declares the coordinate variable I ranging from 0 to n-1. Type SimpleNet is the simplest parameterized network type that describes networks consisting of n abstract processors well-ordered by their positions on the coordinate line.

The next application demonstrates how different computations on different abstract processors of the same network can be specified in mpC:

#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);    else       [mynet]MPC_Printf("Hello, odd world! My coordinate is %d.\n",                   my_coordinate); }

This program uses the binary operator coordof with the coordinate variable I and network mynet as its left and right operands respectively. The result is an integer value distributed over network mynet. The projection of this value to each abstract processor of this network will be equal to the value of coordinate I of this abstract processor in network mynet.

After evaluation of assignment

my_coordinate = I coordof mynet,

each projection of variable my_coordinate will hold the coordinate of the corresponding abstract processor of network mynet. As a result abstract processors with even coordinates will output messages beginning with greeting “Hello, even world!” while processors with odd coordinates will output messages that begin with “Hello, odd world!”

The order in which messages from different abstract processors of mynet will appear on the user’s terminal is not defined. It may depend, for example, on the order in which the mesages arrive at the host-computer.

The next mpC program defines a network whose abstract processors are associated with a two-dimensional coordinate system:

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

Each abstract processor of network mynet outputs its coordinates and the name of the computer hosting the abstract processor. Note that in this program variable nodename is used as the second operand of operator coordof, and not network mynet. In general, the second operand of operator coordof may be either an expression or a network. If it is an expression, then the expression is not evaluated. It is only used to determine the network over which this expression is distributed. And then the operator will be executed as if that network is its second operand.




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