6.5. SYNCHRONIZATION OF PROCESSES


6.4. NETWORK PARENT

We just saw that the lifetime of an automatic network is limited by the block in which the network is defined. When the execution of the block ends, the network ceases to exist, and all processes taken for virtual processors of the network are freed and can be used for other networks.

The question is how the computational result on an automatic network can be saved and used in further computations. Our previous programs did not raise this issue because the only result of parallel computations on networks is output of the some messages to the user’s terminal.

Actually the mpC networks are not entirely independent of each other. A newly created network has one abstract processor that is shared with an already existing network (or with several already existing networks). That abstract processor is called a parent of this newly created network. The parent is the very connecting link through which the computational results are passed if the network ceases to exist.

The parent of a network is always specified by its definition, explicitly or implicitly. So far no network was defined with explicit specification of its parent. The parent was specified implicitly, and the parent was nothing other than the abstract host-processor. The solution is obvious, for at any time of program execution the existence of only one network can be guaranteed. This network is the network host, that is, a pre-defined network consisting of only the abstract processor, which is always mapped onto the host-process associated with the user’s terminal.

The next mpC application implements almost the same functionality as does the first program in Section 6.3, but it does this without the help of the MPC_Printf function:

#include <mpc.h> #include <stdio.h> #define N 5 #define MAX_MSG_LEN 64 int [*]main() {    net SimpleNet(N) mynet;    int [mynet]my_coordinate;    repl [mynet]j;    char [mynet]my_message[MAX_MSG_LEN];    char [host]msg_buffer[MAX_MSG_LEN];    my_coordinate = I coordof mynet;    if(my_coordinate%2==0)       [mynet]sprintf(my_message, "Hello, even world! "          "My coordinate is %d.\n",                   my_coordinate);    else       [mynet]sprintf(my_message, "Hello, odd world! "          "My coordinate is %d.\n",                   my_coordinate);    for(j=0; j<N; j++)    {       msg_buffer[] = [mynet:I==j]my_message[];       [host]printf("%s", msg_buffer);    } }

First each abstract processor of network mynet locally forms a message that will be output to the user’s terminal. The processor stores the message in its projection (a local copy) of the distributed character array my_message. Abstract processors of mynet do it in parallel by calling the nodal library function sprintf. Then all of the abstract processors of network mynet execute in parallel a for loop.

At the very first iteration of the loop (j=0) all processors, except the abstract host-processor, do nothing. Indeed, the parent of any network of type SimpleNet has coordinate 0 in the network. The parent of network mynet is the host-processor. Therefore specifiers [mynet:I==0] and [host] designate the same abstract processor. Array msg_buffer is also located on this abstract processor. As a result all data processed at the first iteration are located on the abstract host-processor. At this iteration the host-processor executes the following computations:

msg_buffer[] = my_message[]; printf("%s", msg_buffer); 

Recall that the mpC language is a superset of the C[ ] language that allows the programmer to explicitly describe operations on arrays (see Section 2.6.2). In particular, C[ ] code

msg_buffer[] = my_message[]

assigns the value of the ith element of array my_message to the ith element of array msg_buffer (i = 0,..., MAX_MSG_LEN-1).

The second iteration of this loop (j=1) involves the host-processor and abstract processor with coordinate 1. All other processors of mynet just do nothing. During execution of statement

msg_buffer[] = [mynet:I==1]my_message[];

the value of array my_message (a vector of MAX_MSG_LEN characters) is first sent from processor 1 to the host-processor, where it is assigned to array msg_buffer. Statement

[host]printf("%s", msg_buffer);

is then executed on the host-processor and outputs msg_buffer to the user’s terminal. Similarly the third iteration (j=2) is executed by the host-processor and abstract processor 2, and so on.

Unlike the mpC program using MPC_Printf, this program defines the order in which messages from different abstract processors of network mynet will appear on the user’s terminal. The order is determined by the order of execution of iterations of the for loop by the host-processor, that is, by the very abstract processor that outputs the messages to the user’s terminal. Therefore a message from processor 0 (the host-processor) always appears first, a message from processor 1 appears second, and so on.

The next mpC program is completely equivalent to the second program in Section 6.3, except that the parent of network mynet is specified explicitly:

#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);          MPC_Printf("I’m on \"%s\". My coordinates are (%d, %d).\n",                      nodename,             I coordof nodename,             J coordof nodename);       free(nodename);    } }

One more difference can be found in the definition of network type Mesh. Line

 parent [0,0];

has been added, which explicitly specifies coordinates of the parent in a network of the type Mesh. By default, the coordinates are also set to zeros. Should for any reason we need the parent of network mynet to have not the least but the greatest coordinates, line

 parent [m-1,n-1];

has to be used in the definition of network type Mesh instead of line

 parent [0,0];.

By now at most one network has existed at any time of the mpC program execution. This is not a restriction of the mpC language. The mpC language allows the programmer to write programs with an arbitrary number of simultaneously existing (and visible) networks. The only limitation is the total number of processes of the parallel program.

The next program defines three networks net1, net2, and net3 that exist simultaneously:

#include <mpc.h> nettype TrivialNet(int n, int m) {    coord I=n;    parent [m]; }; int [*]main() {    [host]MPC_Printf("I’m host. I’ll be a parent of net1.\n\n");    {       net TrivialNet(3,0) net1;       int [net1]mycoordinnet1;       mycoordinnet1 = I coordof net1;       [net1]:          if(mycoordinnet1)             MPC_Printf("I’m a regular member of net1. "                "My coordinate in net1 is %d.\n"                " I’ll be a parent of net%d.\n\n",                mycoordinnet1, mycoordinnet1+1);          else             MPC_Printf("I’m a parent of net1. "                "My coordinate in net1 is %d.\n\n",                mycoordinnet1);          {             net TrivialNet(3,1) [net1:I==1]net2;             net TrivialNet(3,2) [net1:I==2]net3;             [net2]:               {                  int mycoordinnet2;                  mycoordinnet2 = I coordof net2;                  if(mycoordinnet2!=1)                     MPC Printf("I’m a regular member of net2."                   "My coordinate in net2 is %d.\n\n",                   mycoordinnet2);          else             MPC_Printf( "I’m a parent of net2. "  "My coordinate in net2 is %d.\n\n", mycoordinnet2);    }    [net3]:          {          int mycoordinnet3;          mycoordinnet3 = I coordof net3;          if(mycoordinnet3!=2)             MPC_Printf("I’m a regular member of net3. "                "My coordinate in net3 is %d.\n\n",                mycoordinnet3);          else             MPC_Printf("I’m a parent of net3. "                "My coordinate in net3 is %d.\n\n",                mycoordinnet3);       }    }    [net1]:          if(mycoordinnet1)             MPC_Printf("I’m a regular member of net1. "                "My coordinate in net1 is %d.\n"                " I was a parent of net%d.\n\n",                mycoordinnet1, mycoordinnet1+1);    }    [host]MPC_Printf("I’m host. I was a parent of                 net1.\n\n"); }

The parent of network net1 is the abstract host-processor. This is specified implicitly by the definition of this network. The parent of network net2 is the abstract processor of network net1 with coordinate 1. This is specified explicitly by using construct [net1:I==1] in the definition of network net2. The parent of network net3 is the abstract processor of network net1 with coordinate 2, which is also specified explicitly in the definition of network net3.




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